diff --git a/novaclient/servers.py b/novaclient/servers.py index ce802eb9c..bb48c8b43 100644 --- a/novaclient/servers.py +++ b/novaclient/servers.py @@ -210,8 +210,7 @@ class ServerManager(base.BootingManagerWithFind): """ return self._get("/servers/%s" % base.getid(server), "server") - def list(self, detailed=True, fixed_ip=None, project_id=None, - reservation_id=None, recurse_zones=None): + def list(self, detailed=True, search_opts=None): """ Get a list of servers. Optional detailed returns details server info. @@ -220,15 +219,13 @@ class ServerManager(base.BootingManagerWithFind): :rtype: list of :class:`Server` """ + if search_opts is None: + search_opts = {} qparams = {} - if reservation_id: - qparams['reservation_id'] = reservation_id - if fixed_ip: - qparams['fixed_ip'] = fixed_ip - if project_id: - qparams['project_id'] = project_id - if recurse_zones: - qparams['recurse_zones'] = recurse_zones + # only use values in query string if they are set + for opt, val in search_opts.iteritems(): + if val: + qparams[opt] = val query_string = "?%s" % urllib.urlencode(qparams) if qparams else "" diff --git a/novaclient/shell.py b/novaclient/shell.py index b04a5b14f..2e1cd9ddf 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -582,18 +582,49 @@ class OpenStackShell(object): const=1, default=0, help='Recurse through all zones if set.') + @arg('--ip', + dest='ip', + metavar='<ip_regexp>', + default=None, + help='Search with regular expression match by IP address') + @arg('--ip6', + dest='ip6', + metavar='<ip6_regexp>', + default=None, + help='Search with regular expression match by IPv6 address') + @arg('--server_name', + dest='server_name', + metavar='<name_regexp>', + default=None, + help='Search with regular expression match by server name') + @arg('--name', + dest='display_name', + metavar='<name_regexp>', + default=None, + help='Search with regular expression match by display name') + @arg('--instance_name', + dest='name', + metavar='<name_regexp>', + default=None, + help='Search with regular expression match by instance name') def do_list(self, args): """List active servers.""" - reservation_id = args.reservation_id - fixed_ip = args.fixed_ip recurse_zones = args.recurse_zones + search_opts = { + 'reservation_id': args.reservation_id, + 'fixed_ip': args.fixed_ip, + 'recurse_zones': recurse_zones, + 'ip': args.ip, + 'ip6': args.ip6, + 'name': args.name, + 'server_name': args.server_name, + 'display_name': args.display_name} if recurse_zones: to_print = ['UUID', 'Name', 'Status', 'Public IP', 'Private IP'] else: to_print = ['ID', 'Name', 'Status', 'Public IP', 'Private IP'] - print_list(self.cs.servers.list(fixed_ip=fixed_ip, - reservation_id=reservation_id, - recurse_zones=recurse_zones), to_print) + print_list(self.cs.servers.list(search_opts=search_opts), + to_print) @arg('--hard', dest='reboot_type',