Skip to content

Commit 052cf96

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Remove (almost) all references to 'instance_type'"
2 parents 75ef63f + 1bf45c4 commit 052cf96

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+639
-651
lines changed

nova/api/metadata/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ def get_ec2_metadata(self, version):
279279
meta_data['public-ipv4'] = floating_ip
280280

281281
if self._check_version('2007-08-29', version):
282-
instance_type = self.instance.get_flavor()
283-
meta_data['instance-type'] = instance_type['name']
282+
flavor = self.instance.get_flavor()
283+
meta_data['instance-type'] = flavor['name']
284284

285285
if self._check_version('2007-12-15', version):
286286
meta_data['block-device-mapping'] = self.mappings

nova/api/openstack/compute/views/servers.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -547,34 +547,32 @@ def _get_image(self, request, instance):
547547
else:
548548
return ""
549549

550-
def _get_flavor_dict(self, request, instance_type, show_extra_specs):
550+
def _get_flavor_dict(self, request, flavor, show_extra_specs):
551551
flavordict = {
552-
"vcpus": instance_type.vcpus,
553-
"ram": instance_type.memory_mb,
554-
"disk": instance_type.root_gb,
555-
"ephemeral": instance_type.ephemeral_gb,
556-
"swap": instance_type.swap,
557-
"original_name": instance_type.name
552+
"vcpus": flavor.vcpus,
553+
"ram": flavor.memory_mb,
554+
"disk": flavor.root_gb,
555+
"ephemeral": flavor.ephemeral_gb,
556+
"swap": flavor.swap,
557+
"original_name": flavor.name
558558
}
559559
if show_extra_specs:
560-
flavordict['extra_specs'] = instance_type.extra_specs
560+
flavordict['extra_specs'] = flavor.extra_specs
561561
return flavordict
562562

