Given a device name, return the corresponding interface object
172626
def interface_by_name(self, name):
        '''
        
        '''
        if name in self._devinfo:
            return self._devinfo[name]
        raise KeyError("No device named {}".format(name))
162128
def get_device(name, device_dict, loader, resource_dict):
    
    device = Device(name, device_dict.get('delimiter', ';').encode('utf-8'))

    device_dict = get_bases(device_dict, loader)

    err = device_dict.get('error', {})
    device.add_error_handler(err)

    for itype, eom_dict in device_dict.get('eom', {}).items():
        device.add_eom(itype, *_get_pair(eom_dict))

    update_component(name, device, device_dict)

    for ch_name, ch_dict in device_dict.get('channels', {}).items():
        device.add_channels(ch_name, get_channel(device, ch_name, ch_dict,
                                                 loader, resource_dict))

    return device
399010
def Get(self, interface_name, property_name):
        ''''''

        self.log('Get %s.%s' % (interface_name, property_name))

        if not interface_name:
            interface_name = self.interface
        try:
            return self.GetAll(interface_name)[property_name]
        except KeyError:
            raise dbus.exceptions.DBusException(
                'no such property ' + property_name,
                name=self.interface + '.UnknownProperty')
279532
def _get_base_interface_info(interface):
    '''
    
    '''
    blacklist = {
        'tcpip': {
            'name': [],
            'type': [],
            'additional_protocol': False
        },
        'disabled': {
            'name': ['eth0'],
            'type': ['gadget'],
            'additional_protocol': False
        },
        'ethercat': {
            'name': ['eth0'],
            'type': ['gadget', 'usb', 'wlan'],
            'additional_protocol': True
        },
        '_': {
            'usb': 'sys',
            'gadget': 'uevent',
            'wlan': 'uevent'
        }
    }
    return {
        'label': interface.name,
        'connectionid': interface.name,
        'supported_adapter_modes': _get_possible_adapter_modes(interface.name, blacklist),
        'adapter_mode': _get_adapter_mode_info(interface.name),
        'up': interface.flags & IFF_RUNNING != 0,
        'ipv4': {
            'supportedrequestmodes': ['dhcp_linklocal', 'dhcp_only', 'linklocal_only', 'static'],
            'requestmode': _get_request_mode_info(interface.name)
        },
        'hwaddr': interface.hwaddr[:-1]
    }
247707
def alter(self, interfaces):
        
        # fixup some things
        for device, device_dict in interfaces.items():
            if len(device_dict['inet4']) > 0:
                device_dict['inet'] = device_dict['inet4'][0]
            if 'inet' in device_dict and not device_dict['inet'] is None:
                try:
                    host = socket.gethostbyaddr(device_dict['inet'])[0]
                    interfaces[device]['hostname'] = host
                except (socket.herror, socket.gaierror):
                    interfaces[device]['hostname'] = None

            # To be sure that hex values and similar are always consistent, we
            # return everything in lowercase. For instance, Windows writes
            # MACs in upper-case.
            for key, device_item in device_dict.items():
                if hasattr(device_item, 'lower'):
                    interfaces[device][key] = device_dict[key].lower()

        return interfaces
71436
def _get_interfaces():
    """"""
    # Get CMSIS-DAPv1 interfaces.
    v1_interfaces = INTERFACE[USB_BACKEND].get_all_connected_interfaces()
    
    # Get CMSIS-DAPv2 interfaces.
    v2_interfaces = INTERFACE[USB_BACKEND_V2].get_all_connected_interfaces()
    
    # Prefer v2 over v1 if a device provides both.
    devices_in_both = [v1 for v1 in v1_interfaces for v2 in v2_interfaces
                        if _get_unique_id(v1) == _get_unique_id(v2)]
    for dev in devices_in_both:
        v1_interfaces.remove(dev)
        
    # Return the combined list.
    return v1_interfaces + v2_interfaces
