Determine the port type based on device owner and vnic type
436982
def get_instance_type(self, port):
        """"""
        if port[portbindings.VNIC_TYPE] == portbindings.VNIC_BAREMETAL:
            return a_const.BAREMETAL_RESOURCE
        owner_to_type = {
            n_const.DEVICE_OWNER_DHCP: a_const.DHCP_RESOURCE,
            n_const.DEVICE_OWNER_DVR_INTERFACE: a_const.ROUTER_RESOURCE,
            trunk_consts.TRUNK_SUBPORT_OWNER: a_const.VM_RESOURCE}
        if port['device_owner'] in owner_to_type.keys():
            return owner_to_type[port['device_owner']]
        elif port['device_owner'].startswith(
                n_const.DEVICE_OWNER_COMPUTE_PREFIX):
            return a_const.VM_RESOURCE
        return None
572773
def check_serial_port(name):
    """"""
    try:
        cdc = next(serial.tools.list_ports.grep(name))
        return cdc[0]
    except StopIteration:
        msg = "device {} not found. ".format(name)
        msg += "available devices are: "
        ports = list(serial.tools.list_ports.comports())
        for p in ports:
            msg += "{},".format(text_type(p))
        raise ValueError(msg)
153729
def get_device_type(device_type=0):
    """"""
    device_types = {
        0: "Unknown",
        1: "Classic - BR/EDR devices",
        2: "Low Energy - LE-only",
        3: "Dual Mode - BR/EDR/LE"
    }
    if device_type in [0, 1, 2, 3]:
        return_value = device_types[device_type]
    else:
        return_value = device_types[0]
    return return_value
76211
def _update_port_group_info(self, switches=None):
        """"""
        if switches is None:
            switches = self._switches.keys()
        for switch_ip in switches:
            client = self._switches.get(switch_ip)
            ret = self._run_eos_cmds(['show interfaces'], client)
            if not ret or len(ret) == 0:
                LOG.warning("Unable to retrieve interface info for %s",
                            switch_ip)
                continue
            intf_info = ret[0]
            self._port_group_info[switch_ip] = intf_info.get('interfaces', {})
996020
function (port, parent_port) {

	// check if the port wasn't reported
	if (l_ports.hasOwnProperty(port) === false) {
		
		LOG.warn('recording used port [' + port + ']...', 'SR.Monitor');	
		l_ports[port] = parent_port || port;
	}
}
1044024
def find_device(vidpid):
    """"""
    for port in list_ports.comports():
        if re.search(vidpid, port[2], flags=re.IGNORECASE):
            return port[0]

    raise exceptions.RoasterLookupError
362676
def _map_device_on_host_networks(provider_nets, devices):
    """"""
    networks = copy.deepcopy(provider_nets)
    for network in networks:
        for device in devices:
            network.setdefault('device', None)
            ip_set = IPSet([network['cidr']])
            if 'ipv4' not in device:
                continue
            ips = device['ipv4']
            if not isinstance(ips, list):
                ips = [ips]
            if len(ips) < 1:
                continue
            ip = IPAddress(ips[0]['address'])
            if ip in ip_set:
                network['device'] = device['device']
                continue
    return networks
43200
def vnic_attach_to_network_distributed(nicspec, port_group, logger):
        
        if nicspec and network_is_portgroup(port_group):
            network_name = port_group.name

            dvs_port_connection = vim.dvs.PortConnection()
            dvs_port_connection.portgroupKey = port_group.key
            dvs_port_connection.switchUuid = port_group.config.distributedVirtualSwitch.uuid

            nicspec.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
            nicspec.device.backing.port = dvs_port_connection

            logger.debug(u"Assigning portgroup '{}' for vNIC".format(network_name))
        else:
            logger.warn(u"Cannot assigning portgroup for vNIC")
        return nicspec
298930
def get_network_adapter_object_type(adapter_object):
    '''
    
    '''
    if isinstance(adapter_object, vim.vm.device.VirtualVmxnet2):
        return 'vmxnet2'
    if isinstance(adapter_object, vim.vm.device.VirtualVmxnet3):
        return 'vmxnet3'
    if isinstance(adapter_object, vim.vm.device.VirtualVmxnet):
        return 'vmxnet'
    if isinstance(adapter_object, vim.vm.device.VirtualE1000e):
        return 'e1000e'
    if isinstance(adapter_object, vim.vm.device.VirtualE1000):
        return 'e1000'

    raise ValueError('An unknown network adapter object type.')
1365411
def get_default_net_device():
    
    with open('/proc/net/route') as fh:
        for line in fh:
            iface, dest, _ = line.split(None, 2)
            if dest == '00000000':
                return iface
    return None
1165662
def systemInformationType2bis():
    """"""
    a = L2PseudoLength(l2pLength=0x15)
    b = TpPd(pd=0x6)
    c = MessageType(mesType=0x2)  # 00000010
    d = NeighbourCellsDescription()
    e = RachControlParameters()
    f = Si2bisRestOctets()
    packet = a / b / c / d / e / f
    return packet
564925
def filter_by_vnic_type(query, vnic_type):
    """"""
    port_model = models_v2.Port
    binding_model = ml2_models.PortBinding
    dst_binding_model = ml2_models.DistributedPortBinding
    query = (query
             .outerjoin_if_necessary(
                 binding_model,
                 port_model.id == binding_model.port_id)
             .outerjoin_if_necessary(
                 dst_binding_model,
                 port_model.id == dst_binding_model.port_id)
             .filter(
                 (binding_model.vnic_type == vnic_type) |
                 (dst_binding_model.vnic_type == vnic_type)))
    return query
80421
def _port_action_vlan(self, port, segment, func, vni):
        """"""

        # Verify segment.
        if not self._is_valid_segment(segment):
            return

        device_id = self._get_port_uuid(port)

        if nexus_help.is_baremetal(port):
            host_id = port.get('dns_name')
        else:
            host_id = port.get(bc.portbindings.HOST_ID)

        vlan_id = segment.get(api.SEGMENTATION_ID)
        is_provider = nxos_db.is_provider_vlan(vlan_id)

        settings = {"vlan_id": vlan_id,
                    "device_id": device_id,
                    "host_id": host_id}
        missing_fields = [field for field, value in settings.items()
                          if (field != 'host_id' and not value)]
        if not missing_fields:
            func(port, vlan_id, device_id, host_id, vni, is_provider)
        else:
            raise excep.NexusMissingRequiredFields(
                fields=' '.join(missing_fields))
290436
def addr(self):
        """"""
        port = self.port
        if port:
            port = int(port)
        else:
            port = default_ports.get(self.scheme or 'http')
        return (self.host, port)
437392
def vm_ip(cls, vm_id):
        """"""
        vm_info = cls.info(vm_id)

        for iface in vm_info['ifaces']:
            if iface['type'] == 'private':
                continue
            for ip in iface['ips']:
                return ip['version'], ip['ip']
475401
def network_type=(type)
      no_cmd = (type == default_network_type) ? 'no' : ''
      network = (type == default_network_type) ? '' : type
      network = 'point-to-point' if type.to_s == 'p2p'
      config_set('interface_ospf', 'network_type', @interface.name,
                 no_cmd, network)
    end
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)