summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorJoe Gordon <joe.gordon0@gmail.com>2013-05-17 22:01:03 -0700
committerJoe Gordon <joe.gordon0@gmail.com>2013-06-11 10:36:39 -0700
commitb7fe4e206b54f5f43d520c1e9504f268fc1dff9a (patch)
tree4858654bf5f34b6d2686df69be095f5f46c32434 /nova/compute
parent685228d96b7d40f537cf6144014234e24e8cd7fd (diff)
Rename functions in nova.compute.flavors from instance_type
Second step in removing references to instance_types. Remove all references to instance_type in nova.compute.flavors. Also update compute devref to reflect changed name. Partially implements bp flavor-instance-type-dedup renamed: nova/tests/test_instance_types.py -> test_flavors.py Change-Id: I7413bf832c61d04ab90ec8b1370d3f01372c4172
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/api.py29
-rw-r--r--nova/compute/cells_api.py4
-rw-r--r--nova/compute/flavors.py72
-rwxr-xr-xnova/compute/manager.py24
-rw-r--r--nova/compute/resource_tracker.py4
-rw-r--r--nova/compute/utils.py2
6 files changed, 67 insertions, 68 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 65142aef0..145a0ee27 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -599,7 +599,7 @@ class API(base.Base):
root_device_name = block_device.properties_root_device_name(
image.get('properties', {}))
- system_metadata = flavors.save_instance_type_info(
+ system_metadata = flavors.save_flavor_info(
dict(), instance_type)
base_options = {
@@ -731,7 +731,7 @@ class API(base.Base):
max_count = max_count or min_count
block_device_mapping = block_device_mapping or []
if not instance_type:
- instance_type = flavors.get_default_instance_type()
+ instance_type = flavors.get_default_flavor()
if image_href:
image_id, image = self._get_image(context, image_href)
@@ -1244,9 +1244,8 @@ class API(base.Base):
new_instance['instance_type_id'] ==
migration_ref['new_instance_type_id']):
old_inst_type_id = migration_ref['old_instance_type_id']
- get_inst_type_by_id = flavors.get_instance_type
try:
- old_inst_type = get_inst_type_by_id(old_inst_type_id)
+ old_inst_type = flavors.get_flavor(old_inst_type_id)
except exception.InstanceTypeNotFound:
LOG.warning(_("instance type %(old_inst_type_id)d "
"not found") % locals())
@@ -1340,7 +1339,7 @@ class API(base.Base):
def restore(self, context, instance):
"""Restore a previously deleted (but not reclaimed) instance."""
# Reserve quotas
- instance_type = flavors.extract_instance_type(instance)
+ instance_type = flavors.extract_flavor(instance)
num_instances, quota_reservations = self._check_num_instances_quota(
context, instance_type, 1, 1)
@@ -1420,7 +1419,7 @@ class API(base.Base):
#NOTE(bcwaldon): this doesn't really belong in this class
def get_instance_type(self, context, instance_type_id):
"""Get an instance type by instance type id."""
- return flavors.get_instance_type(instance_type_id)
+ return flavors.get_flavor(instance_type_id)
def get(self, context, instance_id):
"""Get a single instance with the given instance_id."""
@@ -1477,7 +1476,7 @@ class API(base.Base):
filters = {}
def _remap_flavor_filter(flavor_id):
- instance_type = flavors.get_instance_type_by_flavor_id(
+ instance_type = flavors.get_flavor_by_flavor_id(
flavor_id)
filters['instance_type_id'] = instance_type['id']
@@ -1756,7 +1755,7 @@ class API(base.Base):
#disk format of vhd is non-shrinkable
if orig_image.get('disk_format') == 'vhd':
- instance_type = flavors.extract_instance_type(instance)
+ instance_type = flavors.extract_flavor(instance)
min_disk = instance_type['root_gb']
else:
#set new image values to the original image values
@@ -1834,7 +1833,7 @@ class API(base.Base):
orig_image_ref = instance['image_ref'] or ''
files_to_inject = kwargs.pop('files_to_inject', [])
metadata = kwargs.get('metadata', {})
- instance_type = flavors.extract_instance_type(instance)
+ instance_type = flavors.extract_flavor(instance)
image_id, image = self._get_image(context, image_href)
@@ -2003,9 +2002,9 @@ class API(base.Base):
Calculate deltas required to reverse a prior upsizing
quota adjustment.
"""
- old_instance_type = flavors.get_instance_type(
+ old_instance_type = flavors.get_flavor(
migration_ref['old_instance_type_id'])
- new_instance_type = flavors.get_instance_type(
+ new_instance_type = flavors.get_flavor(
migration_ref['new_instance_type_id'])
return API._resize_quota_delta(context, new_instance_type,
@@ -2016,9 +2015,9 @@ class API(base.Base):
"""
Calculate deltas required to adjust quota for an instance downsize.
"""
- old_instance_type = flavors.extract_instance_type(instance,
+ old_instance_type = flavors.extract_flavor(instance,
'old_')
- new_instance_type = flavors.extract_instance_type(instance,
+ new_instance_type = flavors.extract_flavor(instance,
'new_')
return API._resize_quota_delta(context, new_instance_type,
old_instance_type, 1, -1)
@@ -2038,7 +2037,7 @@ class API(base.Base):
the original flavor_id. If flavor_id is not None, the instance should
be migrated to a new host and resized to the new flavor_id.
"""
- current_instance_type = flavors.extract_instance_type(instance)
+ current_instance_type = flavors.extract_flavor(instance)
# If flavor_id is not provided, only migrate the instance.
if not flavor_id:
@@ -2046,7 +2045,7 @@ class API(base.Base):
instance=instance)
new_instance_type = current_instance_type
else:
- new_instance_type = flavors.get_instance_type_by_flavor_id(
+ new_instance_type = flavors.get_flavor_by_flavor_id(
flavor_id, read_deleted="no")
current_instance_type_name = current_instance_type['name']
diff --git a/nova/compute/cells_api.py b/nova/compute/cells_api.py
index 5ac5dd475..6f1e12480 100644
--- a/nova/compute/cells_api.py
+++ b/nova/compute/cells_api.py
@@ -350,12 +350,12 @@ class ComputeCellsAPI(compute_api.API):
# specified flavor_id is valid and exists. We'll need to load
# it again, but that should be safe.
- old_instance_type = flavors.extract_instance_type(instance)
+ old_instance_type = flavors.extract_flavor(instance)
if not flavor_id:
new_instance_type = old_instance_type
else:
- new_instance_type = flavors.get_instance_type_by_flavor_id(
+ new_instance_type = flavors.get_flavor_by_flavor_id(
flavor_id, read_deleted="no")
# NOTE(johannes): Later, when the resize is confirmed or reverted,
diff --git a/nova/compute/flavors.py b/nova/compute/flavors.py
index 7177f26bd..b58f1f05d 100644
--- a/nova/compute/flavors.py
+++ b/nova/compute/flavors.py
@@ -33,14 +33,16 @@ from nova.openstack.common import log as logging
from nova.openstack.common import strutils
from nova import utils
-instance_type_opts = [
- cfg.StrOpt('default_instance_type',
+flavor_opts = [
+ cfg.StrOpt('default_flavor',
+ # Deprecated in Havana
+ deprecated_name='default_instance_type',
default='m1.small',
- help='default instance type to use, testing only'),
+ help='default flavor to use, testing only'),
]
CONF = cfg.CONF
-CONF.register_opts(instance_type_opts)
+CONF.register_opts(flavor_opts)
LOG = logging.getLogger(__name__)
@@ -52,7 +54,7 @@ def _int_or_none(val):
return int(val)
-system_metadata_instance_type_props = {
+system_metadata_flavor_props = {
'id': int,
'name': str,
'memory_mb': int,
@@ -68,7 +70,7 @@ system_metadata_instance_type_props = {
def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
swap=0, rxtx_factor=1.0, is_public=True):
- """Creates instance types."""
+ """Creates flavors."""
if not flavorid:
flavorid = uuid.uuid4()
@@ -137,7 +139,7 @@ def create(name, memory, vcpus, root_gb, ephemeral_gb=0, flavorid=None,
def destroy(name):
- """Marks instance types as deleted."""
+ """Marks flavor as deleted."""
try:
assert name is not None
db.instance_type_destroy(context.get_admin_context(), name)
@@ -146,10 +148,10 @@ def destroy(name):
raise exception.InstanceTypeNotFoundByName(instance_type_name=name)
-def get_all_types(ctxt=None, inactive=False, filters=None):
+def get_all_flavors(ctxt=None, inactive=False, filters=None):
"""Get all non-deleted flavors.
- Pass true as argument if you want deleted instance types returned also.
+ Pass true as argument if you want deleted flavors returned also.
"""
if ctxt is None:
ctxt = context.get_admin_context()
@@ -162,19 +164,17 @@ def get_all_types(ctxt=None, inactive=False, filters=None):
inst_type_dict[inst_type['name']] = inst_type
return inst_type_dict
-get_all_flavors = get_all_types
+def get_default_flavor():
+ """Get the default flavor."""
+ name = CONF.default_flavor
+ return get_flavor_by_name(name)
-def get_default_instance_type():
- """Get the default instance type."""
- name = CONF.default_instance_type
- return get_instance_type_by_name(name)
-
-def get_instance_type(instance_type_id, ctxt=None, inactive=False):
- """Retrieves single instance type by id."""
+def get_flavor(instance_type_id, ctxt=None, inactive=False):
+ """Retrieves single flavor by id."""
if instance_type_id is None:
- return get_default_instance_type()
+ return get_default_flavor()
if ctxt is None:
ctxt = context.get_admin_context()
@@ -185,10 +185,10 @@ def get_instance_type(instance_type_id, ctxt=None, inactive=False):
return db.instance_type_get(ctxt, instance_type_id)
-def get_instance_type_by_name(name, ctxt=None):
- """Retrieves single instance type by name."""
+def get_flavor_by_name(name, ctxt=None):
+ """Retrieves single flavor by name."""
if name is None:
- return get_default_instance_type()
+ return get_default_flavor()
if ctxt is None:
ctxt = context.get_admin_context()
@@ -198,8 +198,8 @@ def get_instance_type_by_name(name, ctxt=None):
# TODO(termie): flavor-specific code should probably be in the API that uses
# flavors.
-def get_instance_type_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
- """Retrieve instance type by flavorid.
+def get_flavor_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
+ """Retrieve flavor by flavorid.
:raises: FlavorNotFound
"""
@@ -209,43 +209,43 @@ def get_instance_type_by_flavor_id(flavorid, ctxt=None, read_deleted="yes"):
return db.instance_type_get_by_flavor_id(ctxt, flavorid)
-def get_instance_type_access_by_flavor_id(flavorid, ctxt=None):
- """Retrieve instance type access list by flavor id."""
+def get_flavor_access_by_flavor_id(flavorid, ctxt=None):
+ """Retrieve flavor access list by flavor id."""
if ctxt is None:
ctxt = context.get_admin_context()
return db.instance_type_access_get_by_flavor_id(ctxt, flavorid)
-def add_instance_type_access(flavorid, projectid, ctxt=None):
- """Add instance type access for project."""
+def add_flavor_access(flavorid, projectid, ctxt=None):
+ """Add flavor access for project."""
if ctxt is None:
ctxt = context.get_admin_context()
return db.instance_type_access_add(ctxt, flavorid, projectid)
-def remove_instance_type_access(flavorid, projectid, ctxt=None):
- """Remove instance type access for project."""
+def remove_flavor_access(flavorid, projectid, ctxt=None):
+ """Remove flavor access for project."""
if ctxt is None:
ctxt = context.get_admin_context()
return db.instance_type_access_remove(ctxt, flavorid, projectid)
-def extract_instance_type(instance, prefix=''):
+def extract_flavor(instance, prefix=''):
"""Create an InstanceType-like object from instance's system_metadata
information."""
instance_type = {}
sys_meta = utils.instance_sys_meta(instance)
- for key, type_fn in system_metadata_instance_type_props.items():
+ for key, type_fn in system_metadata_flavor_props.items():
type_key = '%sinstance_type_%s' % (prefix, key)
instance_type[key] = type_fn(sys_meta[type_key])
return instance_type
-def save_instance_type_info(metadata, instance_type, prefix=''):
+def save_flavor_info(metadata, instance_type, prefix=''):
"""Save properties from instance_type into instance's system_metadata,
in the format of:
@@ -255,17 +255,17 @@ def save_instance_type_info(metadata, instance_type, prefix=''):
as stash information about another instance_type for later use (such as
during resize)."""
- for key in system_metadata_instance_type_props.keys():
+ for key in system_metadata_flavor_props.keys():
to_key = '%sinstance_type_%s' % (prefix, key)
metadata[to_key] = instance_type[key]
return metadata
-def delete_instance_type_info(metadata, *prefixes):
- """Delete instance_type information from instance's system_metadata
+def delete_flavor_info(metadata, *prefixes):
+ """Delete flavor instance_type information from instance's system_metadata
by prefix."""
- for key in system_metadata_instance_type_props.keys():
+ for key in system_metadata_flavor_props.keys():
for prefix in prefixes:
to_key = '%sinstance_type_%s' % (prefix, key)
del metadata[to_key]
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 42f8029a5..5c697993b 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -2130,15 +2130,15 @@ class ComputeManager(manager.SchedulerDependentManager):
"""
sys_meta = utils.metadata_to_dict(instance['system_metadata'])
if restore_old:
- instance_type = flavors.extract_instance_type(instance,
+ instance_type = flavors.extract_flavor(instance,
'old_')
- sys_meta = flavors.save_instance_type_info(sys_meta,
+ sys_meta = flavors.save_flavor_info(sys_meta,
instance_type)
else:
- instance_type = flavors.extract_instance_type(instance)
+ instance_type = flavors.extract_flavor(instance)
- flavors.delete_instance_type_info(sys_meta, 'old_')
- flavors.delete_instance_type_info(sys_meta, 'new_')
+ flavors.delete_flavor_info(sys_meta, 'old_')
+ flavors.delete_flavor_info(sys_meta, 'new_')
return sys_meta, instance_type
@@ -2384,7 +2384,7 @@ class ComputeManager(manager.SchedulerDependentManager):
# NOTE(danms): Stash the new instance_type to avoid having to
# look it up in the database later
sys_meta = utils.metadata_to_dict(instance['system_metadata'])
- flavors.save_instance_type_info(sys_meta, instance_type,
+ flavors.save_flavor_info(sys_meta, instance_type,
prefix='new_')
# NOTE(mriedem): Stash the old vm_state so we can set the
# resized/reverted instance back to the same state later.
@@ -2555,19 +2555,19 @@ class ComputeManager(manager.SchedulerDependentManager):
resize_instance = False
old_instance_type_id = migration['old_instance_type_id']
new_instance_type_id = migration['new_instance_type_id']
- old_instance_type = flavors.extract_instance_type(instance)
+ old_instance_type = flavors.extract_flavor(instance)
sys_meta = utils.metadata_to_dict(instance['system_metadata'])
# NOTE(mriedem): Get the old_vm_state so we know if we should
# power on the instance. If old_vm_sate is not set we need to default
# to ACTIVE for backwards compatibility
old_vm_state = sys_meta.get('old_vm_state', vm_states.ACTIVE)
- flavors.save_instance_type_info(sys_meta,
- old_instance_type,
- prefix='old_')
+ flavors.save_flavor_info(sys_meta,
+ old_instance_type,
+ prefix='old_')
if old_instance_type_id != new_instance_type_id:
- instance_type = flavors.extract_instance_type(instance,
+ instance_type = flavors.extract_flavor(instance,
prefix='new_')
- flavors.save_instance_type_info(sys_meta, instance_type)
+ flavors.save_flavor_info(sys_meta, instance_type)
instance = self._instance_update(
context,
diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py
index ef91063b4..43fd80c43 100644
--- a/nova/compute/resource_tracker.py
+++ b/nova/compute/resource_tracker.py
@@ -160,7 +160,7 @@ class ResourceTracker(object):
be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource
claim will not be lost if the audit process starts.
"""
- old_instance_type = flavors.extract_instance_type(instance)
+ old_instance_type = flavors.extract_flavor(instance)
return self.conductor_api.migration_create(context, instance,
{'dest_compute': self.host,
@@ -580,7 +580,7 @@ class ResourceTracker(object):
instance_type_id = instance['instance_type_id']
try:
- return flavors.extract_instance_type(instance, prefix)
+ return flavors.extract_flavor(instance, prefix)
except KeyError:
return self.conductor_api.instance_type_get(context,
instance_type_id)
diff --git a/nova/compute/utils.py b/nova/compute/utils.py
index 1ce115b20..561c3308a 100644
--- a/nova/compute/utils.py
+++ b/nova/compute/utils.py
@@ -151,7 +151,7 @@ def get_device_name_for_instance(context, instance, bdms, device):
# NOTE(vish): remove this when xenapi is properly setting
# default_ephemeral_device and default_swap_device
if driver.compute_driver_matches('xenapi.XenAPIDriver'):
- instance_type = flavors.extract_instance_type(instance)
+ instance_type = flavors.extract_flavor(instance)
if instance_type['ephemeral_gb']:
used_letters.add('b')