1142983
def device_info(index=None):
    
    if index is None:
        return (device_info(i) for i in range(_pa.Pa_GetDeviceCount()))
    else:
        info = _pa.Pa_GetDeviceInfo(index)
        if not info:
            raise RuntimeError("Invalid device")
        assert info.structVersion == 2

        if 'DirectSound' in hostapi_info(info.hostApi)['name']:
            enc = 'mbcs'
        else:
            enc = 'utf-8'

        return {'name': ffi.string(info.name).decode(encoding=enc,
                                                     errors='ignore'),
                'hostapi': info.hostApi,
                'max_input_channels': info.maxInputChannels,
                'max_output_channels': info.maxOutputChannels,
                'default_low_input_latency': info.defaultLowInputLatency,
                'default_low_output_latency': info.defaultLowOutputLatency,
                'default_high_input_latency': info.defaultHighInputLatency,
                'default_high_output_latency': info.defaultHighOutputLatency,
                'default_samplerate': info.defaultSampleRate}
176368
def interface_by_macaddr(self, macaddr):
        '''
        
        '''
        macaddr = EthAddr(macaddr)
        for devname,iface in self._devinfo.items():
            if iface.ethaddr == macaddr:
                return iface
        raise KeyError("No device has MAC address {}".format(macaddr))
327419
def _get_interface_name_from_hosting_port(self, port):
        
        try:
            vlan = port['hosting_info']['segmentation_id']
            int_prefix = port['hosting_info']['physical_interface']
            return '%s.%s' % (int_prefix, vlan)
        except KeyError as e:
            params = {'key': e}
            raise cfg_exc.DriverExpectedKeyNotSetException(**params)
509274
def find_device_by_name(name):
    """"""
    if not name:
        return DEFAULT_DEV
    with DEV_LOCK:
        for dev in DEVS:
            if dev.name == name:
                return dev
    return None
983666
def _get_interface_info(interface):
    '''
    
    '''
    adapter_mode = _get_adapter_mode_info(interface.name)
    if adapter_mode == 'disabled':
        return _get_base_interface_info(interface)
    elif adapter_mode == 'ethercat':
        return _get_ethercat_interface_info(interface)
    return _get_tcpip_interface_info(interface)
324351
def get_interfaces(self):
        """"""
        result = {}

        interfaces = junos_views.junos_iface_table(self.device)
        interfaces.get()

        # convert all the tuples to our pre-defined dict structure
        for iface in interfaces.keys():
            result[iface] = {
                'is_up': interfaces[iface]['is_up'],
                'is_enabled': interfaces[iface]['is_enabled'],
                'description': (interfaces[iface]['description'] or u''),
                'last_flapped': float((interfaces[iface]['last_flapped'] or -1)),
                'mac_address': napalm_base.helpers.convert(
                    napalm_base.helpers.mac,
                    interfaces[iface]['mac_address'],
                    py23_compat.text_type(interfaces[iface]['mac_address'])),
                'speed': -1
            }
            # result[iface]['last_flapped'] = float(result[iface]['last_flapped'])

            match = re.search(r'(\d+)(\w*)', interfaces[iface]['speed'] or u'')
            if match is None:
                continue
            speed_value = napalm_base.helpers.convert(int, match.group(1), -1)
            if speed_value == -1:
                continue
            speed_unit = match.group(2)
            if speed_unit.lower() == 'gbps':
                speed_value *= 1000
            result[iface]['speed'] = speed_value

        return result
419691
def get_ports_by_name(device_name):
    ''''''
    filtered_devices = filter(
        lambda device: device_name in device[1],
        list_ports.comports()
    )
    device_ports = [device[0] for device in filtered_devices]
    return device_ports
