def ip_to_hostonlyif(ip): ip_net_address = hf.ip_to_net_address(ip) if not conf.do_build: # Add placeholders for wbatch code for index, (net_name, net_address) in enumerate(conf.networks.iteritems()): if net_address == ip_net_address: if_name = "vboxnet{}".format(index) logger.debug("%s %s %s", net_address, net_name, if_name) return if_name output = vbm("list", "hostonlyifs", wbatch=False) host_net_address = None for line in output.splitlines(): ma = re.match(r"Name:\s+(\S+)", line) if ma: if_name = ma.group(1) continue ma = re.match(r"IPAddress:\s+(\S+)", line) if ma: host_ip = ma.group(1) host_net_address = hf.ip_to_net_address(host_ip) if host_net_address == ip_net_address: return if_name
def ip_to_hostonlyif(ip): ip_net_address = hf.ip_to_net_address(ip) if not conf.do_build: # Add placeholders for wbatch code for index, (net_name, net_address) in enumerate( conf.networks.iteritems()): if net_address == ip_net_address: if_name = "vboxnet{}".format(index) logger.debug("%s %s %s", net_address, net_name, if_name) return if_name output = vbm("list", "hostonlyifs", wbatch=False) host_net_address = None for line in output.splitlines(): ma = re.match(r"Name:\s+(\S+)", line) if ma: if_name = ma.group(1) continue ma = re.match(r"IPAddress:\s+(\S+)", line) if ma: host_ip = ma.group(1) host_net_address = hf.ip_to_net_address(host_ip) if host_net_address == ip_net_address: return if_name
def ip_to_netname(ip): ip_net = hf.ip_to_net_address(ip) for net_name, net_address in conf.networks.items(): if net_address == ip_net: logger.debug("ip_to_netname %s -> %s", ip, net_name) return net_name logger.error("ip_to_netname: no netname found for %s.", ip) raise ValueError