Coverage for nova/virt/libvirt/volume/net.py: 90%
44 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 oslo_log import log as logging
15import nova.conf
16from nova.virt.libvirt.volume import volume as libvirt_volume
19CONF = nova.conf.CONF
20LOG = logging.getLogger(__name__)
23class LibvirtNetVolumeDriver(libvirt_volume.LibvirtBaseVolumeDriver):
24 """Driver to attach Network volumes to libvirt."""
26 def __init__(self, host):
27 super(LibvirtNetVolumeDriver,
28 self).__init__(host, is_block_dev=False)
29 self.connector = None
31 def _set_auth_config_rbd(self, conf, netdisk_properties):
32 # The rbd volume driver in cinder sets auth_enabled if the rbd_user is
33 # set in cinder. The rbd auth values from the cinder connection take
34 # precedence over any local nova config values in case the cinder ceph
35 # backend is configured differently than the nova rbd ephemeral storage
36 # configuration.
37 auth_enabled = netdisk_properties.get('auth_enabled')
38 if auth_enabled:
39 conf.auth_username = netdisk_properties['auth_username']
40 # We started preferring Cinder config for rbd auth values starting
41 # in Ocata, but if we have a guest connection from before that when
42 # secret_uuid wasn't configured in Cinder, we need to fallback to
43 # get it from local nova.conf.
44 if netdisk_properties['secret_uuid'] is not None:
45 conf.auth_secret_uuid = netdisk_properties['secret_uuid']
46 else:
47 # If we're using the rbd_secret_uuid from nova.conf we need to
48 # use the rbd_user from nova.conf as well.
49 LOG.debug('Falling back to Nova configuration for RBD auth '
50 'secret_uuid and username values.')
51 conf.auth_username = CONF.libvirt.rbd_user
52 conf.auth_secret_uuid = CONF.libvirt.rbd_secret_uuid
53 # secret_type is always hard-coded to 'ceph' in cinder
54 conf.auth_secret_type = netdisk_properties['secret_type']
55 elif CONF.libvirt.rbd_secret_uuid:
56 # Anyone relying on falling back to nova config is probably having
57 # this work accidentally and we'll remove that support in the
58 # future.
59 # NOTE(mriedem): We'll have to be extra careful about this in case
60 # the reason we got here is due to an old volume connection created
61 # before we started preferring the Cinder settings in Ocata.
62 LOG.warning('Falling back to Nova configuration values for '
63 'RBD authentication. Cinder should be configured '
64 'for auth with Ceph volumes. This fallback will '
65 'be dropped in a future release.')
66 # use the nova config values
67 conf.auth_username = CONF.libvirt.rbd_user
68 conf.auth_secret_uuid = CONF.libvirt.rbd_secret_uuid
69 # secret_type is always hard-coded to 'ceph' in cinder
70 conf.auth_secret_type = netdisk_properties['secret_type']
72 def _get_block_config(self, conf, connection_info):
73 conf.source_type = "block"
74 conf.source_path = connection_info['data']['device_path']
75 conf.driver_io = "native"
76 return conf
78 def _get_net_config(self, conf, connection_info):
79 netdisk_properties = connection_info['data']
80 conf.source_type = "network"
81 conf.source_protocol = connection_info['driver_volume_type']
82 conf.source_name = netdisk_properties.get('name')
83 conf.source_hosts = netdisk_properties.get('hosts', [])
84 conf.source_ports = netdisk_properties.get('ports', [])
85 if conf.source_protocol == 'rbd': 85 ↛ 87line 85 didn't jump to line 87 because the condition on line 85 was always true
86 self._set_auth_config_rbd(conf, netdisk_properties)
87 return conf
89 def get_config(self, connection_info, disk_info):
90 """Returns xml for libvirt."""
91 conf = super(
92 LibvirtNetVolumeDriver, self).get_config(
93 connection_info, disk_info)
94 return self._get_net_config(conf, connection_info)
96 def extend_volume(self, connection_info, instance, requested_size):
97 # There is nothing to do for network volumes. Cinder already
98 # extended the volume and there is no local block device which
99 # needs to be refreshed.
100 return requested_size