r"""Re-attach an interface's kernel driver, which was previously
        detached using detach_kernel_driver().

        The interface parameter is the device interface number to attach the
        driver to.
166681
def attach_kernel_driver(self, interface):
        
        """
        self._ctx.managed_open()
        self._ctx.backend.attach_kernel_driver(
            self._ctx.handle,
            interface)
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)
656363
def detach_network_interface(self, network_interface_id, force=False):
        
        params = {'NetworkInterfaceId' : network_interface_id}
        if force:
            params['Force'] = 'true'
        return self.get_status('DetachNetworkInterface', params, verb='POST')
878498
def reload
      device = SimCtl.device(udid: udid)
      device.instance_variables.each do |ivar|
        instance_variable_set(ivar, device.instance_variable_get(ivar))
      end
    end
515573
def reset_kernel(self):
        """"""
        client = self.get_current_client()
        if client is not None:
            self.switch_to_plugin()
            client.reset_namespace()
696690
def _add_interface(self, interface_id, mgt=None, **kw):
        
        _kw = copy.deepcopy(kw) # Preserve original kw, especially lists
        mgt = mgt if mgt else {}
        
        if 'cvi_mode' in _kw:
            self.data.update(cvi_mode=_kw.pop('cvi_mode'))
        
        if 'macaddress' in _kw:
            self.data.update(
                macaddress=_kw.pop('macaddress'))
            if 'cvi_mode' not in self.data:
                self.data.update(cvi_mode='packetdispatch')
        
        if 'zone_ref' in _kw:
            zone_ref = _kw.pop('zone_ref')
            self.data.update(zone_ref=zone_helper(zone_ref) if zone_ref else None)
        
        if 'comment' in _kw:
            self.data.update(comment=_kw.pop('comment'))

        interfaces = _kw.pop('interfaces', [])
        for interface in interfaces:
            vlan_id = interface.pop('vlan_id', None)
            if vlan_id:
                _interface_id = '{}.{}'.format(interface_id, vlan_id)
            else:
                _interface_id = interface_id
    
            _interface = []
            if_mgt = {k: str(v) == str(_interface_id) for k, v in mgt.items()}
            
            if 'cluster_virtual' in interface and 'network_value' in interface:
                cluster_virtual = interface.pop('cluster_virtual')
                network_value = interface.pop('network_value')
                if cluster_virtual and network_value:
                    cvi = ClusterVirtualInterface.create(
                        _interface_id, cluster_virtual, network_value,
                        auth_request=True if if_mgt.get('primary_mgt') else False)
                      
                    _interface.append({cvi.typeof: cvi.data})
    
            for node in interface.pop('nodes', []):
                _node = if_mgt.copy()
                _node.update(outgoing=True if if_mgt.get('primary_mgt') else False)
                # Add node specific key/value pairs set on the node. This can
                # also be used to override management settings
                _node.update(node)
                ndi = NodeInterface.create(
                    interface_id=_interface_id, **_node)
                _interface.append({ndi.typeof: ndi.data})

            if vlan_id:
                vlan_interface = {
                    'interface_id': _interface_id,
                    'zone_ref': zone_helper(interface.pop('zone_ref', None)),
                    'comment': interface.pop('comment', None),
                    'interfaces': _interface}
                # Add remaining kwargs on vlan level to VLAN physical interface
                for name, value in interface.items():
                    vlan_interface[name] = value
                self.data.setdefault('vlanInterfaces', []).append(
                    vlan_interface)
            else:
                self.data.setdefault('interfaces', []).extend(
                    _interface)

        # Remaining kw go to base level interface
        for name, value in _kw.items():
            self.data[name] = value
