Friday, May 21, 2010

CORE is now a Python package

The CORE Python code has been reorganized into a Python package. New example scripts are included in the source under core/python/examples/netns/. Here is a snippet from one of the samples, how you would make N nodes connected to a switch:

from core import pycore
from core.misc import ipaddr

def main:
...
# IP subnet
prefix = ipaddr.IPv4Prefix("10.83.0.0/16")
session = pycore.Session()
# emulated ethernet switch
switch = session.addobj(cls = pycore.nodes.SwitchNode)
print "creating %d nodes with addresses from %s" % \
(options.numnodes, prefix)
for i in xrange(1, options.numnodes + 1):
tmp = session.addobj(cls = pycore.nodes.LxcNode, name = "n%d" % i)
tmp.newnetif(switch, ["%s/%s" % (prefix.addr(i), prefix.prefixlen)])
tmp.cmd(["sysctl", "net.ipv4.icmp_echo_ignore_broadcasts=0"])
n.append(tmp)

# start a shell on node 1
n[1].term("bash")

No comments:

Post a Comment