X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=topo.py;h=5cdc7c10cdfc3f292c575e260f13d460f2e4532a;hb=3328b25fe2ed39610ec542f4f6d1e0609791ef39;hp=e142802772f22312d41298905c439a19f52ab4b9;hpb=1b5940a1a58122ab437c3b2dfe0794bbf01118c7;p=nodemanager-topo.git diff --git a/topo.py b/topo.py index e142802..5cdc7c1 100755 --- a/topo.py +++ b/topo.py @@ -31,6 +31,13 @@ def run(cmd): return subprocess.call(cmd, shell=True); +""" +Subnet used for virtual interfaces by setup-egre-link script +""" +def iias_network(): + return "192.168.0.0 255.255.0.0" + + """ Check for existence of interface dx """ @@ -71,6 +78,14 @@ def refresh_virtual_link(nodeid, key): return +""" +IP address of the NAT interface created inside the slice by the +setup-nat script. +""" +def nat_inner_ip(key): + return "10.0.%s.2" % key + + """ Check for existence of interface natx """ @@ -161,11 +176,12 @@ def update_links(slice, myid, topospec, key, netns): """ -Write /etc/vservers//spaces/net +Write /etc/vservers//spaces/net. If the vserver is running and the spaces/net file is modified, we need to restart it. """ -def writeConf(slicename, value): +def write_conf_and_restart(slicename, value): SLICEDIR="/etc/vservers/%s/" % slicename SPACESDIR="%s/spaces/" % SLICEDIR + FILENAME="%s/net" % SPACESDIR if os.path.exists(SLICEDIR): if not os.path.exists(SPACESDIR): try: @@ -173,13 +189,27 @@ def writeConf(slicename, value): except os.error: logger.log("topo: could not create %s\n" % SPACESDIR) return - f = open("%s/net" % SPACESDIR, "w") - f.write("%s\n" % value) - f.close() - STATUS="OFF" - if value: - STATUS="ON" - logger.log("%s: network namespace %s\n" % (slicename, STATUS)) + + if os.path.exists(FILENAME) != value: + sliver = vserver.VServer(slicename) + restart = sliver.is_running() + + if (restart): + sliver.stop() + + if value: + STATUS="ON" + f = open(FILENAME, "w") + f.close() + else: + STATUS="OFF" + os.remove(FILENAME) + + logger.log("%s: network namespace %s\n" % (slicename, STATUS)) + + if (restart): + logger.log("topo: restarting sliver %s\n" % slicename) + sliver.start() """ @@ -211,17 +241,16 @@ password %s """ -Network used by OpenVPN on this node +IP address of NAT gateway to outside world """ -def openvpn_net(myid): - return "10.%s.0.0/16" % myid - +def nat_gw(key): + return "10.0.%s.1" % key """ -IP address of NAT gateway to outside world +IP address of the NAT interface inside the slice """ -def nat_gw(key, myid): - return "10.%s.%s.1" % (key, myid) +def nat_inner(key): + return "10.0.%s.2" % key """ @@ -241,13 +270,11 @@ link-detect """ % name) f.write ("""! -ip route %s %s -! access-list vty permit 127.0.0.1/32 ! line vty ! -""" % (openvpn_net(myid), nat_gw(key, myid))) +""") f.close() return @@ -281,7 +308,7 @@ def write_ospf(filename, myname, ifaces): net = ifaces[name]['network'] f.write (" network %s area 0\n" % net) - f.write(""" redistribute static + f.write(""" redistribute kernel ! access-list vty permit 127.0.0.1/32 ! @@ -326,6 +353,7 @@ def update_hosts(slicename, hosts): def start(options, config): + run ("echo 1 > /proc/sys/net/ipv4/ip_forward") pass @@ -343,12 +371,13 @@ def GetSlivers(data): for sliver in data['slivers']: attrs = {} for attribute in sliver['attributes']: - attrs[attribute['name']] = attribute['value'] + attrs[attribute['tagname']] = attribute['value'] + if 'netns' in attrs: netns = int(attrs['netns']) - writeConf(sliver['name'], netns) else: netns = 0 + write_conf_and_restart(sliver['name'], netns) if vserver.VServer(sliver['name']).is_running(): if 'egre_key' in attrs and 'topo_rspec' in attrs: