Remove references to 'inst_type'
This is significantly shorter since we're mostly dealing with local variables. Change-Id: Ib5456a8b02fe69592a6cc59ee77ea32386ce17a5 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
parent
1bf45c4720
commit
0ac74f4e00
|
@ -680,14 +680,15 @@ class ServersController(wsgi.Controller):
|
|||
|
||||
flavor_id = self._flavor_id_from_req_data(body)
|
||||
try:
|
||||
inst_type = flavors.get_flavor_by_flavor_id(
|
||||
flavor_id, ctxt=context, read_deleted="no")
|
||||
flavor = flavors.get_flavor_by_flavor_id(
|
||||
flavor_id, ctxt=context, read_deleted="no")
|
||||
|
||||
supports_multiattach = common.supports_multiattach_volume(req)
|
||||
supports_port_resource_request = \
|
||||
common.supports_port_resource_request(req)
|
||||
(instances, resv_id) = self.compute_api.create(context,
|
||||
inst_type,
|
||||
instances, resv_id = self.compute_api.create(
|
||||
context,
|
||||
flavor,
|
||||
image_uuid,
|
||||
display_name=name,
|
||||
display_description=description,
|
||||
|
|
|
@ -916,7 +916,7 @@ class DisabledFlavorsWithRealDBTestV21(test.TestCase):
|
|||
|
||||
self.disabled_type = self._create_disabled_flavor()
|
||||
self.addCleanup(self.disabled_type.destroy)
|
||||
self.inst_types = objects.FlavorList.get_all(self.admin_context)
|
||||
self.flavors = objects.FlavorList.get_all(self.admin_context)
|
||||
self.controller = self.Controller()
|
||||
|
||||
def _create_disabled_flavor(self):
|
||||
|
@ -935,7 +935,7 @@ class DisabledFlavorsWithRealDBTestV21(test.TestCase):
|
|||
flavor_list = self.controller.index(self.req)['flavors']
|
||||
api_flavorids = set(f['id'] for f in flavor_list)
|
||||
|
||||
db_flavorids = set(i['flavorid'] for i in self.inst_types)
|
||||
db_flavorids = set(i['flavorid'] for i in self.flavors)
|
||||
disabled_flavorid = str(self.disabled_type['flavorid'])
|
||||
|
||||
self.assertIn(disabled_flavorid, db_flavorids)
|
||||
|
@ -948,7 +948,7 @@ class DisabledFlavorsWithRealDBTestV21(test.TestCase):
|
|||
flavor_list = self.controller.index(self.req)['flavors']
|
||||
api_flavorids = set(f['id'] for f in flavor_list)
|
||||
|
||||
db_flavorids = set(i['flavorid'] for i in self.inst_types)
|
||||
db_flavorids = set(i['flavorid'] for i in self.flavors)
|
||||
disabled_flavorid = str(self.disabled_type['flavorid'])
|
||||
|
||||
self.assertIn(disabled_flavorid, db_flavorids)
|
||||
|
|
|
@ -48,28 +48,30 @@ START = NOW - datetime.timedelta(hours=HOURS)
|
|||
STOP = NOW
|
||||
|
||||
|
||||
FAKE_INST_TYPE = {'id': 1,
|
||||
'vcpus': VCPUS,
|
||||
'root_gb': ROOT_GB,
|
||||
'ephemeral_gb': EPHEMERAL_GB,
|
||||
'memory_mb': MEMORY_MB,
|
||||
'name': 'fakeflavor',
|
||||
'flavorid': 'foo',
|
||||
'rxtx_factor': 1.0,
|
||||
'vcpu_weight': 1,
|
||||
'swap': 0,
|
||||
'created_at': None,
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'deleted': 0,
|
||||
'disabled': False,
|
||||
'is_public': True,
|
||||
'extra_specs': {'foo': 'bar'}}
|
||||
FAKE_FLAVOR = {
|
||||
'id': 1,
|
||||
'vcpus': VCPUS,
|
||||
'root_gb': ROOT_GB,
|
||||
'ephemeral_gb': EPHEMERAL_GB,
|
||||
'memory_mb': MEMORY_MB,
|
||||
'name': 'fakeflavor',
|
||||
'flavorid': 'foo',
|
||||
'rxtx_factor': 1.0,
|
||||
'vcpu_weight': 1,
|
||||
'swap': 0,
|
||||
'created_at': None,
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'deleted': 0,
|
||||
'disabled': False,
|
||||
'is_public': True,
|
||||
'extra_specs': {'foo': 'bar'},
|
||||
}
|
||||
|
||||
|
||||
def _fake_instance(start, end, instance_id, tenant_id,
|
||||
vm_state=vm_states.ACTIVE):
|
||||
flavor = objects.Flavor(**FAKE_INST_TYPE)
|
||||
flavor = objects.Flavor(**FAKE_FLAVOR)
|
||||
return objects.Instance(
|
||||
deleted=False,
|
||||
id=instance_id,
|
||||
|
@ -100,7 +102,7 @@ def _fake_instance_deleted_flavorless(context, start, end, instance_id,
|
|||
project_id=tenant_id,
|
||||
user_id='fakeuser',
|
||||
display_name='name',
|
||||
instance_type_id=FAKE_INST_TYPE['id'],
|
||||
instance_type_id=FAKE_FLAVOR['id'],
|
||||
launched_at=start,
|
||||
terminated_at=end,
|
||||
deleted_at=start,
|
||||
|
@ -610,7 +612,7 @@ class SimpleTenantUsageControllerTestV21(test.TestCase):
|
|||
self.inst_obj.deleted = 1
|
||||
flavor = self.controller._get_flavor(self.context, self.inst_obj, {})
|
||||
self.assertEqual(objects.Flavor, type(flavor))
|
||||
self.assertEqual(FAKE_INST_TYPE['id'], flavor.id)
|
||||
self.assertEqual(FAKE_FLAVOR['id'], flavor.id)
|
||||
|
||||
@mock.patch('nova.objects.Instance.get_flavor',
|
||||
side_effect=exception.NotFound())
|
||||
|
|
|
@ -456,8 +456,8 @@ def stub_instance(id=1, user_id=None, project_id=None, host=None,
|
|||
else:
|
||||
metadata = []
|
||||
|
||||
inst_type = flavors.get_flavor_by_flavor_id(int(flavor_id))
|
||||
sys_meta = flavors.save_flavor_info({}, inst_type)
|
||||
sys_meta = flavors.save_flavor_info(
|
||||
{}, flavors.get_flavor_by_flavor_id(int(flavor_id)))
|
||||
sys_meta.update(system_metadata or {})
|
||||
|
||||
if host is not None:
|
||||
|
|
|
@ -4907,7 +4907,7 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
def test_provision_instances_with_keypair(self, mock_im, mock_instance,
|
||||
mock_br, mock_rs):
|
||||
fake_keypair = objects.KeyPair(name='test')
|
||||
inst_type = self._create_flavor()
|
||||
flavor = self._create_flavor()
|
||||
|
||||
@mock.patch.object(self.compute_api, '_get_volumes_for_bdms')
|
||||
@mock.patch.object(self.compute_api,
|
||||
|
@ -4922,24 +4922,16 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
'_bdm_validate_set_size_and_instance')
|
||||
def do_test(mock_bdm_v, mock_sg, mock_cniq, mock_get_vols):
|
||||
mock_cniq.return_value = 1
|
||||
self.compute_api._provision_instances(self.context,
|
||||
inst_type,
|
||||
1, 1, mock.MagicMock(),
|
||||
{}, None,
|
||||
None, None, None, {}, None,
|
||||
fake_keypair,
|
||||
objects.TagList(), None,
|
||||
False)
|
||||
self.compute_api._provision_instances(
|
||||
self.context, flavor, 1, 1, mock.MagicMock(), {}, None, None,
|
||||
None, None, {}, None, fake_keypair, objects.TagList(), None,
|
||||
False)
|
||||
self.assertEqual(
|
||||
'test',
|
||||
mock_instance.return_value.keypairs.objects[0].name)
|
||||
self.compute_api._provision_instances(self.context,
|
||||
inst_type,
|
||||
1, 1, mock.MagicMock(),
|
||||
{}, None,
|
||||
None, None, None, {}, None,
|
||||
None, objects.TagList(),
|
||||
None, False)
|
||||
self.compute_api._provision_instances(
|
||||
self.context, flavor, 1, 1, mock.MagicMock(), {}, None, None,
|
||||
None, None, {}, None, None, objects.TagList(), None, False)
|
||||
self.assertEqual(
|
||||
0,
|
||||
len(mock_instance.return_value.keypairs.objects))
|
||||
|
@ -5295,12 +5287,10 @@ class _ComputeAPIUnitTestMixIn(object):
|
|||
def test(mock_objects, mock_secgroup, mock_cniq):
|
||||
ctxt = context.RequestContext('fake-user', 'fake-project')
|
||||
mock_cniq.return_value = 1
|
||||
inst_type = self._create_flavor()
|
||||
self.compute_api._provision_instances(ctxt, inst_type, None, None,
|
||||
mock.MagicMock(), None, None,
|
||||
[], None, None, None, None,
|
||||
None, objects.TagList(),
|
||||
None, False)
|
||||
flavor = self._create_flavor()
|
||||
self.compute_api._provision_instances(
|
||||
ctxt, flavor, None, None, mock.MagicMock(), None, None, [],
|
||||
None, None, None, None, None, objects.TagList(), None, False)
|
||||
secgroups = mock_secgroup.return_value
|
||||
mock_objects.RequestSpec.from_components.assert_called_once_with(
|
||||
mock.ANY, mock.ANY, mock.ANY, mock.ANY, mock.ANY, mock.ANY,
|
||||
|
|
|
@ -8484,44 +8484,44 @@ class ComputeAPITestCase(BaseTestCase):
|
|||
def test_create_with_too_little_ram(self):
|
||||
# Test an instance type with too little memory.
|
||||
|
||||
inst_type = self.default_flavor
|
||||
inst_type['memory_mb'] = 1
|
||||
flavor = self.default_flavor
|
||||
flavor['memory_mb'] = 1
|
||||
|
||||
self.fake_image['min_ram'] = 2
|
||||
self.stub_out('nova.tests.fixtures.GlanceFixture.show', self.fake_show)
|
||||
|
||||
self.assertRaises(exception.FlavorMemoryTooSmall,
|
||||
self.compute_api.create, self.context,
|
||||
inst_type, self.fake_image['id'])
|
||||
flavor, self.fake_image['id'])
|
||||
|
||||
# Now increase the inst_type memory and make sure all is fine.
|
||||
inst_type['memory_mb'] = 2
|
||||
(refs, resv_id) = self.compute_api.create(self.context,
|
||||
inst_type, self.fake_image['id'])
|
||||
# Now increase the flavor memory and make sure all is fine.
|
||||
flavor['memory_mb'] = 2
|
||||
refs, resv_id = self.compute_api.create(
|
||||
self.context, flavor, self.fake_image['id'])
|
||||
|
||||
def test_create_with_too_little_disk(self):
|
||||
# Test an instance type with too little disk space.
|
||||
|
||||
inst_type = self.default_flavor
|
||||
inst_type['root_gb'] = 1
|
||||
flavor = self.default_flavor
|
||||
flavor['root_gb'] = 1
|
||||
|
||||
self.fake_image['min_disk'] = 2
|
||||
self.stub_out('nova.tests.fixtures.GlanceFixture.show', self.fake_show)
|
||||
|
||||
self.assertRaises(exception.FlavorDiskSmallerThanMinDisk,
|
||||
self.compute_api.create, self.context,
|
||||
inst_type, self.fake_image['id'])
|
||||
flavor, self.fake_image['id'])
|
||||
|
||||
# Now increase the inst_type disk space and make sure all is fine.
|
||||
inst_type['root_gb'] = 2
|
||||
(refs, resv_id) = self.compute_api.create(self.context,
|
||||
inst_type, self.fake_image['id'])
|
||||
# Now increase the flavor disk space and make sure all is fine.
|
||||
flavor['root_gb'] = 2
|
||||
refs, resv_id = self.compute_api.create(
|
||||
self.context, flavor, self.fake_image['id'])
|
||||
|
||||
def test_create_with_too_large_image(self):
|
||||
# Test an instance type with too little disk space.
|
||||
|
||||
inst_type = self.default_flavor
|
||||
inst_type['root_gb'] = 1
|
||||
flavor = self.default_flavor
|
||||
flavor['root_gb'] = 1
|
||||
|
||||
self.fake_image['size'] = '1073741825'
|
||||
|
||||
|
@ -8529,39 +8529,39 @@ class ComputeAPITestCase(BaseTestCase):
|
|||
|
||||
self.assertRaises(exception.FlavorDiskSmallerThanImage,
|
||||
self.compute_api.create, self.context,
|
||||
inst_type, self.fake_image['id'])
|
||||
flavor, self.fake_image['id'])
|
||||
|
||||
# Reduce image to 1 GB limit and ensure it works
|
||||
self.fake_image['size'] = '1073741824'
|
||||
(refs, resv_id) = self.compute_api.create(self.context,
|
||||
inst_type, self.fake_image['id'])
|
||||
refs, resv_id = self.compute_api.create(
|
||||
self.context, flavor, self.fake_image['id'])
|
||||
|
||||
def test_create_just_enough_ram_and_disk(self):
|
||||
# Test an instance type with just enough ram and disk space.
|
||||
|
||||
inst_type = self.default_flavor
|
||||
inst_type['root_gb'] = 2
|
||||
inst_type['memory_mb'] = 2
|
||||
flavor = self.default_flavor
|
||||
flavor['root_gb'] = 2
|
||||
flavor['memory_mb'] = 2
|
||||
|
||||
self.fake_image['min_ram'] = 2
|
||||
self.fake_image['min_disk'] = 2
|
||||
self.fake_image['name'] = 'fake_name'
|
||||
self.stub_out('nova.tests.fixtures.GlanceFixture.show', self.fake_show)
|
||||
|
||||
(refs, resv_id) = self.compute_api.create(self.context,
|
||||
inst_type, self.fake_image['id'])
|
||||
refs, resv_id = self.compute_api.create(
|
||||
self.context, flavor, self.fake_image['id'])
|
||||
|
||||
def test_create_with_no_ram_and_disk_reqs(self):
|
||||
# Test an instance type with no min_ram or min_disk.
|
||||
|
||||
inst_type = self.default_flavor
|
||||
inst_type['root_gb'] = 1
|
||||
inst_type['memory_mb'] = 1
|
||||
flavor = self.default_flavor
|
||||
flavor['root_gb'] = 1
|
||||
flavor['memory_mb'] = 1
|
||||
|
||||
self.stub_out('nova.tests.fixtures.GlanceFixture.show', self.fake_show)
|
||||
|
||||
(refs, resv_id) = self.compute_api.create(self.context,
|
||||
inst_type, self.fake_image['id'])
|
||||
refs, resv_id = self.compute_api.create(
|
||||
self.context, flavor, self.fake_image['id'])
|
||||
|
||||
def test_create_with_deleted_image(self):
|
||||
# If we're given a deleted image by glance, we should not be able to
|
||||
|
@ -9746,24 +9746,22 @@ class ComputeAPITestCase(BaseTestCase):
|
|||
'destination_type': 'volume'}
|
||||
blank_bdm = {'source_type': 'blank', 'destination_type': 'volume'}
|
||||
|
||||
inst_type = {'ephemeral_gb': ephemeral_size, 'swap': swap_size}
|
||||
flavor = {'ephemeral_gb': ephemeral_size, 'swap': swap_size}
|
||||
self.assertEqual(
|
||||
self.compute_api._volume_size(inst_type, ephemeral_bdm),
|
||||
self.compute_api._volume_size(flavor, ephemeral_bdm),
|
||||
ephemeral_size)
|
||||
ephemeral_bdm['volume_size'] = 42
|
||||
self.assertEqual(
|
||||
self.compute_api._volume_size(inst_type, ephemeral_bdm), 42)
|
||||
self.compute_api._volume_size(flavor, ephemeral_bdm), 42)
|
||||
self.assertEqual(
|
||||
self.compute_api._volume_size(inst_type, swap_bdm),
|
||||
swap_size)
|
||||
self.compute_api._volume_size(flavor, swap_bdm), swap_size)
|
||||
swap_bdm['volume_size'] = 42
|
||||
self.assertEqual(
|
||||
self.compute_api._volume_size(inst_type, swap_bdm), 42)
|
||||
self.compute_api._volume_size(flavor, swap_bdm), 42)
|
||||
self.assertEqual(
|
||||
self.compute_api._volume_size(inst_type, volume_bdm),
|
||||
volume_size)
|
||||
self.compute_api._volume_size(flavor, volume_bdm), volume_size)
|
||||
self.assertIsNone(
|
||||
self.compute_api._volume_size(inst_type, blank_bdm))
|
||||
self.compute_api._volume_size(flavor, blank_bdm))
|
||||
|
||||
def test_reservation_id_one_instance(self):
|
||||
"""Verify building an instance has a reservation_id that
|
||||
|
@ -13083,18 +13081,18 @@ class DisabledInstanceTypesTestCase(BaseTestCase):
|
|||
def setUp(self):
|
||||
super(DisabledInstanceTypesTestCase, self).setUp()
|
||||
self.compute_api = compute.API()
|
||||
self.inst_type = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
self.flavor = objects.Flavor.get_by_name(self.context, 'm1.small')
|
||||
|
||||
def test_can_build_instance_from_visible_flavor(self):
|
||||
self.inst_type['disabled'] = False
|
||||
self.flavor['disabled'] = False
|
||||
# Assert that exception.FlavorNotFound is not raised
|
||||
self.compute_api.create(self.context, self.inst_type,
|
||||
image_href=uuids.image_instance)
|
||||
self.compute_api.create(
|
||||
self.context, self.flavor, image_href=uuids.image_instance)
|
||||
|
||||
def test_cannot_build_instance_from_disabled_flavor(self):
|
||||
self.inst_type['disabled'] = True
|
||||
self.flavor['disabled'] = True
|
||||
self.assertRaises(exception.FlavorNotFound,
|
||||
self.compute_api.create, self.context, self.inst_type, None)
|
||||
self.compute_api.create, self.context, self.flavor, None)
|
||||
|
||||
@mock.patch('nova.compute.api.API.get_instance_host_status',
|
||||
new=mock.Mock(return_value=obj_fields.HostStatus.UP))
|
||||
|
@ -13300,11 +13298,12 @@ class ComputeInactiveImageTestCase(BaseTestCase):
|
|||
|
||||
def test_create_instance_with_deleted_image(self):
|
||||
# Make sure we can't start an instance with a deleted image.
|
||||
inst_type = objects.Flavor.get_by_name(context.get_admin_context(),
|
||||
'm1.tiny')
|
||||
self.assertRaises(exception.ImageNotActive,
|
||||
self.compute_api.create,
|
||||
self.context, inst_type, uuids.image_instance)
|
||||
flavor = objects.Flavor.get_by_name(
|
||||
context.get_admin_context(), 'm1.tiny')
|
||||
self.assertRaises(
|
||||
exception.ImageNotActive,
|
||||
self.compute_api.create,
|
||||
self.context, flavor, uuids.image_instance)
|
||||
|
||||
|
||||
class EvacuateHostTestCase(BaseTestCase):
|
||||
|
|
|
@ -118,9 +118,9 @@ def stub_out_db_instance_api(test, injected=True):
|
|||
|
||||
@classmethod
|
||||
def fake_flavor_get(cls, context, id):
|
||||
for inst_type in FLAVORS.values():
|
||||
if str(inst_type['id']) == str(id):
|
||||
return inst_type
|
||||
for flavor in FLAVORS.values():
|
||||
if str(flavor['id']) == str(id):
|
||||
return flavor
|
||||
return None
|
||||
|
||||
funcs = {
|
||||
|
|
|
@ -123,9 +123,8 @@ class FlavorFilteringTest(test.TestCase):
|
|||
self.context = context.get_admin_context()
|
||||
|
||||
def assertFilterResults(self, filters, expected):
|
||||
inst_types = objects.FlavorList.get_all(
|
||||
self.context, filters=filters)
|
||||
inst_names = [i.name for i in inst_types]
|
||||
flavors = objects.FlavorList.get_all(self.context, filters=filters)
|
||||
inst_names = [i.name for i in flavors]
|
||||
self.assertEqual(inst_names, expected)
|
||||
|
||||
def test_no_filters(self):
|
||||
|
|
|
@ -174,7 +174,7 @@ def set_vif_mtu_config(conf, mtu):
|
|||
conf.mtu = mtu
|
||||
|
||||
|
||||
def set_vif_bandwidth_config(conf, inst_type):
|
||||
def set_vif_bandwidth_config(conf, flavor):
|
||||
"""Config vif inbound/outbound bandwidth limit. parameters are
|
||||
set in instance_type_extra_specs table, key is in the format
|
||||
quota:vif_inbound_average.
|
||||
|
@ -183,7 +183,7 @@ def set_vif_bandwidth_config(conf, inst_type):
|
|||
bandwidth_items = ['vif_inbound_average', 'vif_inbound_peak',
|
||||
'vif_inbound_burst', 'vif_outbound_average', 'vif_outbound_peak',
|
||||
'vif_outbound_burst']
|
||||
for key, value in inst_type.get('extra_specs', {}).items():
|
||||
for key, value in flavor.get('extra_specs', {}).items():
|
||||
scope = key.split(':')
|
||||
if len(scope) > 1 and scope[0] == 'quota':
|
||||
if scope[1] in bandwidth_items:
|
||||
|
|
|
@ -4186,7 +4186,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
|
||||
LOG.info('Creating image', instance=instance)
|
||||
|
||||
inst_type = instance.get_flavor()
|
||||
flavor = instance.get_flavor()
|
||||
swap_mb = 0
|
||||
if 'disk.swap' in disk_mapping:
|
||||
mapping = disk_mapping['disk.swap']
|
||||
|
@ -4202,15 +4202,15 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
# developed. Also at that stage we probably may get rid of
|
||||
# the direct usage of flavor swap size here,
|
||||
# leaving the work with bdm only.
|
||||
swap_mb = inst_type['swap']
|
||||
swap_mb = flavor['swap']
|
||||
else:
|
||||
swap = driver.block_device_info_get_swap(block_device_info)
|
||||
if driver.swap_is_usable(swap):
|
||||
swap_mb = swap['swap_size']
|
||||
elif (inst_type['swap'] > 0 and
|
||||
elif (flavor['swap'] > 0 and
|
||||
not block_device.volume_in_mapping(
|
||||
mapping['dev'], block_device_info)):
|
||||
swap_mb = inst_type['swap']
|
||||
swap_mb = flavor['swap']
|
||||
|
||||
if swap_mb > 0:
|
||||
if (CONF.libvirt.virt_type == "parallels" and
|
||||
|
@ -4830,8 +4830,10 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
|
||||
return cpu
|
||||
|
||||
def _get_guest_disk_config(self, instance, name, disk_mapping, inst_type,
|
||||
image_type=None, boot_order=None):
|
||||
def _get_guest_disk_config(
|
||||
self, instance, name, disk_mapping, flavor, image_type=None,
|
||||
boot_order=None,
|
||||
):
|
||||
disk_unit = None
|
||||
disk = self.image_backend.by_name(instance, name, image_type)
|
||||
if (name == 'disk.config' and image_type == 'rbd' and
|
||||
|
@ -4851,20 +4853,19 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
if 'unit' in disk_mapping and disk_info['bus'] == 'scsi':
|
||||
disk_unit = disk_mapping['unit']
|
||||
disk_mapping['unit'] += 1 # Increments for the next disk added
|
||||
conf = disk.libvirt_info(disk_info, self.disk_cachemode,
|
||||
inst_type['extra_specs'],
|
||||
disk_unit=disk_unit,
|
||||
boot_order=boot_order)
|
||||
conf = disk.libvirt_info(
|
||||
disk_info, self.disk_cachemode, flavor['extra_specs'],
|
||||
disk_unit=disk_unit, boot_order=boot_order)
|
||||
return conf
|
||||
|
||||
def _get_guest_fs_config(self, instance, name, image_type=None):
|
||||
disk = self.image_backend.by_name(instance, name, image_type)
|
||||
return disk.libvirt_fs_info("/", "ploop")
|
||||
|
||||
def _get_guest_storage_config(self, context, instance, image_meta,
|
||||
disk_info,
|
||||
rescue, block_device_info,
|
||||
inst_type, os_type):
|
||||
def _get_guest_storage_config(
|
||||
self, context, instance, image_meta, disk_info, rescue,
|
||||
block_device_info, flavor, os_type,
|
||||
):
|
||||
devices = []
|
||||
disk_mapping = disk_info['mapping']
|
||||
|
||||
|
@ -4900,7 +4901,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
diskeph = self._get_guest_disk_config(
|
||||
instance,
|
||||
blockinfo.get_eph_disk(idx),
|
||||
disk_mapping, inst_type)
|
||||
disk_mapping, flavor)
|
||||
eph_devices.append(diskeph)
|
||||
return eph_devices
|
||||
|
||||
|
@ -4927,30 +4928,22 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
else:
|
||||
|
||||
if rescue and disk_mapping['disk.rescue'] == disk_mapping['root']:
|
||||
diskrescue = self._get_guest_disk_config(instance,
|
||||
'disk.rescue',
|
||||
disk_mapping,
|
||||
inst_type)
|
||||
diskrescue = self._get_guest_disk_config(
|
||||
instance, 'disk.rescue', disk_mapping, flavor)
|
||||
devices.append(diskrescue)
|
||||
|
||||
diskos = self._get_guest_disk_config(instance,
|
||||
'disk',
|
||||
disk_mapping,
|
||||
inst_type)
|
||||
diskos = self._get_guest_disk_config(
|
||||
instance, 'disk', disk_mapping, flavor)
|
||||
devices.append(diskos)
|
||||
else:
|
||||
if 'disk' in disk_mapping:
|
||||
diskos = self._get_guest_disk_config(instance,
|
||||
'disk',
|
||||
disk_mapping,
|
||||
inst_type)
|
||||
diskos = self._get_guest_disk_config(
|
||||
instance, 'disk', disk_mapping, flavor)
|
||||
devices.append(diskos)
|
||||
|
||||
if 'disk.local' in disk_mapping:
|
||||
disklocal = self._get_guest_disk_config(instance,
|
||||
'disk.local',
|
||||
disk_mapping,
|
||||
inst_type)
|
||||
disklocal = self._get_guest_disk_config(
|
||||
instance, 'disk.local', disk_mapping, flavor)
|
||||
devices.append(disklocal)
|
||||
instance.default_ephemeral_device = (
|
||||
block_device.prepend_dev(disklocal.target_dev))
|
||||
|
@ -4958,10 +4951,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
devices = devices + _get_ephemeral_devices()
|
||||
|
||||
if 'disk.swap' in disk_mapping:
|
||||
diskswap = self._get_guest_disk_config(instance,
|
||||
'disk.swap',
|
||||
disk_mapping,
|
||||
inst_type)
|
||||
diskswap = self._get_guest_disk_config(
|
||||
instance, 'disk.swap', disk_mapping, flavor)
|
||||
devices.append(diskswap)
|
||||
instance.default_swap_device = (
|
||||
block_device.prepend_dev(diskswap.target_dev))
|
||||
|
@ -4972,7 +4963,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
|
||||
if config_name in disk_mapping:
|
||||
diskconfig = self._get_guest_disk_config(
|
||||
instance, config_name, disk_mapping, inst_type,
|
||||
instance, config_name, disk_mapping, flavor,
|
||||
self._get_disk_config_image_type())
|
||||
devices.append(diskconfig)
|
||||
|
||||
|
@ -5003,9 +4994,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
devices.append(scsi_controller)
|
||||
|
||||
if rescue and disk_mapping['disk.rescue'] != disk_mapping['root']:
|
||||
diskrescue = self._get_guest_disk_config(instance, 'disk.rescue',
|
||||
disk_mapping, inst_type,
|
||||
boot_order='1')
|
||||
diskrescue = self._get_guest_disk_config(
|
||||
instance, 'disk.rescue', disk_mapping, flavor, boot_order='1')
|
||||
devices.append(diskrescue)
|
||||
|
||||
return devices
|
||||
|
@ -9242,7 +9232,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
self.vif_driver.get_config,
|
||||
instance=instance,
|
||||
image_meta=instance.image_meta,
|
||||
inst_type=instance.flavor,
|
||||
flavor=instance.flavor,
|
||||
virt_type=CONF.libvirt.virt_type,
|
||||
)
|
||||
self._detach_direct_passthrough_vifs(context,
|
||||
|
@ -10050,8 +10040,8 @@ class LibvirtDriver(driver.ComputeDriver):
|
|||
size=info['virt_disk_size'],
|
||||
ephemeral_size=info['virt_disk_size'] / units.Gi)
|
||||
elif cache_name.startswith('swap'):
|
||||
inst_type = instance.get_flavor()
|
||||
swap_mb = inst_type.swap
|
||||
flavor = instance.get_flavor()
|
||||
swap_mb = flavor.swap
|
||||
disk.cache(fetch_func=self._create_swap,
|
||||
filename="swap_%s" % swap_mb,
|
||||
size=swap_mb * units.Mi,
|
||||
|
|
|
@ -177,8 +177,9 @@ class LibvirtGenericVIFDriver(object):
|
|||
|
||||
return model
|
||||
|
||||
def get_base_config(self, instance, mac, image_meta,
|
||||
inst_type, virt_type, vnic_type):
|
||||
def get_base_config(
|
||||
self, instance, mac, image_meta, flavor, virt_type, vnic_type,
|
||||
):
|
||||
# TODO(sahid): We should rewrite it. This method handles too
|
||||
# many unrelated things. We probably need to have a specific
|
||||
# virtio, vhost, vhostuser functions.
|
||||
|
@ -218,8 +219,8 @@ class LibvirtGenericVIFDriver(object):
|
|||
driver = 'qemu'
|
||||
|
||||
if virt_type in ('kvm', 'parallels'):
|
||||
vhost_drv, vhost_queues = self._get_virtio_mq_settings(image_meta,
|
||||
inst_type)
|
||||
vhost_drv, vhost_queues = self._get_virtio_mq_settings(
|
||||
image_meta, flavor)
|
||||
# TODO(sahid): It seems that we return driver 'vhost' even
|
||||
# for vhostuser interface where for vhostuser interface
|
||||
# the driver should be 'vhost-user'. That currently does
|
||||
|
@ -311,10 +312,10 @@ class LibvirtGenericVIFDriver(object):
|
|||
return (("qvb%s" % iface_id)[:network_model.NIC_NAME_LEN],
|
||||
("qvo%s" % iface_id)[:network_model.NIC_NAME_LEN])
|
||||
|
||||
def get_config_802qbg(self, instance, vif, image_meta,
|
||||
inst_type, virt_type):
|
||||
conf = self.get_base_config(instance, vif['address'], image_meta,
|
||||
inst_type, virt_type, vif['vnic_type'])
|
||||
def get_config_802qbg(self, instance, vif, image_meta, flavor, virt_type):
|
||||
conf = self.get_base_config(
|
||||
instance, vif['address'], image_meta, flavor, virt_type,
|
||||
vif['vnic_type'])
|
||||
|
||||
params = vif["qbg_params"]
|
||||
designer.set_vif_host_backend_802qbg_config(
|
||||
|
@ -324,14 +325,14 @@ class LibvirtGenericVIFDriver(object):
|
|||
params['typeidversion'],
|
||||
params['instanceid'])
|
||||
|
||||
designer.set_vif_bandwidth_config(conf, inst_type)
|
||||
designer.set_vif_bandwidth_config(conf, flavor)
|
||||
|
||||
return conf
|
||||
|
||||
def get_config_802qbh(self, instance, vif, image_meta,
|
||||
inst_type, virt_type):
|
||||
conf = self.get_base_config(instance, vif['address'], image_meta,
|
||||
inst_type, virt_type, vif['vnic_type'])
|
||||
def get_config_802qbh(self, instance, vif, image_meta, flavor, virt_type):
|
||||
conf = self.get_base_config(
|
||||
instance, vif['address'], image_meta, flavor, virt_type,
|
||||
vif['vnic_type'])
|
||||
|
||||
profile = vif["profile"]
|
||||
vif_details = vif["details"]
|
||||
|
@ -343,14 +344,14 @@ class LibvirtGenericVIFDriver(object):
|
|||
conf, net_type, profile['pci_slot'],
|
||||
vif_details[network_model.VIF_DETAILS_PROFILEID])
|
||||
|
||||
designer.set_vif_bandwidth_config(conf, inst_type)
|
||||
designer.set_vif_bandwidth_config(conf, flavor)
|
||||
|
||||
return conf
|
||||
|
||||
def get_config_hw_veb(self, instance, vif, image_meta,
|
||||
inst_type, virt_type):
|
||||
conf = self.get_base_config(instance, vif['address'], image_meta,
|
||||
inst_type, virt_type, vif['vnic_type'])
|
||||
def get_config_hw_veb(self, instance, vif, image_meta, flavor, virt_type):
|
||||
conf = self.get_base_config(
|
||||
instance, vif['address'], image_meta, flavor, virt_type,
|
||||
vif['vnic_type'])
|
||||
|
||||
profile = vif["profile"]
|
||||
vif_details = vif["details"]
|
||||
|
@ -362,18 +363,19 @@ class LibvirtGenericVIFDriver(object):
|
|||
conf, net_type, profile['pci_slot'],
|
||||
vif_details[network_model.VIF_DETAILS_VLAN])
|
||||
|
||||
designer.set_vif_bandwidth_config(conf, inst_type)
|
||||
designer.set_vif_bandwidth_config(conf, flavor)
|
||||
|
||||
return conf
|
||||
|
||||
def get_config_hostdev_physical(self, instance, vif, image_meta,
|
||||
inst_type, virt_type):
|
||||
def get_config_hostdev_physical(
|
||||
self, instance, vif, image_meta, flavor, virt_type,
|
||||
):
|
||||
return self.get_base_hostdev_pci_config(vif)
|
||||
|
||||
def get_config_macvtap(self, instance, vif, image_meta,
|
||||
inst_type, virt_type):
|
||||
conf = self.get_base_config(instance, vif['address'], image_meta,
|
||||
inst_type, virt_type, vif['vnic_type'])
|
||||
def get_config_macvtap(self, instance, vif, image_meta, flavor, virt_type):
|
||||
conf = self.get_base_config(
|
||||
instance, vif['address'], image_meta, flavor, virt_type,
|
||||
vif['vnic_type'])
|
||||
|
||||
vif_details = vif['details']
|
||||
macvtap_src = vif_details.get(network_model.VIF_DETAILS_MACVTAP_SOURCE)
|
||||
|
@ -397,35 +399,36 @@ class LibvirtGenericVIFDriver(object):
|
|||
designer.set_vif_host_backend_direct_config(
|
||||
conf, macvtap_src, macvtap_mode)
|
||||
|
||||
designer.set_vif_bandwidth_config(conf, inst_type)
|
||||
designer.set_vif_bandwidth_config(conf, flavor)
|
||||
|
||||
return conf
|
||||
|
||||
def get_config_iovisor(self, instance, vif, image_meta,
|
||||
inst_type, virt_type):
|
||||
conf = self.get_base_config(instance, vif['address'], image_meta,
|
||||
inst_type, virt_type, vif['vnic_type'])
|
||||
def get_config_iovisor(self, instance, vif, image_meta, flavor, virt_type):
|
||||
conf = self.get_base_config(
|
||||
instance, vif['address'], image_meta, flavor, virt_type,
|
||||
vif['vnic_type'])
|
||||
|
||||
dev = self.get_vif_devname(vif)
|
||||
designer.set_vif_host_backend_ethernet_config(conf, dev)
|
||||
|
||||
designer.set_vif_bandwidth_config(conf, inst_type)
|
||||
designer.set_vif_bandwidth_config(conf, flavor)
|
||||
|
||||
return conf
|
||||
|
||||
def get_config_midonet(self, instance, vif, image_meta,
|
||||
inst_type, virt_type):
|
||||
conf = self.get_base_config(instance, vif['address'], image_meta,
|
||||
inst_type, virt_type, vif['vnic_type'])
|
||||
def get_config_midonet(self, instance, vif, image_meta, flavor, virt_type):
|
||||
conf = self.get_base_config(
|
||||
instance, vif['address'], image_meta, flavor, virt_type,
|
||||
vif['vnic_type'])
|
||||
|
||||
dev = self.get_vif_devname(vif)
|
||||
designer.set_vif_host_backend_ethernet_config(conf, dev)
|
||||
|
||||
return conf
|
||||
|
||||
def get_config_tap(self, instance, vif, image_meta, inst_type, virt_type):
|
||||
conf = self.get_base_config(instance, vif['address'], image_meta,
|
||||
inst_type, virt_type, vif['vnic_type'])
|
||||
def get_config_tap(self, instance, vif, image_meta, flavor, virt_type):
|
||||
conf = self.get_base_config(
|
||||
instance, vif['address'], image_meta, flavor, virt_type,
|
||||
vif['vnic_type'])
|
||||
|
||||
dev = self.get_vif_devname(vif)
|
||||
designer.set_vif_host_backend_ethernet_config(conf, dev)
|
||||
|
@ -436,8 +439,9 @@ class LibvirtGenericVIFDriver(object):
|
|||
|
||||
return conf
|
||||
|
||||
def get_config_ib_hostdev(self, instance, vif, image_meta,
|
||||
inst_type, virt_type):
|
||||
def get_config_ib_hostdev(
|
||||
self, instance, vif, image_meta, flavor, virt_type,
|
||||
):
|
||||
return self.get_base_hostdev_pci_config(vif)
|
||||
|
||||
def _set_config_VIFGeneric(self, instance, vif, conf):
|
||||
|
@ -503,14 +507,15 @@ class LibvirtGenericVIFDriver(object):
|
|||
# is not optional in __init__.
|
||||
raise TypeError("self.host must set to use this function.")
|
||||
|
||||
def _get_config_os_vif(self, instance, vif, image_meta, inst_type,
|
||||
virt_type, vnic_type):
|
||||
def _get_config_os_vif(
|
||||
self, instance, vif, image_meta, flavor, virt_type, vnic_type,
|
||||
):
|
||||
"""Get the domain config for a VIF
|
||||
|
||||
:param instance: nova.objects.Instance
|
||||
:param vif: os_vif.objects.vif.VIFBase subclass
|
||||
:param image_meta: nova.objects.ImageMeta
|
||||
:param inst_type: nova.objects.Flavor
|
||||
:param flavor: nova.objects.Flavor
|
||||
:param virt_type: virtualization type
|
||||
:param vnic_type: vnic type
|
||||
|
||||
|
@ -518,8 +523,8 @@ class LibvirtGenericVIFDriver(object):
|
|||
"""
|
||||
|
||||
# Do the config that's common to all vif types
|
||||
conf = self.get_base_config(instance, vif.address, image_meta,
|
||||
inst_type, virt_type, vnic_type)
|
||||
conf = self.get_base_config(
|
||||
instance, vif.address, image_meta, flavor, virt_type, vnic_type)
|
||||
|
||||
# Do the VIF type specific config
|
||||
if isinstance(vif, osv_vifs.VIFGeneric):
|
||||
|
@ -545,14 +550,14 @@ class LibvirtGenericVIFDriver(object):
|
|||
# not all VIF types support bandwidth configuration
|
||||
# https://github.com/libvirt/libvirt/blob/568a41722/src/conf/netdev_bandwidth_conf.h#L38
|
||||
if vif.obj_name() not in ('VIFVHostUser', 'VIFHostDevice'):
|
||||
designer.set_vif_bandwidth_config(conf, inst_type)
|
||||
designer.set_vif_bandwidth_config(conf, flavor)
|
||||
|
||||
if 'network' in vif and 'mtu' in vif.network:
|
||||
designer.set_vif_mtu_config(conf, vif.network.mtu)
|
||||
|
||||
return conf
|
||||
|
||||
def get_config(self, instance, vif, image_meta, inst_type, virt_type):
|
||||
def get_config(self, instance, vif, image_meta, flavor, virt_type):
|
||||
vif_type = vif['type']
|
||||
vnic_type = vif['vnic_type']
|
||||
|
||||
|
@ -571,11 +576,11 @@ class LibvirtGenericVIFDriver(object):
|
|||
# Try os-vif codepath first
|
||||
vif_obj = os_vif_util.nova_to_osvif_vif(vif)
|
||||
if vif_obj is not None:
|
||||
return self._get_config_os_vif(instance, vif_obj, image_meta,
|
||||
inst_type, virt_type, vnic_type)
|
||||
return self._get_config_os_vif(
|
||||
instance, vif_obj, image_meta, flavor, virt_type, vnic_type)
|
||||
|
||||
# Legacy non-os-vif codepath
|
||||
args = (instance, vif, image_meta, inst_type, virt_type)
|
||||
args = (instance, vif, image_meta, flavor, virt_type)
|
||||
if vif_type == network_model.VIF_TYPE_IOVISOR:
|
||||
return self.get_config_iovisor(*args)
|
||||
elif vif_type == network_model.VIF_TYPE_802_QBG:
|
||||
|
|
Loading…
Reference in New Issue