816632
function getDeviceConnectionTypesData(deviceInfo) {
            if(false) {
                console.log(
                    'in getDeviceConnectionTypesData',
                    deviceInfo.serialNumber,
                    deviceInfo.ct,
                    deviceInfo.port,
                    deviceInfo.isActive,
                    deviceInfo.isMockDevice
                );//, Object.keys(deviceInfo));
            }
            var connectionTypes = [];

            var foundUSB = false;
            var usbInfo = {};
            var foundEth = false;
            var ethInfo = {};
            var foundWiFi = false;
            var wifiInfo = {};

            var usbCT = driver_const.connectionTypes.usb;
            var ethCT = driver_const.connectionTypes.ethernet;
            var wifiCT = driver_const.connectionTypes.wifi;
            if(deviceInfo.ct === usbCT) {
                usbInfo = createDeviceConnectionObj(
                    deviceInfo.dt,
                    deviceInfo.ct,
                    deviceInfo.serialNumber.toString()
                );
                // Always indicate that a USB device's USB connection 
                // is verified.
                usbInfo.isVerified = true;
                usbInfo.verified = true;
                
                usbInfo.isScanned = true;
                usbInfo.insertionMethod = 'scan';
                usbInfo.isActive = deviceInfo.isActive;
                if(deviceInfo.isActive) {
                    usbInfo.insertionMethod = 'connected';
                    usbInfo.isVerified = true;
                    usbInfo.verified = true;
                }
                foundUSB = true;
            } else if(deviceInfo.ct === ethCT) {
                ethInfo = createDeviceConnectionObj(
                    deviceInfo.dt,
                    deviceInfo.ct,
                    // deviceInfo.ip
                    deviceInfo.ethernetIP
                );
                ethInfo.isScanned = true;
                ethInfo.insertionMethod = 'scan';
                ethInfo.isActive = deviceInfo.isActive;
                if(deviceInfo.isActive) {
                    ethInfo.insertionMethod = 'connected';
                    ethInfo.isVerified = true;
                    ethInfo.verified = true;
                }
                foundEth = true;
            } else if(deviceInfo.ct === wifiCT) {
                wifiInfo = createDeviceConnectionObj(
                    deviceInfo.dt,
                    deviceInfo.ct,
                    // deviceInfo.ip
                    deviceInfo.wifiIP
                );
                wifiInfo.isScanned = true;
                wifiInfo.insertionMethod = 'scan';
                wifiInfo.isActive = deviceInfo.isActive;
                if(deviceInfo.isActive) {
                    wifiInfo.insertionMethod = 'connected';
                    wifiInfo.isVerified = true;
                    wifiInfo.verified = true;
                }
                foundWiFi = true;
            } else {
                console.error('openall_d_s, Encountered Invalid Connection Type', deviceInfo.ct);
            }

            if(!foundEth) {
                if(deviceInfo.ETHERNET_IP) {
                    if(deviceInfo.ETHERNET_IP.isReal) {
                        ethInfo = createDeviceConnectionObj(
                            deviceInfo.dt,
                            ethCT,
                            deviceInfo.ethernetIP
                        );
                        foundEth = true;
                        ethInfo.insertionMethod = 'attribute';
                        ethInfo.foundByAttribute = true;
                    }
                }
            }
            if(!foundWiFi) {
                if(deviceInfo.WIFI_IP) {
                    if(deviceInfo.WIFI_IP.isReal) {
                        wifiInfo = createDeviceConnectionObj(
                            deviceInfo.dt,
                            wifiCT,
                            deviceInfo.wifiIP
                        );
                        foundWiFi = true;
                        wifiInfo.insertionMethod = 'attribute';
                        wifiInfo.foundByAttribute = true;
                    }
                }
            }

            if(foundUSB) {connectionTypes.push(usbInfo);}
            if(foundEth) {connectionTypes.push(ethInfo);}
            if(foundWiFi) {connectionTypes.push(wifiInfo);}

            // console.log('device connection types', deviceInfo.ct, deviceInfo.WIFI_IP, deviceInfo.ETHERNET_IP);

            return connectionTypes;
        }
1232034
def interfaces(self):
        """"""

        self._ifaces = []
        wifi_ctrl = wifiutil.WifiUtil()

        for interface in wifi_ctrl.interfaces():
            iface = Interface(interface)
            self._ifaces.append(iface)
            self._logger.info("Get interface: %s", iface.name())

        if not self._ifaces:
            self._logger.error("Can't get wifi interface")

        return self._ifaces
328463
def _getdevicetuple(iobtdevice):
    
    addr = _macutil.formatdevaddr(iobtdevice.getAddressString())
    name = iobtdevice.getName()
    cod = iobtdevice.getClassOfDevice()
    return (addr, name, cod)
1262967
def interface(self, iface_name):
        
        if self.has_interface(iface_name):
            return self.interfaces[iface_name]
        else:
            raise RpcException(ERR_INVALID_PARAMS, "Unknown interface: '%s'", iface_name)