Get domain network interfaces from a libvirt domain object.
19996
def _get_nics(dom):
    '''
    
    '''
    nics = {}
    doc = ElementTree.fromstring(dom.XMLDesc(0))
    for iface_node in doc.findall('devices/interface'):
        nic = {}
        nic['type'] = iface_node.get('type')
        for v_node in iface_node:
            if v_node.tag == 'mac':
                nic['mac'] = v_node.get('address')
            if v_node.tag == 'model':
                nic['model'] = v_node.get('type')
            if v_node.tag == 'target':
                nic['target'] = v_node.get('dev')
            # driver, source, and match can all have optional attributes
            if re.match('(driver|source|address)', v_node.tag):
                temp = {}
                for key, value in six.iteritems(v_node.attrib):
                    temp[key] = value
                nic[v_node.tag] = temp
            # virtualport needs to be handled separately, to pick up the
            # type attribute of the virtualport itself
            if v_node.tag == 'virtualport':
                temp = {}
                temp['type'] = v_node.get('type')
                for key, value in six.iteritems(v_node.attrib):
                    temp[key] = value
                nic['virtualport'] = temp
        if 'mac' not in nic:
            continue
        nics[nic['mac']] = nic
    return nics
185882
def list(gandi, fqdn, name, sort, type, rrset_type, text):
    """"""
    domains = gandi.dns.list()
    domains = [domain['fqdn'] for domain in domains]
    if fqdn not in domains:
        gandi.echo('Sorry domain %s does not exist' % fqdn)
        gandi.echo('Please use one of the following: %s' % ', '.join(domains))
        return

    output_keys = ['name', 'ttl', 'type', 'values']

    result = gandi.dns.records(fqdn, sort_by=sort, text=text)
    if text:
        gandi.echo(result)
        return result

    for num, rec in enumerate(result):
        if type and rec['rrset_type'] != type:
            continue
        if rrset_type and rec['rrset_type'] != rrset_type:
            continue
        if name and rec['rrset_name'] != name:
            continue
        if num:
            gandi.separator_line()
        output_dns_records(gandi, rec, output_keys)

    return result
661931
def interfaces(self):
        
        if 'interfaces' not in self._cached_values:
            self._cached_values['interfaces'] = []
            for name, interface in six.iteritems(self.settings.INTERFACES):
                listen = interface.get('LISTEN')
                unix_socket = interface.get('UNIX_SOCKET')
                if not listen and not unix_socket:
                    raise ValueError(
                        'Interface MUST listen either on TCP '
                        'or UNIX socket or both')
                host, port = parse_host(listen) if listen else (None, None)
                processes = int(interface.get('PROCESSES', 1))
                urls_obj_name = interface.get('URLS', '')
                if urls_obj_name:
                    urls = import_object(urls_obj_name)
                else:
                    urls = ()
                self._cached_values['interfaces'].append(
                    self.Interface(
                        name, host, port, unix_socket, processes, urls)
                )
        return self._cached_values['interfaces']
115439
def interfaces():
    

    results = []
    if not sys.platform.startswith("win"):
        net_if_addrs = psutil.net_if_addrs()
        for interface in sorted(net_if_addrs.keys()):
            ip_address = ""
            mac_address = ""
            netmask = ""
            interface_type = "ethernet"
            for addr in net_if_addrs[interface]:
                # get the first available IPv4 address only
                if addr.family == socket.AF_INET:
                    ip_address = addr.address
                    netmask = addr.netmask
                if addr.family == psutil.AF_LINK:
                    mac_address = addr.address
            if interface.startswith("tap"):
                # found no way to reliably detect a TAP interface
                interface_type = "tap"
            results.append({"id": interface,
                            "name": interface,
                            "ip_address": ip_address,
                            "netmask": netmask,
                            "mac_address": mac_address,
                            "type": interface_type})
    else:
        try:
            service_installed = True
            if not _check_windows_service("npf") and not _check_windows_service("npcap"):
                service_installed = False
            else:
                results = get_windows_interfaces()
        except ImportError:
            message = "pywin32 module is not installed, please install it on the server to get the available interface names"
            raise aiohttp.web.HTTPInternalServerError(text=message)
        except Exception as e:
            log.error("uncaught exception {type}".format(type=type(e)), exc_info=1)
            raise aiohttp.web.HTTPInternalServerError(text="uncaught exception: {}".format(e))

        if service_installed is False:
            raise aiohttp.web.HTTPInternalServerError(text="The Winpcap or Npcap is not installed or running")

    # This interface have special behavior
    for result in results:
        result["special"] = False
        for special_interface in ("lo", "vmnet", "vboxnet", "docker", "lxcbr",
                                  "virbr", "ovs-system", "veth", "fw", "p2p",
                                  "bridge", "vmware", "virtualbox", "gns3"):
            if result["name"].lower().startswith(special_interface):
                result["special"] = True
        for special_interface in ("-nic"):
            if result["name"].lower().endswith(special_interface):
                result["special"] = True
    return results
