compute: Add '--force' option to 'server delete'
This is an admin-only operation by default but can be useful. Change-Id: I25a4da697e27c0fba4d28b504377667eb18f15fe Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
parent
262e525aad
commit
8a164bb09c
@ -1317,6 +1317,11 @@ class DeleteServer(command.Command):
|
||||
nargs="+",
|
||||
help=_('Server(s) to delete (name or ID)'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--force',
|
||||
action='store_true',
|
||||
help=_('Force delete server(s)'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'--wait',
|
||||
action='store_true',
|
||||
@ -1335,7 +1340,12 @@ class DeleteServer(command.Command):
|
||||
for server in parsed_args.server:
|
||||
server_obj = utils.find_resource(
|
||||
compute_client.servers, server)
|
||||
compute_client.servers.delete(server_obj.id)
|
||||
|
||||
if parsed_args.force:
|
||||
compute_client.servers.force_delete(server_obj.id)
|
||||
else:
|
||||
compute_client.servers.delete(server_obj.id)
|
||||
|
||||
if parsed_args.wait:
|
||||
if not utils.wait_for_delete(compute_client.servers,
|
||||
server_obj.id,
|
||||
|
@ -2850,6 +2850,7 @@ class TestServerDelete(TestServer):
|
||||
super(TestServerDelete, self).setUp()
|
||||
|
||||
self.servers_mock.delete.return_value = None
|
||||
self.servers_mock.force_delete.return_value = None
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = server.DeleteServer(self.app, None)
|
||||
@ -2868,6 +2869,26 @@ class TestServerDelete(TestServer):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.servers_mock.delete.assert_called_with(servers[0].id)
|
||||
self.servers_mock.force_delete.assert_not_called()
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_server_delete_with_force(self):
|
||||
servers = self.setup_servers_mock(count=1)
|
||||
|
||||
arglist = [
|
||||
servers[0].id,
|
||||
'--force',
|
||||
]
|
||||
verifylist = [
|
||||
('server', [servers[0].id]),
|
||||
('force', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.servers_mock.force_delete.assert_called_with(servers[0].id)
|
||||
self.servers_mock.delete.assert_not_called()
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_server_delete_multi_servers(self):
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Add ``--force`` option to ``server delete`` command, allowing users to
|
||||
force delete a server. This is admin-only by default.
|
Loading…
Reference in New Issue
Block a user