attach/detach_volume() take instance as a parameter
Previously the methods take instance['name'] as a parameter. With this change, ComputeDriver can lookup informations about the instance from hypervisor (in bare-metal driver, it is a local DB) by any other attributes of the instance. blueprint general-bare-metal-provisioning-framework Change-Id: Ibd0567f34ed5053909ce1a408f9cbf87516ba597
This commit is contained in:
parent
7cd22aaca7
commit
e6cae13dd2
|
@ -2388,7 +2388,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
|||
|
||||
try:
|
||||
self.driver.attach_volume(connection_info,
|
||||
instance['name'],
|
||||
instance,
|
||||
mountpoint)
|
||||
except Exception: # pylint: disable=W0702
|
||||
with excutils.save_and_reraise_exception():
|
||||
|
@ -2435,7 +2435,7 @@ class ComputeManager(manager.SchedulerDependentManager):
|
|||
connection_info['serial'] = volume_id
|
||||
try:
|
||||
self.driver.detach_volume(connection_info,
|
||||
instance['name'],
|
||||
instance,
|
||||
mp)
|
||||
except Exception: # pylint: disable=W0702
|
||||
with excutils.save_and_reraise_exception():
|
||||
|
|
|
@ -508,7 +508,7 @@ class HyperVAPITestCase(basetestcase.BaseTestCase):
|
|||
self._volume_target_portal, self._volume_id)
|
||||
|
||||
self._conn.attach_volume(connection_info,
|
||||
self._instance_data["name"], '/dev/sdc')
|
||||
self._instance_data, '/dev/sdc')
|
||||
|
||||
def test_attach_volume(self):
|
||||
self._attach_volume()
|
||||
|
@ -527,7 +527,7 @@ class HyperVAPITestCase(basetestcase.BaseTestCase):
|
|||
self._volume_target_portal, self._volume_id)
|
||||
|
||||
self._conn.detach_volume(connection_info,
|
||||
self._instance_data["name"], '/dev/sdc')
|
||||
self._instance_data, '/dev/sdc')
|
||||
|
||||
(_, volumes_paths, _) = self._hypervutils.get_vm_disks(
|
||||
self._instance_data["name"])
|
||||
|
|
|
@ -1707,8 +1707,8 @@ class LibvirtConnTestCase(test.TestCase):
|
|||
self.assertRaises(exception.VolumeDriverNotFound,
|
||||
conn.attach_volume,
|
||||
{"driver_volume_type": "badtype"},
|
||||
"fake",
|
||||
"/dev/fake")
|
||||
{"name": "fake-instance"},
|
||||
"/dev/fake")
|
||||
|
||||
def test_multi_nic(self):
|
||||
instance_data = dict(self.test_instance)
|
||||
|
|
|
@ -379,10 +379,10 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
|
|||
def test_attach_detach_volume(self):
|
||||
instance_ref, network_info = self._get_running_instance()
|
||||
self.connection.attach_volume({'driver_volume_type': 'fake'},
|
||||
instance_ref['name'],
|
||||
instance_ref,
|
||||
'/mnt/nova/something')
|
||||
self.connection.detach_volume({'driver_volume_type': 'fake'},
|
||||
instance_ref['name'],
|
||||
instance_ref,
|
||||
'/mnt/nova/something')
|
||||
|
||||
@catch_notimplementederror
|
||||
|
@ -390,11 +390,11 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
|
|||
instance_ref, network_info = self._get_running_instance()
|
||||
self.connection.power_off(instance_ref)
|
||||
self.connection.attach_volume({'driver_volume_type': 'fake'},
|
||||
instance_ref['name'],
|
||||
instance_ref,
|
||||
'/mnt/nova/something')
|
||||
self.connection.power_on(instance_ref)
|
||||
self.connection.detach_volume({'driver_volume_type': 'fake'},
|
||||
instance_ref['name'],
|
||||
instance_ref,
|
||||
'/mnt/nova/something')
|
||||
|
||||
@catch_notimplementederror
|
||||
|
|
|
@ -271,7 +271,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBase):
|
|||
instance = db.instance_create(self.context, self.instance_values)
|
||||
vm = xenapi_fake.create_vm(instance['name'], 'Running')
|
||||
result = conn.attach_volume(self._make_connection_info(),
|
||||
instance['name'], '/dev/sdc')
|
||||
instance, '/dev/sdc')
|
||||
|
||||
# check that the VM has a VBD attached to it
|
||||
# Get XenAPI record for VBD
|
||||
|
@ -290,7 +290,7 @@ class XenAPIVolumeTestCase(stubs.XenAPITestBase):
|
|||
self.assertRaises(exception.VolumeDriverNotFound,
|
||||
conn.attach_volume,
|
||||
{'driver_volume_type': 'nonexist'},
|
||||
instance['name'],
|
||||
instance,
|
||||
'/dev/sdc')
|
||||
|
||||
|
||||
|
|
|
@ -308,14 +308,14 @@ class BareMetalDriver(driver.ComputeDriver):
|
|||
def get_volume_connector(self, instance):
|
||||
return self.volume_driver.get_volume_connector(instance)
|
||||
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
return self.volume_driver.attach_volume(connection_info,
|
||||
instance_name, mountpoint)
|
||||
instance, mountpoint)
|
||||
|
||||
@exception.wrap_exception()
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
return self.volume_driver.detach_volume(connection_info,
|
||||
instance_name, mountpoint)
|
||||
instance, mountpoint)
|
||||
|
||||
def get_info(self, instance):
|
||||
# NOTE(deva): compute/manager.py expects to get NotFound exception
|
||||
|
|
|
@ -50,22 +50,9 @@ CONF.import_opt('libvirt_volume_drivers', 'nova.virt.libvirt.driver')
|
|||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_baremetal_node_by_instance_name(virtapi, instance_name):
|
||||
def _get_baremetal_node_by_instance_uuid(instance_uuid):
|
||||
context = nova_context.get_admin_context()
|
||||
# TODO(deva): optimize this DB query.
|
||||
# I don't think it should be _get_all
|
||||
for node in bmdb.bm_node_get_all(context, service_host=CONF.host):
|
||||
if not node['instance_uuid']:
|
||||
continue
|
||||
try:
|
||||
inst = virtapi.instance_get_by_uuid(context, node['instance_uuid'])
|
||||
if inst['name'] == instance_name:
|
||||
return node
|
||||
except exception.InstanceNotFound:
|
||||
continue
|
||||
|
||||
# raise exception if we found no matching instance
|
||||
raise exception.InstanceNotFound(instance_name)
|
||||
return bmdb.bm_node_get_by_instance_uuid(context, instance_uuid)
|
||||
|
||||
|
||||
def _create_iscsi_export_tgtadm(path, tid, iqn):
|
||||
|
@ -200,10 +187,10 @@ class VolumeDriver(object):
|
|||
'host': CONF.host,
|
||||
}
|
||||
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
raise NotImplementedError()
|
||||
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
|
@ -227,22 +214,21 @@ class LibvirtVolumeDriver(VolumeDriver):
|
|||
method = getattr(driver, method_name)
|
||||
return method(connection_info, *args, **kwargs)
|
||||
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
node = _get_baremetal_node_by_instance_name(self.virtapi,
|
||||
instance_name)
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
node = _get_baremetal_node_by_instance_uuid(instance['uuid'])
|
||||
ctx = nova_context.get_admin_context()
|
||||
pxe_ip = bmdb.bm_pxe_ip_get_by_bm_node_id(ctx, node['id'])
|
||||
if not pxe_ip:
|
||||
if not CONF.baremetal.use_unsafe_iscsi:
|
||||
raise exception.NovaException(_(
|
||||
'No fixed PXE IP is associated to %s') % instance_name)
|
||||
'No fixed PXE IP is associated to %s') % instance['uuid'])
|
||||
|
||||
mount_device = mountpoint.rpartition("/")[2]
|
||||
self._volume_driver_method('connect_volume',
|
||||
connection_info,
|
||||
mount_device)
|
||||
device_path = connection_info['data']['device_path']
|
||||
iqn = _get_iqn(instance_name, mountpoint)
|
||||
iqn = _get_iqn(instance['name'], mountpoint)
|
||||
tid = _get_next_tid()
|
||||
_create_iscsi_export_tgtadm(device_path, tid, iqn)
|
||||
|
||||
|
@ -259,10 +245,10 @@ class LibvirtVolumeDriver(VolumeDriver):
|
|||
_allow_iscsi_tgtadm(tid, 'ALL')
|
||||
|
||||
@exception.wrap_exception()
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
mount_device = mountpoint.rpartition("/")[2]
|
||||
try:
|
||||
iqn = _get_iqn(instance_name, mountpoint)
|
||||
iqn = _get_iqn(instance['name'], mountpoint)
|
||||
tid = _find_tid(iqn)
|
||||
if tid is not None:
|
||||
_delete_iscsi_export_tgtadm(tid)
|
||||
|
|
|
@ -263,11 +263,11 @@ class ComputeDriver(object):
|
|||
# TODO(Vek): Need to pass context in for access to auth_token
|
||||
raise NotImplementedError()
|
||||
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Attach the disk to the instance at mountpoint using info"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Detach the disk attached to the instance"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
|
|
@ -198,17 +198,18 @@ class FakeDriver(driver.ComputeDriver):
|
|||
{'key': key,
|
||||
'inst': self.instances}, instance=instance)
|
||||
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Attach the disk to the instance at mountpoint using info"""
|
||||
instance_name = instance['name']
|
||||
if not instance_name in self._mounts:
|
||||
self._mounts[instance_name] = {}
|
||||
self._mounts[instance_name][mountpoint] = connection_info
|
||||
return True
|
||||
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Detach the disk attached to the instance"""
|
||||
try:
|
||||
del self._mounts[instance_name][mountpoint]
|
||||
del self._mounts[instance['name']][mountpoint]
|
||||
except KeyError:
|
||||
pass
|
||||
return True
|
||||
|
|
|
@ -104,16 +104,16 @@ class HyperVDriver(driver.ComputeDriver):
|
|||
def get_info(self, instance):
|
||||
return self._vmops.get_info(instance)
|
||||
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Attach volume storage to VM instance"""
|
||||
return self._volumeops.attach_volume(connection_info,
|
||||
instance_name,
|
||||
instance['name'],
|
||||
mountpoint)
|
||||
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Detach volume storage to VM instance"""
|
||||
return self._volumeops.detach_volume(connection_info,
|
||||
instance_name,
|
||||
instance['name'],
|
||||
mountpoint)
|
||||
|
||||
def get_volume_connector(self, instance):
|
||||
|
|
|
@ -651,7 +651,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
return method(connection_info, *args, **kwargs)
|
||||
|
||||
@exception.wrap_exception()
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
instance_name = instance['name']
|
||||
virt_dom = self._lookup_by_name(instance_name)
|
||||
mount_device = mountpoint.rpartition("/")[2]
|
||||
conf = self.volume_driver_method('connect_volume',
|
||||
|
@ -705,7 +706,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
return xml
|
||||
|
||||
@exception.wrap_exception()
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
instance_name = instance['name']
|
||||
mount_device = mountpoint.rpartition("/")[2]
|
||||
try:
|
||||
virt_dom = self._lookup_by_name(instance_name)
|
||||
|
|
|
@ -178,11 +178,11 @@ class VMWareESXDriver(driver.ComputeDriver):
|
|||
'host': None
|
||||
}
|
||||
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Attach volume storage to VM instance."""
|
||||
pass
|
||||
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Detach volume storage to VM instance."""
|
||||
pass
|
||||
|
||||
|
|
|
@ -355,16 +355,16 @@ class XenAPIDriver(driver.ComputeDriver):
|
|||
xs_url = urlparse.urlparse(CONF.xenapi_connection_url)
|
||||
return xs_url.netloc
|
||||
|
||||
def attach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def attach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Attach volume storage to VM instance"""
|
||||
return self._volumeops.attach_volume(connection_info,
|
||||
instance_name,
|
||||
instance['name'],
|
||||
mountpoint)
|
||||
|
||||
def detach_volume(self, connection_info, instance_name, mountpoint):
|
||||
def detach_volume(self, connection_info, instance, mountpoint):
|
||||
"""Detach volume storage to VM instance"""
|
||||
return self._volumeops.detach_volume(connection_info,
|
||||
instance_name,
|
||||
instance['name'],
|
||||
mountpoint)
|
||||
|
||||
def get_console_pool_info(self, console_type):
|
||||
|
|
Loading…
Reference in New Issue