Add all tenants search opt to del instnce by name

Nova delete command deletes an instance by name
or ID. Nova delete command is able to delete an
instance within the same the tenant by name or
ID. When admin credentials are sourced and try
to delete a non admin tenant instances, nova
delete command is able to delete an instance by
ID only, it is not able to delete an instance by
name.

Nova delete command deletes an instances by id
using following api call
/v2/{tenant_id}/servers/{server_id}
But to delete an instance by name, nova delete
command first find the resources by name using
following api call
/servers?name={server_name}
This api call is not able to retrive the list
of other tenant instances.
Adding all tenants parameter to this api call
will retrive the list of other tenant
instances. The following will be new api
call
/servers?all_tenants=1&name={server_name}

Closes-Bug: #1247030

Change-Id: I03e578d58214c835d9a411752bd618d77ced37ff
This commit is contained in:
Ritesh Paiboina 2015-02-09 07:32:36 +01:00
parent 578390ee7e
commit a0481e1c80
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):