Returns a list of subnets to which the host belongs
486597
def _subnets(proto='inet', interfaces_=None):
    '''
    
    '''
    if interfaces_ is None:
        ifaces = interfaces()
    elif isinstance(interfaces_, list):
        ifaces = {}
        for key, value in six.iteritems(interfaces()):
            if key in interfaces_:
                ifaces[key] = value
    else:
        ifaces = {interfaces_: interfaces().get(interfaces_, {})}

    ret = set()

    if proto == 'inet':
        subnet = 'netmask'
        dflt_cidr = 32
    elif proto == 'inet6':
        subnet = 'prefixlen'
        dflt_cidr = 128
    else:
        log.error('Invalid proto %s calling subnets()', proto)
        return

    for ip_info in six.itervalues(ifaces):
        addrs = ip_info.get(proto, [])
        addrs.extend([addr for addr in ip_info.get('secondary', []) if addr.get('type') == proto])

        for intf in addrs:
            if subnet in intf:
                intf = ipaddress.ip_interface('{0}/{1}'.format(intf['address'], intf[subnet]))
            else:
                intf = ipaddress.ip_interface('{0}/{1}'.format(intf['address'], dflt_cidr))
            if not intf.is_loopback:
                ret.add(intf.network)
    return [six.text_type(net) for net in sorted(ret)]
1207149
def get_slave_addrs(mgr_addr, N):
    '''
    '''
    return  [(HOST, p) for p in range(mgr_addr+1, mgr_addr+1+N)]
956160
async def ListSubnets(self, space_tag, zone):
        '''
        
        '''
        # map input types to rpc msg
        _params = dict()
        msg = dict(type='DiscoverSpaces',
                   request='ListSubnets',
                   version=2,
                   params=_params)
        _params['space-tag'] = space_tag
        _params['zone'] = zone
        reply = await self.rpc(msg)
        return reply
299489
def nslookup(host):
    '''
    
    '''
    ret = []
    addresses = []
    cmd = ['nslookup', salt.utils.network.sanitize_host(host)]
    lines = __salt__['cmd.run'](cmd, python_shell=False).splitlines()
    for line in lines:
        if addresses:
            # We're in the last block listing addresses
            addresses.append(line.strip())
            continue
        if line.startswith('Non-authoritative'):
            continue
        if 'Addresses' in line:
            comps = line.split(":", 1)
            addresses.append(comps[1].strip())
            continue
        if ":" in line:
            comps = line.split(":", 1)
            ret.append({comps[0].strip(): comps[1].strip()})
    if addresses:
        ret.append({'Addresses': addresses})
    return ret
799394
def list_nodes():
    '''
    
    '''
    ret = {}
    nodes = list_nodes_full()
    for node in nodes:
        ret[node] = {
            'id': nodes[node]['UUID'],
            'image': nodes[node]['Guest OS'],
            'name': nodes[node]['Name'],
            'state': None,
            'private_ips': [],
            'public_ips': [],
        }
        ret[node]['size'] = '{0} RAM, {1} CPU'.format(
            nodes[node]['Memory size'],
            nodes[node]['Number of CPUs'],
        )
    return ret
302156
def dns():
    '''
    
    '''
    # Provides:
    #   dns
    if salt.utils.platform.is_windows() or 'proxyminion' in __opts__:
        return {}

    resolv = salt.utils.dns.parse_resolv()
    for key in ('nameservers', 'ip4_nameservers', 'ip6_nameservers',
                'sortlist'):
        if key in resolv:
            resolv[key] = [six.text_type(i) for i in resolv[key]]

    return {'dns': resolv} if resolv else {}
385699
def list_subdomains(self, limit=None, offset=None):
        
        return self.manager.list_subdomains(self, limit=limit, offset=offset)
1341502
def get_members_of_group(self, gname):
        
        hostgroup = self.find_by_name(gname)
        if hostgroup:
            return hostgroup.get_hosts()
        return []
429218
def get_hosts(self):
        
        limited_hosts = {}
        if self.limit is not None:
            # Find hosts and groups of hosts to include
            for include in self.limit['include']:
                # Include whole group
                for hostname in self.hosts_in_group(include):
                    limited_hosts[hostname] = self.hosts[hostname]
                # Include individual host
                if include in self.hosts:
                    limited_hosts[include] = self.hosts[include]
            # Find hosts and groups of hosts to exclude
            for exclude in self.limit["exclude"]:
                # Exclude whole group
                for hostname in self.hosts_in_group(exclude):
                    if hostname in limited_hosts:
                        limited_hosts.pop(hostname)
                # Exclude individual host
                if exclude in limited_hosts:
                    limited_hosts.pop(exclude)

            return limited_hosts
        else:
            # Return all hosts
            return self.hosts
445858
def get_host_map(root):
  ''' 
  '''
  hosts_map = {}
  for host in root.get_all_hosts():
    hosts_map[host.hostId] = {"hostname": NAGIOS_HOSTNAME_FORMAT % (host.hostname,),
                              "address": host.ipAddress}

  ''' Also define "virtual hosts" for the CM clusters- they will be the hosts
      to which CM services are mapped
  '''
  for cluster in root.get_all_clusters():
    hosts_map[cluster.name] = {"hostname": cluster.name,
                               "address": quote(cluster.name)}
  hosts_map[CM_DUMMY_HOST] = {"hostname": CM_DUMMY_HOST,
                              "address": CM_DUMMY_HOST}
  return hosts_map
497202
def get_hosts_info(self):
        
        result = []
        index = 0
        while index < self.host_numbers:
            host = self.get_generic_host_entry(index)
            result.append({
                'ip': host['NewIPAddress'],
                'name': host['NewHostName'],
                'mac': host['NewMACAddress'],
                'status': host['NewActive']})
            index += 1
        return result
1299687
def _get_distinct_hostnames(self):
        
        hostnames = []
        for section in self.sections:
            hostnames.extend(self._group_get_hostnames(section['name']))
        return set(hostnames)
1197969
def get_ssh_subsystem_names(self):
        
        preferred_ssh_subsystem = self.device_params.get("ssh_subsystem_name")
        name_list = [ "netconf", "xmlagent" ]
        if preferred_ssh_subsystem:
            return [ preferred_ssh_subsystem ] + \
                        [ n for n in name_list if n != preferred_ssh_subsystem ]
        else:
            return name_list
581420
def list_cache_subnet_groups(region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    return [g['CacheSubnetGroupName'] for g in
            describe_cache_subnet_groups(None, region, key, keyid, profile)]
1189798
def list_dhcp_agent_hosting_networks(self, network, **_params):
        """"""
        return self.get((self.network_path + self.DHCP_AGENTS) % network,
                        params=_params)
1273141
def subdomains(self, value=None):
        
        if value is not None:
            return URL._mutate(self, host='.'.join(value))
        return self.host().split('.')
1347686
def hosts_in_group(self, groupname):
        
        result = []
        for hostname, hostinfo in self.hosts.items():
            if groupname == 'all':
                result.append(hostname)
            elif 'groups' in hostinfo:
                if groupname in hostinfo['groups']:
                    result.append(hostname)
            else:
                hostinfo['groups'] = [groupname]
        return result