Merge "Add all tenants search opt to del instnce by name"

This commit is contained in:
Jenkins 2015-02-10 17:29:26 +00:00 committed by Gerrit Code Review
commit 3870216567
3 changed files with 13 additions and 5 deletions

View File

@ -179,6 +179,10 @@ class ManagerWithFind(Manager):
list_kwargs['search_opts'] = {"name": kwargs["name"]}
elif "display_name" in kwargs:
list_kwargs['search_opts'] = {"name": kwargs["display_name"]}
if "all_tenants" in kwargs:
all_tenants = kwargs['all_tenants']
list_kwargs['search_opts']['all_tenants'] = all_tenants
searches = [(k, v) for k, v in searches if k != 'all_tenants']
listing = self.list(**list_kwargs)

View File

@ -1111,10 +1111,13 @@ class ShellTest(utils.TestCase):
self.assert_called('DELETE', '/servers/1234', pos=-3)
self.assert_called('DELETE', '/servers/5678', pos=-1)
self.run_command('delete sample-server sample-server2')
self.assert_called('GET', '/servers?name=sample-server', pos=-6)
self.assert_called('GET',
'/servers?all_tenants=1&name=sample-server', pos=-6)
self.assert_called('GET', '/servers/1234', pos=-5)
self.assert_called('DELETE', '/servers/1234', pos=-4)
self.assert_called('GET', '/servers?name=sample-server2', pos=-3)
self.assert_called('GET',
'/servers?all_tenants=1&name=sample-server2',
pos=-3)
self.assert_called('GET', '/servers/5678', pos=-2)
self.assert_called('DELETE', '/servers/5678', pos=-1)

View File

@ -1876,16 +1876,17 @@ def do_show(cs, args):
help=_('Name or ID of server(s).'))
def do_delete(cs, args):
"""Immediately shut down and delete specified server(s)."""
find_args = {'all_tenants': '1'}
utils.do_action_on_many(
lambda s: _find_server(cs, s).delete(),
lambda s: _find_server(cs, s, **find_args).delete(),
args.server,
_("Request to delete server %s has been accepted."),
_("Unable to delete the specified server(s)."))
def _find_server(cs, server):
def _find_server(cs, server, **find_args):
"""Get a server by name or ID."""
return utils.find_resource(cs.servers, server)
return utils.find_resource(cs.servers, server, **find_args)
def _find_image(cs, image):