diff --git a/etc/nova/nova.conf.sample b/etc/nova/nova.conf.sample index 93ae85e24c..377bcd998b 100644 --- a/etc/nova/nova.conf.sample +++ b/etc/nova/nova.conf.sample @@ -2116,6 +2116,10 @@ # Base dir where Scality SOFS shall be mounted (string value) #scality_sofs_mount_point=$state_path/scality +# Protocols listed here will be accessed directly from QEMU. +# Currently supported protocols: [gluster] (list value) +#qemu_allowed_storage_drivers= + # # Options defined in nova.virt.powervm.driver diff --git a/nova/tests/virt/libvirt/test_libvirt_volume.py b/nova/tests/virt/libvirt/test_libvirt_volume.py index a84c41c01b..a6bc5116c4 100644 --- a/nova/tests/virt/libvirt/test_libvirt_volume.py +++ b/nova/tests/virt/libvirt/test_libvirt_volume.py @@ -471,6 +471,32 @@ class LibvirtVolumeTestCase(test.TestCase): export_string, export_mnt_base)] self.assertEqual(self.executes, expected_commands) + def test_libvirt_glusterfs_libgfapi(self): + self.flags(qemu_allowed_storage_drivers=['gluster']) + libvirt_driver = volume.LibvirtGlusterfsVolumeDriver(self.fake_conn) + export_string = '192.168.1.1:/volume-00001' + name = 'volume-00001' + + connection_info = {'data': {'export': export_string, 'name': name}} + + disk_info = { + "dev": "vde", + "type": "disk", + "bus": "virtio", + } + + conf = libvirt_driver.connect_volume(connection_info, disk_info) + tree = conf.format_dom() + self.assertEqual(tree.get('type'), 'network') + self.assertEqual(tree.find('./driver').get('type'), 'raw') + + source = tree.find('./source') + self.assertEqual(source.get('protocol'), 'gluster') + self.assertEqual(source.get('name'), 'volume-00001/volume-00001') + self.assertEqual(source.find('./host').get('name'), '192.168.1.1') + + libvirt_driver.disconnect_volume(connection_info, "vde") + def fibrechan_connection(self, volume, location, wwn): return { 'driver_volume_type': 'fibrechan', diff --git a/nova/virt/libvirt/volume.py b/nova/virt/libvirt/volume.py index 26ffaae759..03f73ff46a 100644 --- a/nova/virt/libvirt/volume.py +++ b/nova/virt/libvirt/volume.py @@ -73,6 +73,10 @@ volume_opts = [ cfg.StrOpt('scality_sofs_mount_point', default='$state_path/scality', help='Base dir where Scality SOFS shall be mounted'), + cfg.ListOpt('qemu_allowed_storage_drivers', + default=[], + help='Protocols listed here will be accessed directly ' + 'from QEMU. Currently supported protocols: [gluster]') ] CONF = cfg.CONF @@ -604,11 +608,23 @@ class LibvirtGlusterfsVolumeDriver(LibvirtBaseVolumeDriver): """Connect the volume. Returns xml for libvirt.""" conf = super(LibvirtGlusterfsVolumeDriver, self).connect_volume(connection_info, mount_device) - options = connection_info['data'].get('options') - path = self._ensure_mounted(connection_info['data']['export'], options) - path = os.path.join(path, connection_info['data']['name']) - conf.source_type = 'file' - conf.source_path = path + + data = connection_info['data'] + + if 'gluster' in CONF.qemu_allowed_storage_drivers: + vol_name = data['export'].split('/')[1] + source_host = data['export'].split('/')[0][:-1] + + conf.source_ports = [None] + conf.source_type = 'network' + conf.source_protocol = 'gluster' + conf.source_hosts = [source_host] + conf.source_name = '%s/%s' % (vol_name, data['name']) + else: + path = self._ensure_mounted(data['export'], data.get('options')) + path = os.path.join(path, data['name']) + conf.source_type = 'file' + conf.source_path = path return conf def _ensure_mounted(self, glusterfs_export, options=None):