b912556ae0
_disconnect_volume was being passed disk_dev, which was is name of the disk as presented to the gust. However, _disconnect_volume is only concerned with unmounting the volume from the host, so this isn't relevant. A couple of volume drivers were using it for logging. We remove these because it wasn't done consistently, is better done by the caller, and isn't required as the information is available from other log messages. In the very minor associated debug log cleanup we also remove logging of connection_info from one volume driver, which is potential security bug. We also do some associated cleanup in a few volume driver tests which were assuming that disconnect_volume was being passed disk_info rather than disk_dev, and that connection_info['data'] is related to disk_info, which it isn't. Change-Id: I61a0bee9e71e9a67f6a7c04a7bfd6e77fe818a77
72 lines
2.8 KiB
Python
72 lines
2.8 KiB
Python
# 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.
|
|
|
|
import re
|
|
|
|
import nova.conf
|
|
from nova.virt.libvirt import utils as libvirt_utils
|
|
from nova.virt.libvirt.volume import fs
|
|
from nova.virt.libvirt.volume import remotefs
|
|
|
|
CONF = nova.conf.CONF
|
|
|
|
USERNAME_REGEX = re.compile(r"(user(?:name)?)=(?:[^ ,]+\\)?([^ ,]+)")
|
|
|
|
|
|
class LibvirtSMBFSVolumeDriver(fs.LibvirtBaseFileSystemVolumeDriver):
|
|
"""Class implements libvirt part of volume driver for SMBFS."""
|
|
|
|
def _get_mount_point_base(self):
|
|
return CONF.libvirt.smbfs_mount_point_base
|
|
|
|
def get_config(self, connection_info, disk_info):
|
|
"""Returns xml for libvirt."""
|
|
conf = super(LibvirtSMBFSVolumeDriver,
|
|
self).get_config(connection_info, disk_info)
|
|
|
|
conf.source_type = 'file'
|
|
conf.driver_cache = 'writethrough'
|
|
conf.source_path = connection_info['data']['device_path']
|
|
conf.driver_format = connection_info['data'].get('format', 'raw')
|
|
return conf
|
|
|
|
def connect_volume(self, connection_info, instance):
|
|
"""Connect the volume."""
|
|
smbfs_share = connection_info['data']['export']
|
|
mount_path = self._get_mount_path(connection_info)
|
|
|
|
if not libvirt_utils.is_mounted(mount_path, smbfs_share):
|
|
mount_options = self._parse_mount_options(connection_info)
|
|
remotefs.mount_share(mount_path, smbfs_share,
|
|
export_type='cifs', options=mount_options)
|
|
|
|
device_path = self._get_device_path(connection_info)
|
|
connection_info['data']['device_path'] = device_path
|
|
|
|
def disconnect_volume(self, connection_info, instance):
|
|
"""Disconnect the volume."""
|
|
smbfs_share = connection_info['data']['export']
|
|
mount_path = self._get_mount_path(connection_info)
|
|
remotefs.unmount_share(mount_path, smbfs_share)
|
|
|
|
def _parse_mount_options(self, connection_info):
|
|
mount_options = " ".join(
|
|
[connection_info['data'].get('options') or '',
|
|
CONF.libvirt.smbfs_mount_options])
|
|
|
|
if not USERNAME_REGEX.findall(mount_options):
|
|
mount_options = mount_options + ' -o username=guest'
|
|
else:
|
|
# Remove the Domain Name from user name
|
|
mount_options = USERNAME_REGEX.sub(r'\1=\2', mount_options)
|
|
return mount_options.strip(", ").split(' ')
|