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
|
endpoints Discover endpoints that get returned from the
|
||||||
authenticate services
|
authenticate services
|
||||||
evacuate Evacuate a server from failed host
|
evacuate Evacuate a server from failed host
|
||||||
flavor-create Create a new flavor
|
flavor-create Create a new flavor.
|
||||||
flavor-delete Delete a specific flavor
|
flavor-delete Delete a specific flavor.
|
||||||
flavor-list Print a list of available 'flavors' (sizes of
|
flavor-list Print a list of available 'flavors' (sizes of
|
||||||
servers).
|
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-create Allocate a floating IP for the current tenant.
|
||||||
floating-ip-delete De-allocate a floating IP.
|
floating-ip-delete De-allocate a floating IP.
|
||||||
floating-ip-list List floating ips for this tenant.
|
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."""
|
"""Helper for the _find_* methods."""
|
||||||
# first try to get entity as integer id
|
# first try to get entity as integer id
|
||||||
try:
|
try:
|
||||||
is_intid = isinstance(name_or_id, int) or name_or_id.isdigit()
|
return manager.get(int(name_or_id))
|
||||||
except AttributeError:
|
except (TypeError, ValueError, exceptions.NotFound):
|
||||||
is_intid = False
|
pass
|
||||||
|
|
||||||
if is_intid:
|
|
||||||
try:
|
|
||||||
return manager.get(int(name_or_id))
|
|
||||||
except exceptions.NotFound:
|
|
||||||
pass
|
|
||||||
|
|
||||||
# now try to get entity as uuid
|
# now try to get entity as uuid
|
||||||
try:
|
try:
|
||||||
@ -365,13 +359,6 @@ def is_uuid_like(val):
|
|||||||
return False
|
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):
|
def _load_entry_point(ep_name, name=None):
|
||||||
"""Try to load the entry point ep_name that matches name."""
|
"""Try to load the entry point ep_name that matches name."""
|
||||||
for ep in pkg_resources.iter_entry_points(ep_name, name=name):
|
for ep in pkg_resources.iter_entry_points(ep_name, name=name):
|
||||||
|
@ -134,35 +134,37 @@ class FlavorManager(base.ManagerWithFind):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ram = int(ram)
|
ram = int(ram)
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
raise exceptions.CommandError("Ram must be an integer.")
|
raise exceptions.CommandError("Ram must be an integer.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vcpus = int(vcpus)
|
vcpus = int(vcpus)
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
raise exceptions.CommandError("VCPUs must be an integer.")
|
raise exceptions.CommandError("VCPUs must be an integer.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
disk = int(disk)
|
disk = int(disk)
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
raise exceptions.CommandError("Disk must be an integer.")
|
raise exceptions.CommandError("Disk must be an integer.")
|
||||||
|
|
||||||
if flavorid == "auto":
|
if flavorid == "auto":
|
||||||
flavorid = None
|
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:
|
try:
|
||||||
swap = int(swap)
|
swap = int(swap)
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
raise exceptions.CommandError("Swap must be an integer.")
|
raise exceptions.CommandError("Swap must be an integer.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ephemeral = int(ephemeral)
|
ephemeral = int(ephemeral)
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
raise exceptions.CommandError("Ephemeral must be an integer.")
|
raise exceptions.CommandError("Ephemeral must be an integer.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rxtx_factor = float(rxtx_factor)
|
rxtx_factor = float(rxtx_factor)
|
||||||
except:
|
except (TypeError, ValueError):
|
||||||
raise exceptions.CommandError("rxtx_factor must be a float.")
|
raise exceptions.CommandError("rxtx_factor must be a float.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -416,7 +416,7 @@ def _print_flavor_extra_specs(flavor):
|
|||||||
return "N/A"
|
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)
|
_translate_flavor_keys(flavors)
|
||||||
|
|
||||||
headers = [
|
headers = [
|
||||||
@ -456,7 +456,7 @@ def do_flavor_list(cs, args):
|
|||||||
flavors = cs.flavors.list(is_public=None)
|
flavors = cs.flavors.list(is_public=None)
|
||||||
else:
|
else:
|
||||||
flavors = cs.flavors.list()
|
flavors = cs.flavors.list()
|
||||||
_print_flavor_list(cs, flavors, args.extra_specs)
|
_print_flavor_list(flavors, args.extra_specs)
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('flavor',
|
@utils.arg('flavor',
|
||||||
@ -466,6 +466,7 @@ def do_flavor_delete(cs, args):
|
|||||||
"""Delete a specific flavor"""
|
"""Delete a specific flavor"""
|
||||||
flavorid = _find_flavor(cs, args.flavor)
|
flavorid = _find_flavor(cs, args.flavor)
|
||||||
cs.flavors.delete(flavorid)
|
cs.flavors.delete(flavorid)
|
||||||
|
_print_flavor_list([flavorid])
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('flavor',
|
@utils.arg('flavor',
|
||||||
@ -474,7 +475,7 @@ def do_flavor_delete(cs, args):
|
|||||||
def do_flavor_show(cs, args):
|
def do_flavor_show(cs, args):
|
||||||
"""Show details about the given flavor."""
|
"""Show details about the given flavor."""
|
||||||
flavor = _find_flavor(cs, args.flavor)
|
flavor = _find_flavor(cs, args.flavor)
|
||||||
_print_flavor(cs, flavor)
|
_print_flavor(flavor)
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('name',
|
@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,
|
f = cs.flavors.create(args.name, args.ram, args.vcpus, args.disk, args.id,
|
||||||
args.ephemeral, args.swap, args.rxtx_factor,
|
args.ephemeral, args.swap, args.rxtx_factor,
|
||||||
args.is_public)
|
args.is_public)
|
||||||
_print_flavor_list(cs, [f])
|
_print_flavor_list([f])
|
||||||
|
|
||||||
|
|
||||||
@utils.arg('flavor',
|
@utils.arg('flavor',
|
||||||
@ -847,7 +848,7 @@ def _print_image(image):
|
|||||||
utils.print_dict(info)
|
utils.print_dict(info)
|
||||||
|
|
||||||
|
|
||||||
def _print_flavor(cs, flavor):
|
def _print_flavor(flavor):
|
||||||
info = flavor._info.copy()
|
info = flavor._info.copy()
|
||||||
# ignore links, we don't need to present those
|
# ignore links, we don't need to present those
|
||||||
info.pop('links')
|
info.pop('links')
|
||||||
|
Loading…
Reference in New Issue
Block a user