summaryrefslogtreecommitdiff
path: root/novaclient
diff options
context:
space:
mode:
authorRitesh Paiboina <rsritesh@rediff.com>2015-02-09 07:32:36 +0100
committerRitesh Paiboina <rsritesh@rediff.com>2015-02-10 06:03:09 +0100
commita0481e1c8008935d34e8f6e2cf896723b5e36f0a (patch)
tree8fd70a90e7c090e623b8a7a478daee6140dd4c6f /novaclient
parent578390ee7e74c0998b9590f0327449ae19a5c8f0 (diff)
downloadpython-novaclient-a0481e1c8008935d34e8f6e2cf896723b5e36f0a.tar.gz
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
Diffstat (limited to 'novaclient')
-rw-r--r--novaclient/base.py4
-rw-r--r--novaclient/tests/unit/v2/test_shell.py7
-rw-r--r--novaclient/v2/shell.py7
3 files changed, 13 insertions, 5 deletions
diff --git a/novaclient/base.py b/novaclient/base.py
index 7f54d936..731d220e 100644
--- a/novaclient/base.py
+++ b/novaclient/base.py
@@ -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)
diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py
index ffa3587d..fb8dac8f 100644
--- a/novaclient/tests/unit/v2/test_shell.py
+++ b/novaclient/tests/unit/v2/test_shell.py
@@ -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)
diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py
index 190d07fe..29f26693 100644
--- a/novaclient/v2/shell.py
+++ b/novaclient/v2/shell.py
@@ -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):