Add start and stop to server actions

Change-Id: I7fc52a87519813e38090f05dd9646b800c5c1813
This commit is contained in:
Vishvananda Ishaya 2012-06-01 01:39:20 +00:00
parent 10a9cb22bd
commit 5c5b098f7c
5 changed files with 56 additions and 0 deletions

View File

@ -166,6 +166,8 @@ You'll find complete documentation on the shell by running
List rules for a security group.
show Show details about the given server.
ssh SSH into a server.
start Start a server.
stop Stop a server.
suspend Suspend a server.
unlock Unlock a server.
unpause Unpause a server.

View File

@ -89,6 +89,18 @@ class Server(base.Resource):
"""
self.manager.remove_floating_ip(self, address)
def stop(self):
"""
Stop -- Stop the running server.
"""
self.manager.stop(self)
def start(self):
"""
Start -- Start the paused server.
"""
self.manager.start(self)
def pause(self):
"""
Pause -- Pause the running server.
@ -329,6 +341,18 @@ class ServerManager(local_base.BootingManagerWithFind):
return self._action('os-getVNCConsole', server,
{'type': console_type})[1]
def stop(self, server):
"""
Stop the server.
"""
return self._action('os-stop', server, None)
def start(self, server):
"""
Start the server.
"""
self._action('os-start', server, None)
def pause(self, server):
"""
Pause the server.

View File

@ -637,6 +637,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_stop(cs, args):
"""Stop a server."""
_find_server(cs, args.server).stop()
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
def do_start(cs, args):
"""Start a server."""
_find_server(cs, args.server).start()
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
def do_lock(cs, args):
"""Lock a server."""

View File

@ -305,6 +305,10 @@ class FakeHTTPClient(base_client.HTTPClient):
assert body[action] is None
elif action == 'migrate':
assert body[action] is None
elif action == 'os-stop':
assert body[action] is None
elif action == 'os-start':
assert body[action] is None
elif action == 'rescue':
assert body[action] is None
elif action == 'unrescue':

View File

@ -188,6 +188,20 @@ class ServersTest(utils.TestCase):
s.remove_floating_ip(f)
cs.assert_called('POST', '/servers/1234/action')
def test_stop(self):
s = cs.servers.get(1234)
s.stop()
cs.assert_called('POST', '/servers/1234/action')
cs.servers.stop(s)
cs.assert_called('POST', '/servers/1234/action')
def test_start(self):
s = cs.servers.get(1234)
s.start()
cs.assert_called('POST', '/servers/1234/action')
cs.servers.start(s)
cs.assert_called('POST', '/servers/1234/action')
def test_rescue(self):
s = cs.servers.get(1234)
s.rescue()