Cleaned up the query_string generation for 'nova list'

Made --recurse_zones not need an '=argument'.
This commit is contained in:
Chris Behrens 2011-06-23 15:07:05 -07:00
parent 5b566a0f5c
commit 9e86dd0634
2 changed files with 15 additions and 15 deletions

@ -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:

@ -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: