From c266c5ee9ca642923f2e94c72a3c7e1de9824e97 Mon Sep 17 00:00:00 2001 From: Andy Bavier Date: Thu, 21 May 2009 15:10:30 +0000 Subject: [PATCH] Restart vserver if spaces/net modified --- NodeManager-topo.spec | 2 +- topo.py | 36 ++++++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/NodeManager-topo.spec b/NodeManager-topo.spec index 4391fb7..c8590ef 100644 --- a/NodeManager-topo.spec +++ b/NodeManager-topo.spec @@ -2,7 +2,7 @@ Name: NodeManager-topo Version: 0.5 -Release: 1 +Release: 2 Summary: Plugin supporting creating a default virtual topology. Group: System Environment/Daemons diff --git a/topo.py b/topo.py index e73eb8a..5cdc7c1 100755 --- a/topo.py +++ b/topo.py @@ -176,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: @@ -188,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() """ @@ -357,11 +372,12 @@ def GetSlivers(data): attrs = {} for attribute in sliver['attributes']: 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: -- 2.43.0