Files
nova/nova/virt/hyperv/volumeutils.py
T
Sean Dague 37bfdd3b38 fix N401 errors, stop ignoring all N4* errors
We had previously been ignoring all our custom N4xx hacking.py
errors. This fixes all the N401 errors "doc strings
should not start with a space" and reduces the ignore set down
to N402 only "single line docstrings should end with period".

It also fixes the N401 parser to catch only docstrings, and
not tripple quoted string blocks used later on in a function.

Clean up a few of the more crazy uses of """ in our code

Clean up additional funky comments to make indents a bit more
consistent, and pull in lines when possible.

Change-Id: I9040a1d2ca7efda83bd5e425b95d1408b5b63577
2013-01-07 21:39:58 -05:00

82 lines
3.1 KiB
Python

# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# Copyright 2012 Pedro Navarro Perez
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""
Helper methods for operations related to the management of volumes,
and storage repositories
"""
import time
from eventlet.green import subprocess
from nova.openstack.common import cfg
from nova.openstack.common import log as logging
from nova.virt.hyperv import basevolumeutils
from nova.virt.hyperv import vmutils
LOG = logging.getLogger(__name__)
CONF = cfg.CONF
class VolumeUtils(basevolumeutils.BaseVolumeUtils):
def __init__(self, conn_wmi):
self._conn_wmi = conn_wmi
def execute(self, *args, **kwargs):
_PIPE = subprocess.PIPE # pylint: disable=E1101
proc = subprocess.Popen(
[args],
stdin=_PIPE,
stdout=_PIPE,
stderr=_PIPE,
)
stdout_value, stderr_value = proc.communicate()
if stdout_value.find('The operation completed successfully') == -1:
raise vmutils.HyperVException(_('An error has occurred when '
'calling the iscsi initiator: %s') % stdout_value)
def login_storage_target(self, target_lun, target_iqn, target_portal):
"""Add target portal, list targets and logins to the target"""
separator = target_portal.find(':')
target_address = target_portal[:separator]
target_port = target_portal[separator + 1:]
#Adding target portal to iscsi initiator. Sending targets
self.execute('iscsicli.exe ' + 'AddTargetPortal ' +
target_address + ' ' + target_port +
' * * * * * * * * * * * * *')
#Listing targets
self.execute('iscsicli.exe ' + 'LisTargets')
#Sending login
self.execute('iscsicli.exe ' + 'qlogintarget ' + target_iqn)
#Waiting the disk to be mounted. Research this to avoid sleep
time.sleep(CONF.hyperv_wait_between_attach_retry)
def logout_storage_target(self, target_iqn):
"""Logs out storage target through its session id """
sessions = self._conn_wmi.query(
"SELECT * FROM MSiSCSIInitiator_SessionClass \
WHERE TargetName='" + target_iqn + "'")
for session in sessions:
self.execute_log_out(session.SessionId)
def execute_log_out(self, session_id):
"""Executes log out of the session described by its session ID """
self.execute('iscsicli.exe ' + 'logouttarget ' + session_id)