From 9e86dd0634db384bc495fcc323fd6db97e890a62 Mon Sep 17 00:00:00 2001 From: Chris Behrens <cbehrens@codestud.com> Date: Thu, 23 Jun 2011 15:07:05 -0700 Subject: [PATCH] Cleaned up the query_string generation for 'nova list' Made --recurse_zones not need an '=argument'. --- novaclient/servers.py | 19 ++++++++----------- novaclient/shell.py | 11 +++++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/novaclient/servers.py b/novaclient/servers.py index c1c6a7371..29a71bfdc 100644 --- a/novaclient/servers.py +++ b/novaclient/servers.py @@ -19,6 +19,7 @@ Server interface. """ +import urllib from novaclient import base REBOOT_SOFT, REBOOT_HARD = 'SOFT', 'HARD' @@ -213,21 +214,17 @@ class ServerManager(base.BootingManagerWithFind): :rtype: list of :class:`Server` """ - query_string = "" + qparams = {} if reservation_id: - # Always going to be '?' here, but added in case someone - # puts another case above this one - prefix = query_string and '&' or '?' - query_string += "sreservation_id=%s" % (prefix, reservation_id) + qparams['reservation_id'] = reservation_id if fixed_ip: - prefix = query_string and '&' or '?' - query_string += "%sfixed_ip=%s" % (prefix, fixed_ip) + qparams['fixed_ip'] = fixed_ip if project_id: - prefix = query_string and '&' or '?' - query_string += "%sproject_id=%s" % (prefix, project_id) + qparams['project_id'] = project_id if recurse_zones: - prefix = query_string and '&' or '?' - query_string += "%srecurse_zones=%s" % (prefix, recurse_zones) + qparams['recurse_zones'] = recurse_zones + + query_string = "?%s" % urllib.urlencode(qparams) if qparams else "" detail = "" if detailed: diff --git a/novaclient/shell.py b/novaclient/shell.py index 2cfb804ad..7383874fa 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -554,14 +554,17 @@ class OpenStackShell(object): help='Only return instances that match reservation_id.') @arg('--recurse_zones', dest='recurse_zones', - metavar='<recurse_zones>', - default=False, - help='Recurse through all zones if set to 1.') + metavar='<0|1>', + nargs='?', + type=int, + const=1, + default=0, + help='Recurse through all zones if set.') def do_list(self, args): """List active servers.""" reservation_id = args.reservation_id fixed_ip = args.fixed_ip - recurse_zones = args.recurse_zones and 1 or 0 + recurse_zones = args.recurse_zones if recurse_zones: to_print = ['UUID', 'Name', 'Status', 'Public IP', 'Private IP'] else: