From eaf3c366c34c64f2e0a6ce0ada2b2db7ff09fc5b Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp> Date: Wed, 19 Dec 2012 04:23:36 +0900 Subject: [PATCH] Specify some arguments by name. 'nova boot', 'nova flavor-key', 'nova flavor-show' and the other subcommands can be specified by a flavor name also. But 'nova flavor-delete' and 'nova list --flavor' cannot, also 'nova list --image' cannot be specified by a image name. I feel it is user-friendly that a user can specify arguments by name. By this patch, a user can do it like the following. Before appying this patch: $ nova flavor-delete m1.tiny ERROR: Flavor m1.tiny could not be found. (HTTP 404) (Request-ID: req-af2c049f-1b77-42cf-a9ed-a3914626bc83) $ $ nova list --flavor m1.tiny ERROR: Flavor could not be found (HTTP 422) (Request-ID: req-dbfd5df2-77d7-4a71-a3e6-b1f7fd25b96c) $ $ nova list --image cirros-0.3.0-x86_64-uec $ After appying this patch: $ nova flavor-delete m1.tiny $ $ nova list --flavor m1.tiny +--------------------------------------+--------+--------+------------------+ | ID | Name | Status | Networks | +--------------------------------------+--------+--------+------------------+ | 2f003e0e-bfdf-4f56-bdf9-276732e640a0 | test01 | ACTIVE | private=10.0.0.2 | +--------------------------------------+--------+--------+------------------+ $ $ nova list --image cirros-0.3.0-x86_64-uec +--------------------------------------+--------+--------+------------------+ | ID | Name | Status | Networks | +--------------------------------------+--------+--------+------------------+ | 2f003e0e-bfdf-4f56-bdf9-276732e640a0 | test01 | ACTIVE | private=10.0.0.2 | +--------------------------------------+--------+--------+------------------+ $ Fixes bug 1091814 Change-Id: Ic7f6ce76608a448dea3c151bc349391fbf3fa456 --- novaclient/v1_1/shell.py | 23 +++++++++++++++-------- tests/v1_1/fakes.py | 3 +++ tests/v1_1/test_shell.py | 4 ++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index a0d304971..6c469c1e0 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -358,12 +358,13 @@ def do_flavor_list(cs, _args): _print_flavor_list(cs, flavors) -@utils.arg('id', - metavar='<id>', - help="Unique ID of the flavor to delete") +@utils.arg('flavor', + metavar='<flavor>', + help="Name or ID of the flavor to delete") def do_flavor_delete(cs, args): """Delete a specific flavor""" - cs.flavors.delete(args.id) + flavorid = _find_flavor(cs, args.flavor) + cs.flavors.delete(flavorid) @utils.arg('flavor', @@ -803,12 +804,12 @@ def do_image_delete(cs, args): dest='flavor', metavar='<flavor>', default=None, - help='Search by flavor ID') + help='Search by flavor name or ID') @utils.arg('--image', dest='image', metavar='<image>', default=None, - help='Search by image ID') + help='Search by image name or ID') @utils.arg('--host', dest='host', metavar='<hostname>', @@ -836,14 +837,20 @@ def do_image_delete(cs, args): help='Display information from single tenant (Admin only).') def do_list(cs, args): """List active servers.""" + imageid = None + flavorid = None + if args.image: + imageid = _find_image(cs, args.image).id + if args.flavor: + flavorid = _find_flavor(cs, args.flavor).id search_opts = { 'all_tenants': args.all_tenants, 'reservation_id': args.reservation_id, 'ip': args.ip, 'ip6': args.ip6, 'name': args.name, - 'image': args.image, - 'flavor': args.flavor, + 'image': imageid, + 'flavor': flavorid, 'status': args.status, 'project_id': args.tenant, 'host': args.host, diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py index c9ff8b618..eb106a790 100644 --- a/tests/v1_1/fakes.py +++ b/tests/v1_1/fakes.py @@ -535,6 +535,9 @@ class FakeHTTPClient(base_client.HTTPClient): def delete_flavors_flavordelete(self, **kw): return (202, None) + def delete_flavors_2(self, **kw): + return (202, None) + def post_flavors(self, body, **kw): return (202, {'flavor': self.get_flavors_detail()[1]['flavors'][0]}) diff --git a/tests/v1_1/test_shell.py b/tests/v1_1/test_shell.py index 191e910f0..4b03f6eff 100644 --- a/tests/v1_1/test_shell.py +++ b/tests/v1_1/test_shell.py @@ -464,8 +464,8 @@ class ShellTest(utils.TestCase): 'detailed=1') def test_flavor_delete(self): - self.run_command("flavor-delete flavordelete") - self.assert_called('DELETE', '/flavors/flavordelete') + self.run_command("flavor-delete 2") + self.assert_called('DELETE', '/flavors/2') def test_flavor_create(self): self.run_command("flavor-create flavorcreate "