From: Andy Bavier Date: Wed, 3 Dec 2008 19:46:52 +0000 (+0000) Subject: Simple module for toggling network namespaces based on slice attributes X-Git-Url: http://git.onelab.eu/?p=nodemanager.git;a=commitdiff_plain;h=refs%2Fheads%2Ftrellis Simple module for toggling network namespaces based on slice attributes --- diff --git a/trellis.py b/trellis.py new file mode 100644 index 0000000..a70d0f6 --- /dev/null +++ b/trellis.py @@ -0,0 +1,35 @@ +# $Id$ +# $URL$ + +"""Trellis configurator. Toggles network namespace based on slice attribute""" + +import logger +import os +from sets import Set + +def start(options, config): + pass + +def GetSlivers(data): + """For each sliver with the netns attribute, write the value to /etc/vservers//spaces/net""" + # Parse attributes and update dict of scripts + for sliver in data['slivers']: + for attribute in sliver['attributes']: + if attribute['name'] == 'netns': + writeConf(sliver['name'], attribute['value']) + +def writeConf(slicename, value): + SLICEDIR="/etc/vservers/%s/" % slicename + SPACESDIR="%s/spaces/" % SLICEDIR + if os.path.exists(SLICEDIR): + if not os.path.exists(SPACESDIR): + try: + os.mkdir(SPACESDIR) + except os.error: + logger.log("trellis: could not create %s\n" % SPACESDIR) + return + f = open("%s/net" % SPACESDIR, "w") + f.write("%s\n" % value) + f.close() + +