diff options
author | Shobhi Jain <shobhi.jain@intel.com> | 2018-04-05 16:04:08 +0100 |
---|---|---|
committer | Shobhi Jain <shobhi.jain@intel.com> | 2018-05-03 08:27:37 +0000 |
commit | 35bbd618b1e69a5b5edbd64a333720bfa5a92400 (patch) | |
tree | 77c31dab3d92018239b13b95ee2613278a76cc1d /yardstick/common/openstack_utils.py | |
parent | d75a91ebf2937e5cfe5cf2aa5a90db9121f73967 (diff) |
Replace nova get flavor with shade client.
Rename get_flavor_by_name with get_flavor.
Function get_flavor now uses shade client.
JIRA: YARDSTICK-1088
Change-Id: Ic82127e475baf39643be0a254b177f3058b85748
Signed-off-by: Shobhi Jain <shobhi.jain@intel.com>
Diffstat (limited to 'yardstick/common/openstack_utils.py')
-rw-r--r-- | yardstick/common/openstack_utils.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index 0220c4212..68cf0a521 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -363,12 +363,22 @@ def get_flavor_id(nova_client, flavor_name): # pragma: no cover return flavor_id -def get_flavor_by_name(name): # pragma: no cover - flavors = get_nova_client().flavors.list() +def get_flavor(shade_client, name_or_id, filters=None, get_extra=True): + """Get a flavor by name or ID. + + :param name_or_id: Name or ID of the flavor. + :param filters: A dictionary of meta data to use for further filtering. + :param get_extra: Whether or not the list_flavors call should get the extra + flavor specs. + + :returns: A flavor ``munch.Munch`` or None if no matching flavor is found. + """ try: - return next((a for a in flavors if a.name == name)) - except StopIteration: - log.exception('No flavor matched') + return shade_client.get_flavor(name_or_id, filters=filters, + get_extra=get_extra) + except exc.OpenStackCloudException as o_exc: + log.error("Error [get_flavor(shade_client, '%s')]. " + "Exception message: %s", name_or_id, o_exc.orig_message) def delete_flavor(flavor_id): # pragma: no cover |