summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShane Wang <shane.wang@intel.com>2013-05-14 21:47:10 +0800
committerShane Wang <shane.wang@intel.com>2013-05-15 15:55:27 +0800
commit3c97f768e5e175c1f2217be9d976fee8cbdca58b (patch)
tree19fc39dc70ffa9fb03369da01f573141c3898b12
parent075e9ca76ec67eb3b95fc068a60be1ee070114ed (diff)
downloadpython-novaclient-3c97f768e5e175c1f2217be9d976fee8cbdca58b.tar.gz
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>
-rw-r--r--README.rst10
-rw-r--r--novaclient/utils.py19
-rw-r--r--novaclient/v1_1/flavors.py22
-rw-r--r--novaclient/v1_1/shell.py11
4 files changed, 29 insertions, 33 deletions
diff --git a/README.rst b/README.rst
index 6a4fcde1..ed4dc96b 100644
--- a/README.rst
+++ b/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.
diff --git a/novaclient/utils.py b/novaclient/utils.py
index 47a59d15..3a0ad3b6 100644
--- a/novaclient/utils.py
+++ b/novaclient/utils.py
@@ -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):
diff --git a/novaclient/v1_1/flavors.py b/novaclient/v1_1/flavors.py
index 267bd2da..b859d3fb 100644
--- a/novaclient/v1_1/flavors.py
+++ b/novaclient/v1_1/flavors.py
@@ -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:
diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py
index f0ea6919..f6bb6d95 100644
--- a/novaclient/v1_1/shell.py
+++ b/novaclient/v1_1/shell.py
@@ -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')