diff --git a/src/execo_g5k/api_utils.py b/src/execo_g5k/api_utils.py index 016fe0bd29b6fd12b70a8d982b115d4ce89abdf4..bfa3e31565213056eeb12c5503816cd53569dea3 100644 --- a/src/execo_g5k/api_utils.py +++ b/src/execo_g5k/api_utils.py @@ -559,7 +559,7 @@ def get_host_site(host): return m.group(3) else: return get_cluster_site(m.group(1)) - else: return None + else: return None def get_host_network_equipments(host): """""" @@ -611,12 +611,12 @@ def get_network_equipment_attributes(equip): site = get_network_equipment_site(equip) return get_api_data()['network'][site][equip] -__canonical_host_name_regex = re.compile("^([a-zA-Z]+\d*-\d+)(-eth\d+)?(-kavlan-\d+)?(-ipv6)?(\.([.\w]+))?") +__canonical_host_name_regex = re.compile("^([a-zA-Z]+\d*-\d+)(-(?!kavlan-\d+)(?!ipv6)(\w+))?(-kavlan-\d+)?(-ipv6)?(\.([.\w]+))?$") def __canonical_sub_func(matchobj): n = matchobj.group(1) - if matchobj.lastindex >= 5: - n += matchobj.group(5) + if matchobj.lastindex >= 6: + n += matchobj.group(6) return n def canonical_host_name(host): @@ -633,6 +633,18 @@ def canonical_host_name(host): else: return h.address +__host_interface_regex = __canonical_host_name_regex + +def get_host_interface(host): + eth = None + h = execo.Host(host) + m = __host_interface_regex.search(h.address) + if m: + eth = m.group(3) + if not eth: + eth = 'eth0' + return eth + def get_host_shortname(host): """Convert, if needed, the host name to its shortname""" if isinstance(host, execo.Host):