From 185a2e3bf48406e5184c2d9259715adc9e6fd975 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 8 Jul 2013 11:35:09 +0200 Subject: [PATCH] command_in_slice moved to tools.py --- plugins/omf_resctl.py | 34 +--------------------------------- tools.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/plugins/omf_resctl.py b/plugins/omf_resctl.py index 463ffaa..85824e1 100644 --- a/plugins/omf_resctl.py +++ b/plugins/omf_resctl.py @@ -43,38 +43,6 @@ yaml_slice_path="/etc/omf_rc/config.yml" # the path for the script that we call when a change occurs omf_rc_trigger_script="plc_trigger_omf_rc" -### 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..") - vs_retcod=subprocess.call ([ 'vserver', '--help' ]) - if vs_retcod == 0: - virt='vs' - else: - virt='lxc' - with file(virt_stamp,"w") as f: - f.write(virt) - return virt - -def command_in_slice (slicename, argv): - # with vserver this can be done using vserver .. exec - # with lxc this is less clear as we are still discussing how lxcsu should behave - # ideally we'd need to run lxcsu .. - virt=get_node_virt() - if virt=='vs': - return [ 'vserver', slicename, 'exec', ] + argv - elif virt=='lxc': - return [ 'lxcsu', slicename, ] + argv - logger.log("command_in_slice: WARNING: could not find a valid virt") - return argv - def GetSlivers(data, conf = None, plc = None): logger.log("omf_resctl.GetSlivers") if 'accounts' not in data: @@ -125,7 +93,7 @@ def GetSlivers(data, conf = None, plc = None): # xxx we might need to use # slice_command=['bash','-l','-c',omf_rc_trigger_script] slice_command = [omf_rc_trigger_script] - to_run = command_in_slice (slicename, slice_command) + to_run = tools.command_in_slice (slicename, slice_command) sp=subprocess.Popen(to_run, stdout=subprocess.PIPE,stderr=subprocess.STDOUT) (out,err)=sp.communicate() retcod=sp.returncode diff --git a/tools.py b/tools.py index afd55bd..4cbfa3b 100644 --- a/tools.py +++ b/tools.py @@ -289,3 +289,35 @@ 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..") + vs_retcod=subprocess.call ([ 'vserver', '--help' ]) + if vs_retcod == 0: + virt='vs' + else: + virt='lxc' + with file(virt_stamp,"w") as f: + f.write(virt) + return virt + +def command_in_slice (slicename, argv): + # with vserver this can be done using vserver .. exec + # with lxc this is less clear as we are still discussing how lxcsu should behave + # ideally we'd need to run lxcsu .. + virt=get_node_virt() + if virt=='vs': + return [ 'vserver', slicename, 'exec', ] + argv + elif virt=='lxc': + return [ 'lxcsu', slicename, ] + argv + logger.log("command_in_slice: WARNING: could not find a valid virt") + return argv + -- 2.43.0