List subnets in a virtual network.
17456
def list_subnets(call=None, kwargs=None):
    '''
    
    '''
    if kwargs is None:
        kwargs = {}

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

    netconn = get_conn(client_type='network')

    resource_group = kwargs.get('resource_group') or config.get_cloud_config_value(
                         'resource_group',
                         get_configured_provider(), __opts__, search_global=False
                     )

    if not resource_group and 'group' in kwargs and 'resource_group' not in kwargs:
        resource_group = kwargs['group']

    if not resource_group:
        raise SaltCloudSystemExit(
            'A resource group must be specified'
        )

    if kwargs.get('network') is None:
        kwargs['network'] = config.get_cloud_config_value(
            'network', get_configured_provider(), __opts__, search_global=False
        )

    if 'network' not in kwargs or kwargs['network'] is None:
        raise SaltCloudSystemExit(
            'A "network" must be specified'
        )

    ret = {}
    subnets = netconn.subnets.list(resource_group, kwargs['network'])
    for subnet in subnets:
        ret[subnet.name] = subnet.as_dict()
        ret[subnet.name]['ip_configurations'] = {}
        for ip_ in subnet.ip_configurations:
            comps = ip_.id.split('/')
            name = comps[-1]
            ret[subnet.name]['ip_configurations'][name] = ip_.as_dict()
            ret[subnet.name]['ip_configurations'][name]['subnet'] = subnet.name
        ret[subnet.name]['resource_group'] = resource_group
    return ret
938208
def list(self):
        
        try:
            return (yield from self._vmware_manager.list_vms())
        except VMwareError as e:
            raise GNS3VMError("Could not list VMware VMs: {}".format(str(e)))
485530
def list_network_ip_availabilities(self, retrieve_all=True, **_params):
        """"""
        return self.list('network_ip_availabilities',
                         self.network_ip_availabilities_path,
                         retrieve_all, **_params)
985650
def _get_subnets_table(subnets):
    
    table = formatting.Table(['id',
                              'network identifier',
                              'cidr',
                              'note'])
    for subnet in subnets:
        table.add_row([subnet.get('id', ''),
                       subnet.get('networkIdentifier', ''),
                       subnet.get('cidr', ''),
                       subnet.get('note', '')])
    return table
1358345
def list_networks(self, retrieve_all=True, **_params):
        """"""
        # Pass filters in "params" argument to do_request
        return self.list('networks', self.networks_path, retrieve_all,
                         **_params)
439281
def get_network():
    """"""
    meta = SoftLayer.MetadataManager()
    network_tables = []
    for network_func in [meta.public_network, meta.private_network]:
        network = network_func()

        table = formatting.KeyValueTable(['name', 'value'])
        table.align['name'] = 'r'
        table.align['value'] = 'l'
        table.add_row(['mac addresses',
                       formatting.listing(network['mac_addresses'],
                                          separator=',')])
        table.add_row(['router', network['router']])
        table.add_row(['vlans',
                       formatting.listing(network['vlans'], separator=',')])
        table.add_row(['vlan ids',
                       formatting.listing(network['vlan_ids'], separator=',')])
        network_tables.append(table)

    return network_tables
63652
def virtual_interface_list(self, name):
        '''
        
        '''
        nt_ks = self.compute_conn
        nets = nt_ks.virtual_interfaces.list(self._server_uuid_from_name(name))
        return [network.__dict__ for network in nets]
1098384
def interface_list(env, securitygroup_id, sortby):
    """"""
    mgr = SoftLayer.NetworkManager(env.client)

    table = formatting.Table(COLUMNS)
    table.sortby = sortby

    mask = (
        '''networkComponentBindings[
            networkComponentId,
            networkComponent[
                id,
                port,
                guest[
                    id,
                    hostname,
                    primaryBackendIpAddress,
                    primaryIpAddress
                ]
            ]
        ]'''
    )

    secgroup = mgr.get_securitygroup(securitygroup_id, mask=mask)
    for binding in secgroup.get('networkComponentBindings', []):
        interface_id = binding['networkComponentId']
        try:
            interface = binding['networkComponent']
            vsi = interface['guest']
            vsi_id = vsi['id']
            hostname = vsi['hostname']
            priv_pub = 'PRIVATE' if interface['port'] == 0 else 'PUBLIC'
            ip_address = (vsi['primaryBackendIpAddress']
                          if interface['port'] == 0
                          else vsi['primaryIpAddress'])
        except KeyError:
            vsi_id = "N/A"
            hostname = "Not enough permission to view"
            priv_pub = "N/A"
            ip_address = "N/A"

        table.add_row([
            interface_id,
            vsi_id,
            hostname,
            priv_pub,
            ip_address
        ])

    env.fout(table)
