def get_iscsi_initiator(self): """Returns the initiator node name.""" try: buff = (ctypes.c_wchar * (iscsi_struct.MAX_ISCSI_NAME_LEN + 1))() self._run_and_check_output(iscsidsc.GetIScsiInitiatorNodeNameW, ctypes.byref(buff)) return buff.value except exceptions.ISCSIInitiatorAPIException as ex: LOG.info(_LI("The ISCSI initiator node name can't be found. " "Choosing the default one. Exception: %s"), ex) return "%s:%s" % (self._MS_IQN_PREFIX, socket.getfqdn().lower())
def create_iscsi_target(self, target_name, fail_if_exists=False): """Creates ISCSI target.""" try: self._conn_wmi.WT_Host.NewHost(HostName=target_name) except wmi.x_wmi as wmi_exc: err_code = self._win32utils.get_com_err_code(wmi_exc.com_error) target_exists = err_code == self._ERR_FILE_EXISTS if not target_exists or fail_if_exists: err_msg = _('Failed to create iSCSI target: %s.') raise exceptions.ISCSITargetWMIException(err_msg % target_name, wmi_exc=wmi_exc) else: LOG.info(_LI('The iSCSI target %s already exists.'), target_name)
def create_iscsi_target(self, target_name, fail_if_exists=False): """Creates ISCSI target.""" try: self._conn_wmi.WT_Host.NewHost(HostName=target_name) except exceptions.x_wmi as wmi_exc: err_code = self._win32utils.get_com_err_code(wmi_exc.com_error) target_exists = err_code == self._ERR_FILE_EXISTS if not target_exists or fail_if_exists: err_msg = _('Failed to create iSCSI target: %s.') raise exceptions.ISCSITargetWMIException(err_msg % target_name, wmi_exc=wmi_exc) else: LOG.info(_LI('The iSCSI target %s already exists.'), target_name)
def get_iscsi_initiator(self): """Get iscsi initiator name for this machine.""" computer_system = self._conn_cimv2.Win32_ComputerSystem()[0] hostname = computer_system.name keypath = ("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\" "iSCSI\\Discovery") try: key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, keypath, 0, winreg.KEY_ALL_ACCESS) temp = winreg.QueryValueEx(key, 'DefaultInitiatorName') initiator_name = str(temp[0]) winreg.CloseKey(key) except Exception: LOG.info(_LI("The ISCSI initiator name can't be found. " "Choosing the default one")) initiator_name = "iqn.1991-05.com.microsoft:" + hostname.lower() if computer_system.PartofDomain: initiator_name += '.' + computer_system.Domain.lower() return initiator_name
def get_iscsi_initiator(self): """Get iscsi initiator name for this machine.""" computer_system = self._conn_cimv2.Win32_ComputerSystem()[0] hostname = computer_system.name keypath = ("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\" "iSCSI\\Discovery") try: key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, keypath, 0, winreg.KEY_ALL_ACCESS) temp = winreg.QueryValueEx(key, 'DefaultInitiatorName') initiator_name = str(temp[0]) winreg.CloseKey(key) except Exception: LOG.info( _LI("The ISCSI initiator name can't be found. " "Choosing the default one")) initiator_name = "iqn.1991-05.com.microsoft:" + hostname.lower() if computer_system.PartofDomain: initiator_name += '.' + computer_system.Domain.lower() return initiator_name