~zulcss/nova/nova-precise-g3

« back to all changes in this revision

Viewing changes to nova/virt/hyperv/basevolumeutils.py

  • Committer: Chuck Short
  • Date: 2013-02-25 12:48:57 UTC
  • mfrom: (94.1.5 raring-proposed)
  • Revision ID: zulcss@ubuntu.com-20130225124857-iiz7w0zqhjo1sbs3
* New upstream release for the Ubuntu Cloud Archive. 
* New usptream release. 
* debian/patches/debian/patches/fix-ubuntu-tests.patch: Refreshed.
* debian/nova-baremetal.logrotate: Fix logfile path.
* debian/control, debian/nova-spiceproxy.{install, logrotate, upstart}:
  Add spice html5 proxy support.
* debian/nova-novncproxy.upstart: Start on runlevel [2345]
* debian/rules: Call testr directly since run_tests.sh -N gives weird return
  value when tests pass.
* debian/pyddist-overrides: Add websockify.
* debian/nova-common.postinst: Removed config file conversion, since
  the option is no longer available. (LP: #1110567)
* debian/control: Add python-pyasn1 as a dependency.
* debian/control: Add python-oslo-config as a dependency.
* debian/control: Suggest sysfsutils, sg3-utils, multipath-tools for fibre
  channel support.
* debian/control: Fix typo (websocikfy -> websockify).
* SECURITY UPDATE: fix lack of authentication on block device used for
  os-volume_boot
  - debian/patches/CVE-2013-0208.patch: adjust nova/compute/api.py to
    validate we can access the volumes
  - CVE-2013-0208

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
2
#
3
3
# Copyright 2012 Pedro Navarro Perez
 
4
# Copyright 2013 Cloudbase Solutions Srl
4
5
# All Rights Reserved.
5
6
#
6
7
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
20
21
and storage repositories
21
22
"""
22
23
 
 
24
import abc
23
25
import sys
24
26
 
 
27
if sys.platform == 'win32':
 
28
    import _winreg
 
29
    import wmi
 
30
 
 
31
from oslo.config import cfg
 
32
 
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
29
36
 
30
 
# Check needed for unit testing on Unix
31
 
if sys.platform == 'win32':
32
 
    import _winreg
33
 
 
34
37
LOG = logging.getLogger(__name__)
35
38
CONF = cfg.CONF
36
 
CONF.import_opt('my_ip', 'nova.config')
 
39
CONF.import_opt('my_ip', 'nova.netconf')
37
40
 
38
41
 
39
42
class BaseVolumeUtils(object):
40
43
 
41
 
    def get_iscsi_initiator(self, cim_conn):
42
 
        """Get iscsi initiator name for this machine"""
43
 
 
44
 
        computer_system = cim_conn.Win32_ComputerSystem()[0]
 
44
    def __init__(self):
 
45
        if sys.platform == 'win32':
 
46
            self._conn_wmi = wmi.WMI(moniker='//./root/wmi')
 
47
            self._conn_cimv2 = wmi.WMI(moniker='//./root/cimv2')
 
48
 
 
49
    @abc.abstractmethod
 
50
    def login_storage_target(self, target_lun, target_iqn, target_portal):
 
51
        pass
 
52
 
 
53
    @abc.abstractmethod
 
54
    def logout_storage_target(self, target_iqn):
 
55
        pass
 
56
 
 
57
    @abc.abstractmethod
 
58
    def execute_log_out(self, session_id):
 
59
        pass
 
60
 
 
61
    def get_iscsi_initiator(self):
 
62
        """Get iscsi initiator name for this machine."""
 
63
 
 
64
        computer_system = self._conn_cimv2.Win32_ComputerSystem()[0]
45
65
        hostname = computer_system.name
46
 
        keypath = \
47
 
           r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\iSCSI\Discovery"
 
66
        keypath = ("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\"
 
67
                   "iSCSI\\Discovery")
48
68
        try:
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)
54
74
        except Exception:
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:" + \
59
 
                hostname.lower()
 
76
                       "Choosing the default one"))
 
77
            computer_system = self._conn_cimv2.Win32_ComputerSystem()[0]
 
78
            initiator_name = "iqn.1991-05.com.microsoft:" + hostname.lower()
60
79
        return {
61
80
            'ip': CONF.my_ip,
62
81
            'initiator': initiator_name,
78
97
 
79
98
        LOG.debug(_("block_device_list %s"), block_device_list)
80
99
        return block_device.strip_dev(mount_device) in block_device_list
 
100
 
 
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:]
 
107
 
 
108
    def get_session_id_from_mounted_disk(self, physical_drive_path):
 
109
        drive_number = self._get_drive_number_from_disk_path(
 
110
            physical_drive_path)
 
111
        initiator_sessions = self._conn_wmi.query("SELECT * FROM "
 
112
                                                  "MSiSCSIInitiator_Session"
 
113
                                                  "Class")
 
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
 
120
 
 
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'"
 
125
                                                 % target_iqn)[0]
 
126
        devices = initiator_session.Devices
 
127
        for device in devices:
 
128
            if device.ScsiLun == target_lun:
 
129
                return device.DeviceNumber