724221
async def list_vms(self, preset_name):
        """"""
        return list(vm for vm in self._vms.values() if vm.name == preset_name)
969683
def _get_ips(networks):
    '''
    
    '''
    v4s = networks.get('v4')
    v6s = networks.get('v6')
    public_ips = []
    private_ips = []

    if v4s:
        for item in v4s:
            ip_type = item.get('type')
            ip_address = item.get('ip_address')
            if ip_type == 'public':
                public_ips.append(ip_address)
            if ip_type == 'private':
                private_ips.append(ip_address)

    if v6s:
        for item in v6s:
            ip_type = item.get('type')
            ip_address = item.get('ip_address')
            if ip_type == 'public':
                public_ips.append(ip_address)
            if ip_type == 'private':
                private_ips.append(ip_address)

    return public_ips, private_ips
537293
def list_vpnservices(self, retrieve_all=True, **_params):
        """"""
        return self.list('vpnservices', self.vpnservices_path, retrieve_all,
                         **_params)
771699
def ip_in_subnet(ip, subnet):
    """"""
    ipaddr = int(''.join(['%02x' % int(x) for x in ip.split('.')]), 16)
    netstr, bits = subnet.split('/')
    netaddr = int(''.join(['%02x' % int(x) for x in netstr.split('.')]), 16)
    mask = (0xffffffff << (32 - int(bits))) & 0xffffffff
    return (ipaddr & mask) == (netaddr & mask)
227445
def list_virtual_networks(kwargs=None, conn=None, call=None):
    '''
    
    '''
    if call != 'function':
        raise SaltCloudSystemExit(
            'The list_virtual_networks function must be called with -f or --function.'
        )

    path = 'services/networking/virtualnetwork'
    data = query(path)
    return data
1021078
def show_subnet(self, subnet, **_params):
        """"""
        return self.get(self.subnet_path % (subnet), params=_params)
186072
def list_nics(nic_type=None):
    """"""
    if isinstance(nic_type, six.string_types):
        int_types = [nic_type]
    else:
        int_types = nic_type

    interfaces = []
    if nic_type:
        for int_type in int_types:
            cmd = ['ip', 'addr', 'show', 'label', int_type + '*']
            ip_output = subprocess.check_output(cmd).decode('UTF-8')
            ip_output = ip_output.split('\n')
            ip_output = (line for line in ip_output if line)
            for line in ip_output:
                if line.split()[1].startswith(int_type):
                    matched = re.search('.*: (' + int_type +
                                        r'[0-9]+\.[0-9]+)@.*', line)
                    if matched:
                        iface = matched.groups()[0]
                    else:
                        iface = line.split()[1].replace(":", "")

                    if iface not in interfaces:
                        interfaces.append(iface)
    else:
        cmd = ['ip', 'a']
        ip_output = subprocess.check_output(cmd).decode('UTF-8').split('\n')
        ip_output = (line.strip() for line in ip_output if line)

        key = re.compile(r'^[0-9]+:\s+(.+):')
        for line in ip_output:
            matched = re.search(key, line)
            if matched:
                iface = matched.group(1)
                iface = iface.partition("@")[0]
                if iface not in interfaces:
                    interfaces.append(iface)

    return interfaces
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)]
588986
def router_connections(self):
        """"""
        clients = []
        for server in self._routers:
            if Servers().is_alive(server):
                client = self.create_connection(Servers().hostname(server))
                clients.append(client)
        return clients