Add suport for instance locking/unlocking.

* Fixes bug 954746

Change-Id: I055597014fd44313780b8a9f10cdbc94196f8efb
This commit is contained in:
Anthony Young 2012-03-13 23:18:41 -07:00
parent 24b9e8055c
commit f90aa8c91a
5 changed files with 56 additions and 0 deletions

View File

@ -124,6 +124,7 @@ You'll find complete documentation on the shell by running
keypair-delete Delete keypair by its id
keypair-list Show a list of keypairs for a user
list List active servers.
lock Lock a server
migrate Migrate a server to a new host.
reboot Reboot a server.
rebuild Shutdown, re-image, and re-boot a server.
@ -149,6 +150,7 @@ You'll find complete documentation on the shell by running
secgroup-list-rules List rules for a security group.
show Show details about the given server.
suspend Suspend a server.
unlock Unlock a server.
unpause Unpause a server.
unrescue Unrescue a server.
usage-list List usage data for all tenants

View File

@ -101,6 +101,18 @@ class Server(base.Resource):
"""
self.manager.unpause(self)
def lock(self):
"""
Lock -- Lock the instance from certain operations.
"""
self.manager.lock(self)
def unlock(self):
"""
Unlock -- Remove instance lock.
"""
self.manager.unlock(self)
def suspend(self):
"""
Suspend -- Suspend the running server.
@ -329,6 +341,18 @@ class ServerManager(local_base.BootingManagerWithFind):
"""
self._action('unpause', server, None)
def lock(self, server):
"""
Lock the server.
"""
self._action('lock', server, None)
def unlock(self, server):
"""
Unlock the server.
"""
self._action('unlock', server, None)
def suspend(self, server):
"""
Suspend the server.

View File

@ -624,6 +624,18 @@ def do_unpause(cs, args):
_find_server(cs, args.server).unpause()
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
def do_lock(cs, args):
"""Lock a server."""
_find_server(cs, args.server).lock()
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
def do_unlock(cs, args):
"""Unlock a server."""
_find_server(cs, args.server).unlock()
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
def do_suspend(cs, args):
"""Suspend a server."""

View File

@ -309,6 +309,10 @@ class FakeHTTPClient(base_client.HTTPClient):
assert body[action] is None
elif action == 'unrescue':
assert body[action] is None
elif action == 'lock':
assert body[action] is None
elif action == 'unlock':
assert body[action] is None
elif action == 'addFixedIp':
assert body[action].keys() == ['networkId']
elif action == 'removeFixedIp':

View File

@ -201,6 +201,20 @@ class ServersTest(utils.TestCase):
cs.servers.unrescue(s)
cs.assert_called('POST', '/servers/1234/action')
def test_lock(self):
s = cs.servers.get(1234)
s.lock()
cs.assert_called('POST', '/servers/1234/action')
cs.servers.lock(s)
cs.assert_called('POST', '/servers/1234/action')
def test_unlock(self):
s = cs.servers.get(1234)
s.unlock()
cs.assert_called('POST', '/servers/1234/action')
cs.servers.unlock(s)
cs.assert_called('POST', '/servers/1234/action')
def test_get_console_output_without_length(self):
success = 'foo'
s = cs.servers.get(1234)