1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright 2012 Pedro Navarro Perez
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
19
Helper methods for operations related to the management of volumes,
20
and storage repositories for Windows 2012
24
from nova.openstack.common import cfg
25
from nova.openstack.common import log as logging
26
from nova.virt.hyperv import basevolumeutils
28
LOG = logging.getLogger(__name__)
32
class VolumeUtilsV2(basevolumeutils.BaseVolumeUtils):
34
def __init__(self, conn_storage, conn_wmi):
35
self._conn_storage = conn_storage
36
self._conn_wmi = conn_wmi
38
def login_storage_target(self, target_lun, target_iqn,
40
"""Add target portal, list targets and logins to the target"""
41
separator = target_portal.find(':')
42
target_address = target_portal[:separator]
43
target_port = target_portal[separator + 1:]
44
#Adding target portal to iscsi initiator. Sending targets
45
portal = self._conn_storage.__getattr__("MSFT_iSCSITargetPortal")
46
portal.New(TargetPortalAddress=target_address,
47
TargetPortalPortNumber=target_port)
48
#Connecting to the target
49
target = self._conn_storage.__getattr__("MSFT_iSCSITarget")
50
target.Connect(NodeAddress=target_iqn,
52
#Waiting the disk to be mounted. Research this
53
time.sleep(CONF.hyperv_wait_between_attach_retry)
55
def logout_storage_target(self, target_iqn):
56
"""Logs out storage target through its session id """
58
target = self._conn_storage.MSFT_iSCSITarget(
59
NodeAddress=target_iqn)[0]
60
if target.IsConnected:
61
session = self._conn_storage.MSFT_iSCSISession(
62
TargetNodeAddress=target_iqn)[0]
63
if session.IsPersistent:
67
def execute_log_out(self, session_id):
68
session = self._conn_wmi.MSiSCSIInitiator_SessionClass(
69
SessionId=session_id)[0]
70
self.logout_storage_target(session.TargetName)