X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=tools.py;h=1cef74699ecbe58cac5b2d7cbc69e4d321ae82ba;hb=e57432c1dfdfeaa52cc32799e2abbc34b7704ce9;hp=42d63d131be77d9c7a0243189cb287aba3a73e6d;hpb=9fbee5e89fe13eb431318b07e4438d4d5e368cfc;p=nodemanager.git diff --git a/tools.py b/tools.py index 42d63d1..1cef746 100644 --- a/tools.py +++ b/tools.py @@ -215,10 +215,11 @@ class NMLock: # running ifconfig inside of the slice's context. def get_sliver_process(slice_name, process_cmdline): - """ Utility function to find a process inside of an LXC sliver. Returns - (cgroup_fn, pid). cgroup_fn is the filename of the cgroup file for - the process, for example /proc/2592/cgroup. Pid is the process id of - the process. If the process is not found then (None, None) is returned. + """ + Utility function to find a process inside of an LXC sliver. Returns + (cgroup_fn, pid). cgroup_fn is the filename of the cgroup file for + the process, for example /proc/2592/cgroup. Pid is the process id of + the process. If the process is not found then (None, None) is returned. """ try: cmd = 'grep %s /proc/*/cgroup | grep freezer'%slice_name @@ -236,8 +237,8 @@ def get_sliver_process(slice_name, process_cmdline): path = l.split(':')[0] comp = l.rsplit(':')[-1] slice_name_check = comp.rsplit('/')[-1] - # the lines above were added by Guilherme - # due to the ipv6 plugin requirements + # the lines below were added by Guilherme + # due to the ipv6 plugin requirements (LXC) virt=get_node_virt() if virt=='lxc': slice_name_check = slice_name_check.rsplit('.')[0] @@ -262,9 +263,12 @@ def get_sliver_process(slice_name, process_cmdline): # Added by Guilherme Sperb Machado ################################################### -import re -import socket -import fileinput +try: + import re + import socket + import fileinput +except: + logger.log("Could not import 're', 'socket', or 'fileinput' python packages.") # TODO: is there anything better to do if the "libvirt", "sliver_libvirt", # and "sliver_lxc" are not in place? @@ -273,13 +277,14 @@ try: from sliver_libvirt import Sliver_Libvirt import sliver_lxc except: - logger.log("Could not import sliver_lxc or libvirt or sliver_libvirt -- which is required here.") + logger.log("Could not import 'sliver_lxc' or 'libvirt' or 'sliver_libvirt'.") ################################################### def get_sliver_ifconfig(slice_name, device="eth0"): - """ return the output of "ifconfig" run from inside the sliver. + """ + return the output of "ifconfig" run from inside the sliver. - side effects: adds "/usr/sbin" to sys.path + side effects: adds "/usr/sbin" to sys.path """ # See if setns is installed. If it's not then we're probably not running @@ -425,16 +430,27 @@ def get_hosts_file_path(slicename): ################################################### # Search if there is a specific ipv6 address in the # /etc/hosts file of a given slice +# If the parameter 'ipv6addr' is None, then search +# for any ipv6 address ################################################### def search_ipv6addr_hosts(slicename, ipv6addr): hostsFilePath = get_hosts_file_path(slicename) found=False try: for line in fileinput.input(r'%s' % (hostsFilePath)): - if re.search(r'%s' % (ipv6addr), line): - found=True - fileinput.close() - return found + if ipv6addr is not None: + if re.search(r'%s' % (ipv6addr), line): + found=True + else: + search = re.search(r'^(.*)\s+.*$', line) + if search: + ipv6candidate = search.group(1) + ipv6candidatestrip = ipv6candidate.strip() + valid = is_valid_ipv6(ipv6candidatestrip) + if valid: + found=True + fileinput.close() + return found except: logger.log("tools: FAILED to search %s in /etc/hosts file of slice=%s" % \ (ipv6addr, slicename) )