Enable force_delete and restore instance via novaclient.
Bug 1195670 Nova supports force_delete or restore instance in the API level, thus it makes sense to support this feature in novaclient. Change-Id: I7cc3d2d2a7ab8dfe043176a3ea97c10deae683c9
This commit is contained in:
parent
f702c25d43
commit
cc2c0a8e6f
@ -489,6 +489,10 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
assert body[action] is None
|
||||
elif action == 'os-start':
|
||||
assert body[action] is None
|
||||
elif action == 'forceDelete':
|
||||
assert body[action] is None
|
||||
elif action == 'restore':
|
||||
assert body[action] is None
|
||||
elif action == 'pause':
|
||||
assert body[action] is None
|
||||
elif action == 'unpause':
|
||||
|
@ -284,6 +284,20 @@ class ServersTest(utils.TestCase):
|
||||
cs.servers.stop(s)
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
|
||||
def test_force_delete(self):
|
||||
s = cs.servers.get(1234)
|
||||
s.force_delete()
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
cs.servers.force_delete(s)
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
|
||||
def test_restore(self):
|
||||
s = cs.servers.get(1234)
|
||||
s.restore()
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
cs.servers.restore(s)
|
||||
cs.assert_called('POST', '/servers/1234/action')
|
||||
|
||||
def test_start(self):
|
||||
s = cs.servers.get(1234)
|
||||
s.start()
|
||||
|
@ -650,6 +650,20 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command('delete sample-server')
|
||||
self.assert_called('DELETE', '/servers/1234')
|
||||
|
||||
def test_force_delete(self):
|
||||
self.run_command('force-delete 1234')
|
||||
self.assert_called('POST', '/servers/1234/action',
|
||||
{'forceDelete': None})
|
||||
self.run_command('force-delete sample-server')
|
||||
self.assert_called('POST', '/servers/1234/action',
|
||||
{'forceDelete': None})
|
||||
|
||||
def test_restore(self):
|
||||
self.run_command('restore 1234')
|
||||
self.assert_called('POST', '/servers/1234/action', {'restore': None})
|
||||
self.run_command('restore sample-server')
|
||||
self.assert_called('POST', '/servers/1234/action', {'restore': None})
|
||||
|
||||
def test_delete_two_with_two_existent(self):
|
||||
self.run_command('delete 1234 5678')
|
||||
self.assert_called('DELETE', '/servers/1234', pos=-3)
|
||||
|
27
novaclient/v1_1/contrib/deferred_delete.py
Normal file
27
novaclient/v1_1/contrib/deferred_delete.py
Normal file
@ -0,0 +1,27 @@
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from novaclient import utils
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
def do_force_delete(cs, args):
|
||||
"""Force delete a server."""
|
||||
utils.find_resource(cs.servers, args.server).force_delete()
|
||||
|
||||
|
||||
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
|
||||
def do_restore(cs, args):
|
||||
"""Restore a soft-deleted server."""
|
||||
utils.find_resource(cs.servers, args.server).restore()
|
@ -123,6 +123,18 @@ class Server(base.Resource):
|
||||
"""
|
||||
self.manager.stop(self)
|
||||
|
||||
def force_delete(self):
|
||||
"""
|
||||
Force delete -- Force delete a server.
|
||||
"""
|
||||
self.manager.force_delete(self)
|
||||
|
||||
def restore(self):
|
||||
"""
|
||||
Restore -- Restore a server in 'soft-deleted' state.
|
||||
"""
|
||||
self.manager.restore(self)
|
||||
|
||||
def start(self):
|
||||
"""
|
||||
Start -- Start the paused server.
|
||||
@ -483,6 +495,18 @@ class ServerManager(local_base.BootingManagerWithFind):
|
||||
"""
|
||||
return self._action('os-stop', server, None)
|
||||
|
||||
def force_delete(self, server):
|
||||
"""
|
||||
Force delete the server.
|
||||
"""
|
||||
return self._action('forceDelete', server, None)
|
||||
|
||||
def restore(self, server):
|
||||
"""
|
||||
Restore soft-deleted server.
|
||||
"""
|
||||
return self._action('restore', server, None)
|
||||
|
||||
def start(self, server):
|
||||
"""
|
||||
Start the server.
|
||||
|
Loading…
Reference in New Issue
Block a user