20
21
and storage repositories
27
if sys.platform == 'win32':
31
from oslo.config import cfg
25
33
from nova import block_device
26
from nova.openstack.common import cfg
27
34
from nova.openstack.common import log as logging
28
35
from nova.virt import driver
30
# Check needed for unit testing on Unix
31
if sys.platform == 'win32':
34
37
LOG = logging.getLogger(__name__)
36
CONF.import_opt('my_ip', 'nova.config')
39
CONF.import_opt('my_ip', 'nova.netconf')
39
42
class BaseVolumeUtils(object):
41
def get_iscsi_initiator(self, cim_conn):
42
"""Get iscsi initiator name for this machine"""
44
computer_system = cim_conn.Win32_ComputerSystem()[0]
45
if sys.platform == 'win32':
46
self._conn_wmi = wmi.WMI(moniker='//./root/wmi')
47
self._conn_cimv2 = wmi.WMI(moniker='//./root/cimv2')
50
def login_storage_target(self, target_lun, target_iqn, target_portal):
54
def logout_storage_target(self, target_iqn):
58
def execute_log_out(self, session_id):
61
def get_iscsi_initiator(self):
62
"""Get iscsi initiator name for this machine."""
64
computer_system = self._conn_cimv2.Win32_ComputerSystem()[0]
45
65
hostname = computer_system.name
47
r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery"
66
keypath = ("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\"
49
69
key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, keypath, 0,
50
_winreg.KEY_ALL_ACCESS)
70
_winreg.KEY_ALL_ACCESS)
51
71
temp = _winreg.QueryValueEx(key, 'DefaultInitiatorName')
52
72
initiator_name = str(temp[0])
53
73
_winreg.CloseKey(key)
55
75
LOG.info(_("The ISCSI initiator name can't be found. "
56
"Choosing the default one"))
57
computer_system = cim_conn.Win32_ComputerSystem()[0]
58
initiator_name = "iqn.1991-05.com.microsoft:" + \
76
"Choosing the default one"))
77
computer_system = self._conn_cimv2.Win32_ComputerSystem()[0]
78
initiator_name = "iqn.1991-05.com.microsoft:" + hostname.lower()
62
81
'initiator': initiator_name,
79
98
LOG.debug(_("block_device_list %s"), block_device_list)
80
99
return block_device.strip_dev(mount_device) in block_device_list
101
def _get_drive_number_from_disk_path(self, disk_path):
102
# TODO(pnavarro) replace with regex
103
start_device_id = disk_path.find('"', disk_path.find('DeviceID'))
104
end_device_id = disk_path.find('"', start_device_id + 1)
105
device_id = disk_path[start_device_id + 1:end_device_id]
106
return device_id[device_id.find("\\") + 2:]
108
def get_session_id_from_mounted_disk(self, physical_drive_path):
109
drive_number = self._get_drive_number_from_disk_path(
111
initiator_sessions = self._conn_wmi.query("SELECT * FROM "
112
"MSiSCSIInitiator_Session"
114
for initiator_session in initiator_sessions:
115
devices = initiator_session.Devices
116
for device in devices:
117
device_number = str(device.DeviceNumber)
118
if device_number == drive_number:
119
return initiator_session.SessionId
121
def get_device_number_for_target(self, target_iqn, target_lun):
122
initiator_session = self._conn_wmi.query("SELECT * FROM "
123
"MSiSCSIInitiator_Session"
124
"Class WHERE TargetName='%s'"
126
devices = initiator_session.Devices
127
for device in devices:
128
if device.ScsiLun == target_lun:
129
return device.DeviceNumber