def get_fc_hba_descriptors(vmhbaname, executor): exec_ = command.get_exec_fn(executor) vmkmgmt_keyval_cls = vmkmgmt_keyval.find(executor) vmkmgmt_keyval_impl = vmkmgmt_keyval_cls() cmd = vmkmgmt_keyval_impl.instance('%s/Emulex' % vmhbaname).key('adapter') key_descriptor = exec_(cmd) if key_descriptor: return _parse(key_descriptor)
def get_fc_hba_descriptors(vmhbaname, executor): exec_ = command.get_exec_fn(executor) vmkmgmt_keyval_cls = vmkmgmt_keyval.find(executor) vmkmgmt_keyval_impl = vmkmgmt_keyval_cls() instances = exec_(vmkmgmt_keyval_impl.dumpInstances) fn = comp(methodcaller('startswith', 'qlnativefc'), methodcaller('lower')) for instance in ifilter(fn, instances): key_descriptors = exec_(vmkmgmt_keyval_impl.instance(instance).list) for descriptor in key_descriptors: if vmhbaname in descriptor.value: return _parse(vmhbaname, descriptor)
def is_applicable(self, os_platform, executor=None, protocol_name=None, **kwargs): is_applicable_platform_fn = fc_hba_discoverer.Discoverer.is_applicable is_applicable_platform = is_applicable_platform_fn(self, os_platform) if is_applicable_platform: esxcli_impl = find_esxcli_impl(executor) if esxcli_impl: esxcli_impl = esxcli_impl() exec_ = command.get_exec_fn(executor) return (exec_(esxcli_impl.iscorrectsyntax('storage san fc list')) and exec_(esxcli_impl.iscorrectsyntax('software vib get -n driver')) and exec_(esxcli_impl.iscorrectsyntax('storage core adapter list')) )
def get_fc_hbas(self, shell): executor = command.cmdlet.executeCommand(shell) fcinfo_impl = find_fcinfo_impl(executor)() exec_ = command.get_exec_fn(executor) safe_exec_ = command.get_safe_exec_fn(executor) descriptors = exec_(fcinfo_impl.hba_port()) result = [] for fchba_descriptor in descriptors: try: name = fchba_descriptor.name nodewwn = wwn.parse_from_str(fchba_descriptor.node_wwn) portwwn = fchba_descriptor.port_wwn model = fchba_descriptor.model vendor = fchba_descriptor.vendor type_ = fchba_descriptor.type serialnum = fchba_descriptor.serial_number driver_version = fchba_descriptor.driver_version fw_version = fchba_descriptor.firmware_version port_speed = fchba_descriptor.port_speed fchba = fc_hba_model.FcHba(name, name, wwn=nodewwn, vendor=vendor, model=model, serial_number=serialnum, driver_version=driver_version, firmware_version=fw_version) ports = [] try: port_id = None port_wwn = wwn.parse_from_str(portwwn) speed = _parse_port_speed(port_speed) remote_port_descriptors = safe_exec_(fcinfo_impl.remote_port.p(portwwn)) target_fchbas = self._create_target_fchba_details(remote_port_descriptors) ports.append((fc_hba_model.FcPort(port_id, port_wwn, type_, None, speed), target_fchbas)) except (command.ExecuteException, TypeError, ValueError), ex: logger.debugException('Failed to create fcport data object') result.append((fchba, ports)) except (command.ExecuteException, TypeError, ValueError), ex: logger.debugException('Failed to create fchba data object')
def get_fc_hbas(self, shell): result = defaultdict(list) executor = command.cmdlet.executeCommand(shell) esxcli = find_esxcli_impl(executor)() esxcli = esxcli.formatter('csv') esxcli_exec = command.get_exec_fn(esxcli, executor) storage = EsxcliStorageNamespace(esxcli) software = EsxcliSoftwareNamespace(esxcli) scsi_path_by_adapter_identifier = fptools.groupby(methodcaller('get', 'AdapterIdentifier'), esxcli_exec(storage.core.path.list())) adapters = esxcli_exec(storage.core.adapter.list()) grouped_adapters = dict((adapter.get('HBAName'), adapter) for adapter in adapters) grouped = defaultdict(list) for descriptor in esxcli_exec(storage.san.fc.list()): grouped[(descriptor.get('Adapter'), descriptor.get('NodeName'))].append(descriptor) get_vendor = Sfn(self.get_vendor) get_fchba_descriptor = Sfn(self._get_fchba_descriptor) for key, descriptors in grouped.iteritems(): try: vmhba, nodewwn = key nodewwn = wwn.parse_from_str(nodewwn) name = vmhba id_ = vmhba adapter_descriptor = grouped_adapters.get(vmhba) driverversion = None vendor = get_vendor(vmhba, executor) model = None fwversion = None serialnum = None if adapter_descriptor: id_ = adapter_descriptor.get('UID') driver = adapter_descriptor.get('Driver') vib_descriptor = esxcli_exec(software.vib.get(vibname=driver)) driverversion = vib_descriptor.get('Version') fchabdescriptor = get_fchba_descriptor(driver, vmhba, executor) if fchabdescriptor: model = fchabdescriptor.model fwversion = fchabdescriptor.firmwareversion serialnum = fchabdescriptor.serialnumber driverversion = fchabdescriptor.driverversion fchba = fc_hba_model.FcHba(id_, name, wwn=nodewwn, vendor=vendor, model=model, serial_number=serialnum, driver_version=driverversion, firmware_version=fwversion) ports = [] for fcdescriptor in descriptors: try: portwwn = fcdescriptor.get('PortName') porttype = fcdescriptor.get('PortType') portwwn = wwn.parse_from_str(portwwn) portid = fcdescriptor.get('PortID') port_speed = _parse_port_speed(fcdescriptor.get('Speed')) portid = Sfn(int)(portid, 16) adapter_identifier = self._compose_adapter_identifier(nodewwn, portwwn) scsi_paths = scsi_path_by_adapter_identifier.get(adapter_identifier) target_fcdescriptors = self._create_target_fchba_details(scsi_paths) ports.append((fc_hba_model.FcPort(portid, portwwn, porttype, None, port_speed), target_fcdescriptors)) except (command.ExecuteException, TypeError, ValueError), ex: logger.debugException('Failed to create fcport data object') result[fchba].extend(ports) except (command.ExecuteException, TypeError, ValueError), ex: logger.debugException('Failed to create fchba data object')