563563
def _get_flavor(self, request, instance, show_extra_specs):
564-
instance_type = instance.get_flavor()
565-
if not instance_type:
566-
LOG.warning("Instance has had its instance_type removed "
564+
flavor = instance.get_flavor()
565+
if not flavor:
566+
LOG.warning("Instance has had its flavor removed "
567567
"from the DB", instance=instance)
568568
return {}
569569

570570
if api_version_request.is_supported(request, min_version="2.47"):
571-
return self._get_flavor_dict(request, instance_type,
572-
show_extra_specs)
571+
return self._get_flavor_dict(request, flavor, show_extra_specs)
573572

574-
flavor_id = instance_type["flavorid"]
575-
flavor_bookmark = self._flavor_builder._get_bookmark_link(request,
576-
flavor_id,
577-
"flavors")
573+
flavor_id = flavor["flavorid"]
574+
flavor_bookmark = self._flavor_builder._get_bookmark_link(
575+
request, flavor_id, "flavors")
578576
return {
579577
"id": str(flavor_id),
580578
"links": [{

nova/compute/claims.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ class Claim(NopClaim):
5757
correct decisions with respect to host selection.
5858
"""
5959

60-
def __init__(self, context, instance, nodename, tracker, compute_node,
61-
pci_requests, migration=None, limits=None):
62-
super(Claim, self).__init__(migration=migration)
60+
def __init__(
61+
self, context, instance, nodename, tracker, compute_node, pci_requests,
62+
migration=None, limits=None,
63+
):
64+
super().__init__(migration=migration)
6365
# Stash a copy of the instance at the current point of time
6466
self.instance = instance.obj_clone()
6567
self.nodename = nodename
@@ -159,21 +161,24 @@ class MoveClaim(Claim):
159161
160162
Move can be either a migrate/resize, live-migrate or an evacuate operation.
161163
"""
162-
def __init__(self, context, instance, nodename, instance_type, image_meta,
163-
tracker, compute_node, pci_requests, migration, limits=None):
164+
def __init__(
165+
self, context, instance, nodename, flavor, image_meta, tracker,
166+
compute_node, pci_requests, migration, limits=None,
167+
):
164168
self.context = context
165-
self.instance_type = instance_type
169+
self.flavor = flavor
166170
if isinstance(image_meta, dict):
167171
image_meta = objects.ImageMeta.from_dict(image_meta)
168172
self.image_meta = image_meta
169-
super(MoveClaim, self).__init__(context, instance, nodename, tracker,
170-
compute_node, pci_requests,
171-
migration=migration, limits=limits)
173+
174+
super().__init__(
175+
context, instance, nodename, tracker, compute_node, pci_requests,
176+
migration=migration, limits=limits,
177+
)
172178

173179
@property
174180
def numa_topology(self):
175-
return hardware.numa_get_constraints(self.instance_type,
176-
self.image_meta)
181+
return hardware.numa_get_constraints(self.flavor, self.image_meta)
177182

178183
def abort(self):
179184
"""Compute operation requiring claimed resources has failed or
@@ -183,7 +188,7 @@ def abort(self):
183188
self.tracker.drop_move_claim(
184189
self.context,
185190
self.instance, self.nodename,
186-
instance_type=self.instance_type)
191+
flavor=self.flavor)
187192
self.instance.drop_migration_context()
188193

189194
def _test_pci(self):

nova/compute/flavors.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,26 +173,27 @@ def extract_flavor(instance, prefix=''):
173173
# NOTE(danms): This method is deprecated, do not use it!
174174
# Use instance.{old_,new_,}flavor instead, as instances no longer
175175
# have flavor information in system_metadata.
176-
def save_flavor_info(metadata, instance_type, prefix=''):
177-
"""Save properties from instance_type into instance's system_metadata,
176+
# NOTE(stephenfin): 'prefix' is unused and could be removed
177+
def save_flavor_info(metadata, flavor, prefix=''):
178+
"""Save properties from flavor into instance's system_metadata,
178179
in the format of:
179180
180181
[prefix]instance_type_[key]
181182
182183
This can be used to update system_metadata in place from a type, as well
183-
as stash information about another instance_type for later use (such as
184+
as stash information about another flavor for later use (such as
184185
during resize).
185186
"""
186187

187188
for key in system_metadata_flavor_props.keys():
188189
to_key = '%sinstance_type_%s' % (prefix, key)
189-
metadata[to_key] = instance_type[key]
190+
metadata[to_key] = flavor[key]
190191

191192
# NOTE(danms): We do NOT save all of extra_specs here, but only the
192193
# NUMA-related ones that we need to avoid an uglier alternative. This
193194
# should be replaced by a general split-out of flavor information from
194195
# system_metadata very soon.
195-
extra_specs = instance_type.get('extra_specs', {})
196+
extra_specs = flavor.get('extra_specs', {})
196197
for extra_prefix in system_metadata_flavor_extra_props:
197198
for key in extra_specs:
198199
if key.startswith(extra_prefix):

nova/compute/manager.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5083,9 +5083,10 @@ def _revert_allocation(self, context, instance, migration):
50835083
instance.uuid)
50845084
return orig_alloc
50855085

5086-
def _prep_resize(self, context, image, instance, instance_type,
5087-
filter_properties, node, migration, request_spec,
5088-
clean_shutdown=True):
5086+
def _prep_resize(
5087+
self, context, image, instance, flavor, filter_properties, node,
5088+
migration, request_spec, clean_shutdown=True,
5089+
):
50895090

50905091
if not filter_properties:
50915092
filter_properties = {}
@@ -5097,7 +5098,7 @@ def _prep_resize(self, context, image, instance, instance_type,
50975098

50985099
same_host = instance.host == self.host
50995100
# if the flavor IDs match, it's migrate; otherwise resize
5100-
if same_host and instance_type.id == instance['instance_type_id']:
5101+
if same_host and flavor.id == instance['instance_type_id']:
51015102
# check driver whether support migrate to same host
51025103
if not self.driver.capabilities.get(
51035104
'supports_migrate_to_same_host', False):
@@ -5108,9 +5109,9 @@ def _prep_resize(self, context, image, instance, instance_type,
51085109
inner_exception=exception.UnableToMigrateToSelf(
51095110
instance_id=instance.uuid, host=self.host))
51105111

5111-
# NOTE(danms): Stash the new instance_type to avoid having to
5112+
# NOTE(danms): Stash the new flavor to avoid having to
51125113
# look it up in the database later
5113-
instance.new_flavor = instance_type
5114+
instance.new_flavor = flavor
51145115
# NOTE(mriedem): Stash the old vm_state so we can set the
51155116
# resized/reverted instance back to the same state later.
51165117
vm_state = instance.vm_state
@@ -5149,14 +5150,15 @@ def _prep_resize(self, context, image, instance, instance_type,
51495150
limits = filter_properties.get('limits', {})
51505151
allocs = self.reportclient.get_allocations_for_consumer(
51515152
context, instance.uuid)
5152-
with self.rt.resize_claim(context, instance, instance_type, node,
5153-
migration, allocs, image_meta=image,
5154-
limits=limits) as claim:
5153+
with self.rt.resize_claim(
5154+
context, instance, flavor, node, migration, allocs,
5155+
image_meta=image, limits=limits,
5156+
) as claim:
51555157
LOG.info('Migrating', instance=instance)
51565158
# RPC cast to the source host to start the actual resize/migration.
51575159
self.compute_rpcapi.resize_instance(
5158-
context, instance, claim.migration, image,
5159-
instance_type, request_spec, clean_shutdown)
5160+
context, instance, claim.migration, image,
5161+
flavor, request_spec, clean_shutdown)
51605162

51615163
def _send_prep_resize_notifications(
51625164
self, context, instance, phase, flavor):
@@ -5262,7 +5264,7 @@ def prep_resize(self, context, image, instance, flavor,
52625264
flavor)
52635265

52645266
def _reschedule_resize_or_reraise(self, context, instance, exc_info,
5265-
instance_type, request_spec, filter_properties, host_list):
5267+
flavor, request_spec, filter_properties, host_list):
52665268
"""Try to re-schedule the resize or re-raise the original error to
52675269
error out the instance.
52685270
"""
@@ -5291,7 +5293,7 @@ def _reschedule_resize_or_reraise(self, context, instance, exc_info,
52915293
scheduler_hint = {'filter_properties': filter_properties}
52925294

52935295
self.compute_task_api.resize_instance(
5294-
context, instance, scheduler_hint, instance_type,
5296+
context, instance, scheduler_hint, flavor,
52955297
request_spec=request_spec, host_list=host_list)
52965298

52975299
rescheduled = True
@@ -5561,9 +5563,10 @@ def resize_instance(self, context, instance, image,
55615563
with excutils.save_and_reraise_exception():
55625564
self._revert_allocation(context, instance, migration)
55635565

5564-
def _resize_instance(self, context, instance, image,
5565-
migration, instance_type, clean_shutdown,
5566-
request_spec):
5566+
def _resize_instance(
5567+
self, context, instance, image, migration, flavor,
5568+
clean_shutdown, request_spec,
5569+
):
55675570
# Pass instance_state=instance.vm_state because we can resize
55685571
# a STOPPED server and we don't want to set it back to ACTIVE
55695572
# in case migrate_disk_and_power_off raises InstanceFaultRollback.
@@ -5592,10 +5595,10 @@ def _resize_instance(self, context, instance, image,
55925595
timeout, retry_interval = self._get_power_off_values(
55935596
instance, clean_shutdown)
55945597
disk_info = self.driver.migrate_disk_and_power_off(
5595-
context, instance, migration.dest_host,
5596-
instance_type, network_info,
5597-
block_device_info,
5598-
timeout, retry_interval)
5598+
context, instance, migration.dest_host,
5599+
flavor, network_info,
5600+
block_device_info,
5601+
timeout, retry_interval)
55995602

56005603
self._terminate_volume_connections(context, instance, bdms)
56015604

@@ -5672,13 +5675,13 @@ def _terminate_volume_connections(self, context, instance, bdms):
56725675
connector)
56735676

56745677
@staticmethod
5675-
def _set_instance_info(instance, instance_type):
5676-
instance.instance_type_id = instance_type.id
5677-
instance.memory_mb = instance_type.memory_mb
5678-
instance.vcpus = instance_type.vcpus
5679-
instance.root_gb = instance_type.root_gb
5680-
instance.ephemeral_gb = instance_type.ephemeral_gb
5681-
instance.flavor = instance_type
5678+
def _set_instance_info(instance, flavor):
5679+
instance.instance_type_id = flavor.id
5680+
instance.memory_mb = flavor.memory_mb
5681+
instance.vcpus = flavor.vcpus
5682+
instance.root_gb = flavor.root_gb
5683+
instance.ephemeral_gb = flavor.ephemeral_gb
5684+
instance.flavor = flavor
56825685

56835686
def _update_volume_attachments(self, context, instance, bdms):
56845687
"""Updates volume attachments using the virt driver host connector.
@@ -9160,7 +9163,7 @@ def drop_move_claim_at_destination(self, context, instance):
91609163
LOG.debug('Dropping live migration resource claim on destination '
91619164
'node %s', nodename, instance=instance)
91629165
self.rt.drop_move_claim(
9163-
context, instance, nodename, instance_type=instance.flavor)
9166+
context, instance, nodename, flavor=instance.flavor)
91649167

91659168
@wrap_exception()
91669169
@wrap_instance_event(prefix='compute')

0 commit comments

Comments
 (0)