def _wwn_struct_from_hex_str(self, wwn_hex_str): try: wwn_struct = fc_struct.HBA_WWN() wwn_struct.wwn[:] = _utils.hex_str_to_byte_array(wwn_hex_str) except ValueError: err_msg = _("Invalid WWN hex string received: %s") % wwn_hex_str raise exceptions.FCException(err_msg) return wwn_struct
def _get_hba_handle(self, adapter_name=None, adapter_wwn_struct=None): if adapter_name: hba_handle = self._open_adapter_by_name(adapter_name) elif adapter_wwn_struct: hba_handle = self._open_adapter_by_wwn(adapter_wwn_struct) else: err_msg = _("Could not open HBA adapter. " "No HBA name or WWN was specified") raise exceptions.FCException(err_msg) try: yield hba_handle finally: self._close_adapter(hba_handle)
def _open_adapter(self, adapter_name=None, adapter_wwn=None): if adapter_name: func = hbaapi.HBA_OpenAdapter arg = ctypes.c_char_p(six.b(adapter_name)) elif adapter_wwn: func = hbaapi.HBA_OpenAdapterByWWN arg = fc_struct.HBA_WWN(*adapter_wwn) else: err_msg = _("Could not open HBA adapter. " "No HBA name or WWN was specified") raise exceptions.FCException(err_msg) handle = self._run_and_check_output(func, arg, ret_val_is_err_code=False, error_on_nonzero_ret_val=False, error_ret_vals=[0]) return handle