Coverage for nova/virt/libvirt/volume/fibrechannel.py: 78%
35 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-24 11:16 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-24 11:16 +0000
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
13from os_brick import initiator
14from os_brick.initiator import connector
15from oslo_log import log as logging
17import nova.conf
18from nova import utils
19from nova.virt.libvirt.volume import volume as libvirt_volume
21CONF = nova.conf.CONF
23LOG = logging.getLogger(__name__)
26class LibvirtFibreChannelVolumeDriver(libvirt_volume.LibvirtBaseVolumeDriver):
27 """Driver to attach Fibre Channel Network volumes to libvirt."""
29 def __init__(self, host):
30 super(LibvirtFibreChannelVolumeDriver,
31 self).__init__(host, is_block_dev=False)
33 # Call the factory here so we can support
34 # more than x86 architectures.
35 self.connector = connector.InitiatorConnector.factory(
36 initiator.FIBRE_CHANNEL, utils.get_root_helper(),
37 use_multipath=CONF.libvirt.volume_use_multipath,
38 device_scan_attempts=CONF.libvirt.num_volume_scan_tries,
39 enforce_multipath=CONF.libvirt.volume_enforce_multipath)
41 def get_config(self, connection_info, disk_info):
42 """Returns xml for libvirt."""
43 conf = super(LibvirtFibreChannelVolumeDriver,
44 self).get_config(connection_info, disk_info)
46 conf.source_type = "block"
47 conf.source_path = connection_info['data']['device_path']
48 conf.driver_io = "native"
49 return conf
51 def connect_volume(self, connection_info, instance):
52 """Attach the volume to instance_name."""
54 LOG.debug("Calling os-brick to attach FC Volume", instance=instance)
55 device_info = self.connector.connect_volume(connection_info['data'])
56 LOG.debug("Attached FC volume %s", device_info, instance=instance)
58 connection_info['data']['device_path'] = device_info['path']
59 if 'multipath_id' in device_info:
60 connection_info['data']['multipath_id'] = \
61 device_info['multipath_id']
63 def disconnect_volume(self, connection_info, instance, force=False):
64 """Detach the volume from instance_name."""
66 LOG.debug("calling os-brick to detach FC Volume", instance=instance)
67 # TODO(walter-boring) eliminated the need for preserving
68 # multipath_id. Use scsi_id instead of multipath -ll
69 # This will then eliminate the need to pass anything in
70 # the 2nd param of disconnect_volume and be consistent
71 # with the rest of the connectors.
72 self.connector.disconnect_volume(connection_info['data'],
73 connection_info['data'],
74 force=force)
75 LOG.debug("Disconnected FC Volume", instance=instance)
77 super(LibvirtFibreChannelVolumeDriver,
78 self).disconnect_volume(connection_info, instance, force=force)
80 def extend_volume(self, connection_info, instance, requested_size):
81 """Extend the volume."""
82 LOG.debug("calling os-brick to extend FC Volume", instance=instance)
83 new_size = self.connector.extend_volume(connection_info['data'])
84 LOG.debug("Extend FC Volume: new_size=%s",
85 new_size, instance=instance)
86 return new_size