885583
def claimInterface(self, interface):
        
        """
        if isinstance(interface, Interface):
            interface = interface.interfaceNumber

        util.claim_interface(self.dev, interface)
        self.__claimed_interface = interface
915962
def get_kernel_id(self):
        
        sessions_url = self.get_session_url()
        sessions_req = requests.get(sessions_url).content.decode()
        sessions = json.loads(sessions_req)

        if os.name == 'nt':
            path = self.path.replace('\\', '/')
        else:
            path = self.path

        for session in sessions:
            notebook_path = session.get('notebook', {}).get('path')
            if notebook_path is not None and notebook_path == path:
                kernel_id = session['kernel']['id']
                return kernel_id
462245
def event(self, interface_id, address, value_key, value):
        """"""
        LOG.debug("RPCFunctions.event: interface_id = %s, address = %s, value_key = %s, value = %s" % (
            interface_id, address, value_key.upper(), str(value)))
        self.devices_all[interface_id.split(
            '-')[-1]][address].event(interface_id, value_key.upper(), value)
        if self.eventcallback:
            self.eventcallback(interface_id=interface_id, address=address,
                               value_key=value_key.upper(), value=value)
        return True
81964
def set_driver_simulated(self):
        """"""
        self._device_dict["servermain.MULTIPLE_TYPES_DEVICE_DRIVER"] = "Simulator"
        if self._is_sixteen_bit:
            self._device_dict["servermain.DEVICE_MODEL"] = 0
        else:
            self._device_dict["servermain.DEVICE_MODEL"] = 1
        self._device_dict["servermain.DEVICE_ID_OCTAL"] = 1
371989
def _detach(self, fcp, assigner_id, target_wwpn, target_lun,
                multipath, os_version, mount_point):
        """"""
        LOG.info('Start to detach device from %s' % assigner_id)
        connections = self.fcp_mgr.decrease_fcp_usage(fcp, assigner_id)

        try:
            self._remove_disk(fcp, assigner_id, target_wwpn, target_lun,
                              multipath, os_version, mount_point)
            if not connections:
                self._undedicate_fcp(fcp, assigner_id)
        except (exception.SDKBaseException,
                exception.SDKSMTRequestFailed) as err:
            errmsg = 'rollback detach because error:' + err.format_message()
            LOG.error(errmsg)
            self.fcp_mgr.increase_fcp_usage(fcp, assigner_id)
            with zvmutils.ignore_errors():
                self._add_disk(fcp, assigner_id, target_wwpn, target_lun,
                               multipath, os_version, mount_point)
            raise exception.SDKBaseException(msg=errmsg)

        LOG.info('Detaching device to %s is done.' % assigner_id)
875941
def attach_hardware(self, ticket_id=None, hardware_id=None):
        
        return self.ticket.addAttachedHardware(hardware_id, id=ticket_id)
1281476
def _remove_redundancy_router_interfaces(self, context, router_id,
                                             old_port):
        
        ha_settings = self._get_ha_settings_by_router_id(context, router_id)
        if ha_settings is None or old_port is None:
            return
        e_context = context.elevated()
        rr_ids = self._get_redundancy_router_ids(e_context, router_id)
        port_info_list = self._core_plugin.get_ports(
            e_context, filters={'device_id': rr_ids,
                                'network_id': [old_port['network_id']]},
            fields=['device_id', 'fixed_ips', 'id'])
        subnet_id = old_port['fixed_ips'][0]['subnet_id']
        for port_info in port_info_list:
            if port_info['fixed_ips'][0]['subnet_id'] == subnet_id:
                interface_info = {'port_id': port_info['id']}
                self.remove_router_interface(e_context, port_info['device_id'],
                                             interface_info)
        self._delete_ha_group(e_context, old_port['id'])
933014
def cleanup_interfaces(self):
        
        debug("Cleaning up interfaces...")
        for gpio_id in self._gpio_kernel_interfaces_created:
            # Close the value-file and remove interrupt bindings
            self.del_interrupt_callback(gpio_id)

            # Remove the kernel GPIO interface
            debug("- unexporting GPIO %s" % gpio_id)
            with open(_SYS_GPIO_ROOT + "unexport", "w") as f:
                f.write("%s" % gpio_id)

        # Reset list of created interfaces
        self._gpio_kernel_interfaces_created = []
44020
def get_all_usb_devices(idVendor, idProduct):
        
        all_dev = list(usb.core.find(find_all = True, idVendor = idVendor, idProduct = idProduct))
        for dev in all_dev:
            try:
                dev.detach_kernel_driver(0)
            except usb.USBError:
                pass
        return all_dev
1057121
def driver(self):
        

        if not self._driver:
            raise AttributeError("`driver` is not bound on this agent implementation({}). "
                                 "Do you forget to call `super().on_bind_driver` when you override the method "
                                 "`on_bind_driver` in your sub class?"
                                 .format(repr(self)))
        return self._driver
1268595
def _open(self, skip=0):
        
        usb_device = self._get_usb_device(skip)

        if usb_device:
            usb_conf = usb_device.configurations[0]
            self._usb_int = usb_conf.interfaces[0][0]
        else:
            raise YubiKeyUSBHIDError('No USB YubiKey found')

        try:
            self._usb_handle = usb_device.open()
            self._usb_handle.detachKernelDriver(0)
        except Exception as error:
            if 'could not detach kernel driver from interface' in str(error):
                self._debug('The in-kernel-HID driver has already been detached\n')
            else:
                self._debug("detachKernelDriver not supported!\n")

        try:
            self._usb_handle.setConfiguration(1)
        except usb.USBError:
            self._debug("Unable to set configuration, ignoring...\n")
        self._usb_handle.claimInterface(self._usb_int)
        return True