Cleanup some flavor commands
Some cleanups include: - Add flavor sub-commands into README.rst - Check flavor ID when creating a flavor - Remove check_uuid_like() because it isn't used - Remove parameter cs in some _print_XXX functions because cs is not used Change-Id: If47ce557d33db05f53e382f0670f436e05a340b7 Signed-off-by: Shane Wang <shane.wang@intel.com>
This commit is contained in:
parent
075e9ca76e
commit
3c97f768e5
10
README.rst
10
README.rst
@ -109,10 +109,16 @@ You'll find complete documentation on the shell by running
|
||||
endpoints Discover endpoints that get returned from the
|
||||
authenticate services
|
||||
evacuate Evacuate a server from failed host
|
||||
flavor-create Create a new flavor
|
||||
flavor-delete Delete a specific flavor
|
||||
flavor-create Create a new flavor.
|
||||
flavor-delete Delete a specific flavor.
|
||||
flavor-list Print a list of available 'flavors' (sizes of
|
||||
servers).
|
||||
flavor-show Show details about the given flavor.
|
||||
flavor-key Set or unset extra_spec for a flavor.
|
||||
flavor-access-list Print access information about the given flavor.
|
||||
flavor-access-add Add flavor access for the given tenant.
|
||||
flavor-access-remove
|
||||
Remove flavor access for the given tenant.
|
||||
floating-ip-create Allocate a floating IP for the current tenant.
|
||||
floating-ip-delete De-allocate a floating IP.
|
||||
floating-ip-list List floating ips for this tenant.
|
||||
|
@ -196,15 +196,9 @@ def find_resource(manager, name_or_id):
|
||||
"""Helper for the _find_* methods."""
|
||||
# first try to get entity as integer id
|
||||
try:
|
||||
is_intid = isinstance(name_or_id, int) or name_or_id.isdigit()
|
||||
except AttributeError:
|
||||
is_intid = False
|
||||
|
||||
if is_intid:
|
||||
try:
|
||||
return manager.get(int(name_or_id))
|
||||
except exceptions.NotFound:
|
||||
pass
|
||||
return manager.get(int(name_or_id))
|
||||
except (TypeError, ValueError, exceptions.NotFound):
|
||||
pass
|
||||
|
||||
# now try to get entity as uuid
|
||||
try:
|
||||
@ -365,13 +359,6 @@ def is_uuid_like(val):
|
||||
return False
|
||||
|
||||
|
||||
def check_uuid_like(val):
|
||||
if not is_uuid_like(val):
|
||||
raise exceptions.CommandError(
|
||||
"error: Invalid tenant-id %s supplied"
|
||||
% val)
|
||||
|
||||
|
||||
def _load_entry_point(ep_name, name=None):
|
||||
"""Try to load the entry point ep_name that matches name."""
|
||||
for ep in pkg_resources.iter_entry_points(ep_name, name=name):
|
||||
|
@ -134,35 +134,37 @@ class FlavorManager(base.ManagerWithFind):
|
||||
|
||||
try:
|
||||
ram = int(ram)
|
||||
except:
|
||||
except (TypeError, ValueError):
|
||||
raise exceptions.CommandError("Ram must be an integer.")
|
||||
|
||||
try:
|
||||
vcpus = int(vcpus)
|
||||
except:
|
||||
except (TypeError, ValueError):
|
||||
raise exceptions.CommandError("VCPUs must be an integer.")
|
||||
|
||||
try:
|
||||
disk = int(disk)
|
||||
except:
|
||||
except (TypeError, ValueError):
|
||||
raise exceptions.CommandError("Disk must be an integer.")
|
||||
|
||||
if flavorid == "auto":
|
||||
flavorid = None
|
||||
elif not utils.is_uuid_like(flavorid):
|
||||
try:
|
||||
flavorid = int(flavorid)
|
||||
except (TypeError, ValueError):
|
||||
raise exceptions.CommandError("Flavor ID must be an integer "
|
||||
"or a UUID or auto.")
|
||||
|
||||
try:
|
||||
swap = int(swap)
|
||||
except:
|
||||
except (TypeError, ValueError):
|
||||
raise exceptions.CommandError("Swap must be an integer.")
|
||||
|
||||
try:
|
||||
ephemeral = int(ephemeral)
|
||||
except:
|
||||
except (TypeError, ValueError):
|
||||
raise exceptions.CommandError("Ephemeral must be an integer.")
|
||||
|
||||
try:
|
||||
rxtx_factor = float(rxtx_factor)
|
||||
except:
|
||||
except (TypeError, ValueError):
|
||||
raise exceptions.CommandError("rxtx_factor must be a float.")
|
||||
|
||||
try:
|
||||
|
@ -416,7 +416,7 @@ def _print_flavor_extra_specs(flavor):
|
||||
return "N/A"
|
||||
|
||||
|
||||
def _print_flavor_list(cs, flavors, show_extra_specs=False):
|
||||
def _print_flavor_list(flavors, show_extra_specs=False):
|
||||
_translate_flavor_keys(flavors)
|
||||
|
||||
headers = [
|
||||
@ -456,7 +456,7 @@ def do_flavor_list(cs, args):
|
||||
flavors = cs.flavors.list(is_public=None)
|
||||
else:
|
||||
flavors = cs.flavors.list()
|
||||
_print_flavor_list(cs, flavors, args.extra_specs)
|
||||
_print_flavor_list(flavors, args.extra_specs)
|
||||
|
||||
|
||||
@utils.arg('flavor',
|
||||
@ -466,6 +466,7 @@ def do_flavor_delete(cs, args):
|
||||
"""Delete a specific flavor"""
|
||||
flavorid = _find_flavor(cs, args.flavor)
|
||||
cs.flavors.delete(flavorid)
|
||||
_print_flavor_list([flavorid])
|
||||
|
||||
|
||||
@utils.arg('flavor',
|
||||
@ -474,7 +475,7 @@ def do_flavor_delete(cs, args):
|
||||
def do_flavor_show(cs, args):
|
||||
"""Show details about the given flavor."""
|
||||
flavor = _find_flavor(cs, args.flavor)
|
||||
_print_flavor(cs, flavor)
|
||||
_print_flavor(flavor)
|
||||
|
||||
|
||||
@utils.arg('name',
|
||||
@ -515,7 +516,7 @@ def do_flavor_create(cs, args):
|
||||
f = cs.flavors.create(args.name, args.ram, args.vcpus, args.disk, args.id,
|
||||
args.ephemeral, args.swap, args.rxtx_factor,
|
||||
args.is_public)
|
||||
_print_flavor_list(cs, [f])
|
||||
_print_flavor_list([f])
|
||||
|
||||
|
||||
@utils.arg('flavor',
|
||||
@ -847,7 +848,7 @@ def _print_image(image):
|
||||
utils.print_dict(info)
|
||||
|
||||
|
||||
def _print_flavor(cs, flavor):
|
||||
def _print_flavor(flavor):
|
||||
info = flavor._info.copy()
|
||||
# ignore links, we don't need to present those
|
||||
info.pop('links')
|
||||
|
Loading…
Reference in New Issue
Block a user