1319815
def host_interface_object
      VirtualBox::Global.global.host.network_interfaces.find do |ni|
        ni.name == host_only_interface
      end
    end
979678
def domain_list(gandi):
    """"""
    domains = gandi.dns.list()
    for domain in domains:
        gandi.echo(domain['fqdn'])

    return domains
464616
def list_nodes(call=None):
    '''
    

    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The list_nodes function must be called '
            'with -f or --function.'
        )

    providers = __opts__.get('providers', {})

    ret = {}
    providers_to_check = [_f for _f in [cfg.get('libvirt') for cfg in six.itervalues(providers)] if _f]
    for provider in providers_to_check:
        conn = __get_conn(provider['url'])
        domains = conn.listAllDomains()
        for domain in domains:
            data = {
                'id': domain.UUIDString(),
                'image': '',
                'size': '',
                'state': VIRT_STATE_NAME_MAP[domain.state()[0]],
                'private_ips': [],
                'public_ips': get_domain_ips(domain, libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE)}
            # TODO: Annoyingly name is not guaranteed to be unique, but the id will not work in other places
            ret[domain.name()] = data

    return ret
1189012
def get_existing_domain(conn, name)
      return conn.lookup_domain_by_name(name)
    rescue Libvirt::Error => e
      return nil if e.libvirt_code == 42 # If domain not defined
      raise # Otherwise reraise
    end
442361
def network_hosts(value, options=None, version=None):
    '''
    
    '''
    ipaddr_filter_out = _filter_ipaddr(value, options=options, version=version)
    if not ipaddr_filter_out:
        return
    if not isinstance(value, (list, tuple, types.GeneratorType)):
        return _network_hosts(ipaddr_filter_out[0])
    return [
        _network_hosts(ip_a)
        for ip_a in ipaddr_filter_out
    ]
771501
def list_nic(self, instance_id):
        
        #NOTE: interfaces a list of novaclient.v2.servers.Server
        interfaces = self.client.servers.interface_list(instance_id)
        return interfaces
106328
def get_join_info():
    '''
    
    '''
    info = win32net.NetGetJoinInformation()
    status = {win32netcon.NetSetupUnknown: 'Unknown',
              win32netcon.NetSetupUnjoined: 'Unjoined',
              win32netcon.NetSetupWorkgroupName: 'Workgroup',
              win32netcon.NetSetupDomainName: 'Domain'}
    return {'Domain': info[0],
            'DomainType': status[info[1]]}
486048
def getservers(self, vhost = None):
        '''
        
        '''
        if vhost is not None:
            return [s for s in self.connections if s.protocol.vhost == vhost]
        else:
            return list(self.connections)
930055
def get_domainalias(self, domainid, aliasid):
        """"""
        return self.api_call(
            ENDPOINTS['domainaliases']['get'],
            dict(domainid=domainid, aliasid=aliasid))
552758
def get_vm_instances(instance_id=None):
    """"""
    return get_instances(device_owners=[n_const.DEVICE_OWNER_COMPUTE_PREFIX],
                         vnic_type=portbindings.VNIC_NORMAL,
                         instance_id=instance_id)
336527
def in6_getifaddr():
    

    # List all network interfaces
    if OPENBSD:
        try:
            f = os.popen("%s" % conf.prog.ifconfig)
        except OSError:
            log_interactive.warning("Failed to execute ifconfig.")
            return []

        # Get the list of network interfaces
        splitted_line = []
        for l in f:
            if "flags" in l:
                iface = l.split()[0].rstrip(':')
                splitted_line.append(iface)

    else:  # FreeBSD, NetBSD or Darwin
        try:
            f = os.popen("%s -l" % conf.prog.ifconfig)
        except OSError:
            log_interactive.warning("Failed to execute ifconfig.")
            return []

        # Get the list of network interfaces
        splitted_line = f.readline().rstrip().split()

    ret = []
    for i in splitted_line:
        ret += _in6_getifaddr(i)
    return ret
865209
def get_interfaces(self):
        
        interfaces = self.xml.find('devices').iter('interface')
        iobjs = []
        for interface in interfaces:
            _type = interface.attrib['type']
            mac = interface.find('mac').attrib['address']
            source = interface.find('source').attrib[_type]
            model = interface.find('model').attrib['type']
            iobjs.append(NetworkInterface(_type, mac, source, model))
        return iobjs
987285
def interface_lookup(interfaces, hwaddr, address_type):
    """"""
    for interface in interfaces.values():
        if interface.get('hwaddr') == hwaddr:
            for address in interface.get('addrs'):
                if address.get('type') == address_type:
                    return address.get('addr')