X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tools.py;h=dbfa55f5fe1da2a5dc67311be25e2c336313f075;hb=dde04827b57a583c8918129c1afae9bffd908c60;hp=afd55bd6815003bb7b9f97b58d28a7b61e91219e;hpb=8391f38bad124335b0ba56fac3514cabc8f85a07;p=nodemanager.git diff --git a/tools.py b/tools.py index afd55bd..dbfa55f 100644 --- a/tools.py +++ b/tools.py @@ -289,3 +289,42 @@ def get_sliver_ip(slice_name): return None +### this returns the kind of virtualization on the node +# either 'vs' or 'lxc' +# also caches it in /etc/planetlab/virt for next calls +# could be promoted to core nm if need be +virt_stamp="/etc/planetlab/virt" +def get_node_virt (): + try: + return file(virt_stamp).read().strip() + except: + pass + logger.log("Computing virt..") + try: + if subprocess.call ([ 'vserver', '--help' ]) ==0: virt='vs' + else: virt='lxc' + except: + virt='lxc' + with file(virt_stamp,"w") as f: + f.write(virt) + return virt + +# how to run a command in a slice +# now this is a painful matter +# the problem is with capsh that forces a bash command to be injected in its exec'ed command +# so because lxcsu uses capsh, you cannot exec anything else than bash +# bottom line is, what actually needs to be called is +# vs: vserver exec slicename command and its arguments +# lxc: lxcsu slicename "command and its arguments" +# which, OK, is no big deal as long as the command is simple enough, +# but do not stretch it with arguments that have spaces or need quoting as that will become a nightmare +def command_in_slice (slicename, argv): + virt=get_node_virt() + if virt=='vs': + return [ 'vserver', slicename, 'exec', ] + argv + elif virt=='lxc': + # wrap up argv in a single string for -c + return [ 'lxcsu', slicename, ] + [ " ".join(argv) ] + logger.log("command_in_slice: WARNING: could not find a valid virt") + return argv +