From 66d8bc49b70be382b2699d2b883ce265ff915e02 Mon Sep 17 00:00:00 2001 From: Jason Straw Date: Sun, 30 Oct 2011 17:20:47 -0500 Subject: [PATCH 1/3] Updated the novaclient shell to display the parent server id that the image came from. --- novaclient/utils.py | 6 +++++- novaclient/v1_0/shell.py | 9 ++++++++- novaclient/v1_1/shell.py | 9 ++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/novaclient/utils.py b/novaclient/utils.py index 46133a067..834785e0b 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -20,6 +20,7 @@ def pretty_choice_list(l): def print_list(objs, fields, formatters={}): + mixed_case_fields = ['serverId'] pt = prettytable.PrettyTable([f for f in fields], caching=False) pt.aligns = ['l' for f in fields] @@ -29,7 +30,10 @@ def print_list(objs, fields, formatters={}): if field in formatters: row.append(formatters[field](o)) else: - field_name = field.lower().replace(' ', '_') + if field in mixed_case_fields: + field_name = field.replace(' ', '_') + else: + field_name = field.lower().replace(' ', '_') data = getattr(o, field_name, '') row.append(data) pt.add_row(row) diff --git a/novaclient/v1_0/shell.py b/novaclient/v1_0/shell.py index 6528c6968..51abdb1a1 100644 --- a/novaclient/v1_0/shell.py +++ b/novaclient/v1_0/shell.py @@ -350,7 +350,14 @@ def do_flavor_list(cs, args): def do_image_list(cs, args): """Print a list of available images to boot from.""" - utils.print_list(cs.images.list(), ['ID', 'Name', 'Status']) + server_list = {} + for server in cs.servers.list(): + server_list[server.id] = server.name + image_list = cs.images.list() + for i in range(len(image_list)): + if hasattr(image_list[i],'serverId'): + image_list[i].serverId = server_list[image_list[i].serverId] + ' (' + str(image_list[i].serverId) + ')' + utils.print_list(image_list, ['ID', 'Name', 'serverId','Status']) @utils.arg('server', metavar='', help='Name or ID of server.') diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index b5e770ddc..26da38390 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -281,7 +281,14 @@ def do_flavor_list(cs, args): def do_image_list(cs, args): """Print a list of available images to boot from.""" - utils.print_list(cs.images.list(), ['ID', 'Name', 'Status']) + server_list = {} + for server in cs.servers.list(): + server_list[server.id] = server.name + image_list = cs.images.list() + for i in range(len(image_list)): + if hasattr(image_list[i],'serverId'): + image_list[i].serverId = server_list[image_list[i].serverId] + ' (' + str(image_list[i].serverId) + ')' + utils.print_list(cs.images.list(), ['ID', 'Name', 'serverId', 'Status']) @utils.arg('image', From 690f3d386600d6c55607bd41b920d458da7f75ac Mon Sep 17 00:00:00 2001 From: Jason Straw Date: Thu, 3 Nov 2011 22:44:22 -0500 Subject: [PATCH 2/3] PEP8 cleanups of utils, and the v1_?/shell.py files --- novaclient/utils.py | 2 +- novaclient/v1_0/shell.py | 5 +++-- novaclient/v1_1/shell.py | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/novaclient/utils.py b/novaclient/utils.py index 834785e0b..582829d11 100644 --- a/novaclient/utils.py +++ b/novaclient/utils.py @@ -32,7 +32,7 @@ def print_list(objs, fields, formatters={}): else: if field in mixed_case_fields: field_name = field.replace(' ', '_') - else: + else: field_name = field.lower().replace(' ', '_') data = getattr(o, field_name, '') row.append(data) diff --git a/novaclient/v1_0/shell.py b/novaclient/v1_0/shell.py index 51abdb1a1..fb782d98e 100644 --- a/novaclient/v1_0/shell.py +++ b/novaclient/v1_0/shell.py @@ -355,8 +355,9 @@ def do_image_list(cs, args): server_list[server.id] = server.name image_list = cs.images.list() for i in range(len(image_list)): - if hasattr(image_list[i],'serverId'): - image_list[i].serverId = server_list[image_list[i].serverId] + ' (' + str(image_list[i].serverId) + ')' + if hasattr(image_list[i], 'serverId'): + image_list[i].serverId = server_list[image_list[i].serverId] + + ' (' + str(image_list[i].serverId) + ')' utils.print_list(image_list, ['ID', 'Name', 'serverId','Status']) diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 5ce1ca2f4..2cfb2dff1 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -286,8 +286,9 @@ def do_image_list(cs, args): server_list[server.id] = server.name image_list = cs.images.list() for i in range(len(image_list)): - if hasattr(image_list[i],'serverId'): - image_list[i].serverId = server_list[image_list[i].serverId] + ' (' + str(image_list[i].serverId) + ')' + if hasattr(image_list[i], 'serverId'): + image_list[i].serverId = server_list[image_list[i].serverId] + + ' (' + str(image_list[i].serverId) + ')' utils.print_list(cs.images.list(), ['ID', 'Name', 'serverId', 'Status']) From 36f34d998365bfdfb20dc26c890238127e1fd24d Mon Sep 17 00:00:00 2001 From: Jason Straw Date: Thu, 3 Nov 2011 23:46:08 -0500 Subject: [PATCH 3/3] fixed missing line continuation characters in shell.py updated tests to use serverId 1234 instead of 12 to allow the tests to function on new image list --- novaclient/v1_0/shell.py | 2 +- novaclient/v1_1/shell.py | 2 +- tests/v1_0/fakes.py | 2 +- tests/v1_1/fakes.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/novaclient/v1_0/shell.py b/novaclient/v1_0/shell.py index fb782d98e..c2ce60e1c 100644 --- a/novaclient/v1_0/shell.py +++ b/novaclient/v1_0/shell.py @@ -356,7 +356,7 @@ def do_image_list(cs, args): image_list = cs.images.list() for i in range(len(image_list)): if hasattr(image_list[i], 'serverId'): - image_list[i].serverId = server_list[image_list[i].serverId] + + image_list[i].serverId = server_list[image_list[i].serverId] + \ ' (' + str(image_list[i].serverId) + ')' utils.print_list(image_list, ['ID', 'Name', 'serverId','Status']) diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 2cfb2dff1..408cc43ad 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -287,7 +287,7 @@ def do_image_list(cs, args): image_list = cs.images.list() for i in range(len(image_list)): if hasattr(image_list[i], 'serverId'): - image_list[i].serverId = server_list[image_list[i].serverId] + + image_list[i].serverId = server_list[image_list[i].serverId] + \ ' (' + str(image_list[i].serverId) + ')' utils.print_list(cs.images.list(), ['ID', 'Name', 'serverId', 'Status']) diff --git a/tests/v1_0/fakes.py b/tests/v1_0/fakes.py index 7646a2d05..b79c02223 100644 --- a/tests/v1_0/fakes.py +++ b/tests/v1_0/fakes.py @@ -287,7 +287,7 @@ class FakeHTTPClient(base_client.HTTPClient): { "id": 743, "name": "My Server Backup", - "serverId": 12, + "serverId": 1234, "updated": "2010-10-10T12:00:00Z", "created": "2010-08-10T12:00:00Z", "status": "SAVING", diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py index a1554fe0d..f0d74a824 100644 --- a/tests/v1_1/fakes.py +++ b/tests/v1_1/fakes.py @@ -359,7 +359,7 @@ class FakeHTTPClient(base_client.HTTPClient): { "id": 743, "name": "My Server Backup", - "serverId": 12, + "serverId": 1234, "updated": "2010-10-10T12:00:00Z", "created": "2010-08-10T12:00:00Z", "status": "SAVING",