diff --git a/README.rst b/README.rst index 0fd35fc33..c0416d2a4 100644 --- a/README.rst +++ b/README.rst @@ -119,6 +119,7 @@ You'll find complete documentation on the shell by running floating-ip-pool-list List all floating ip pools. get-vnc-console Get a vnc console to a server. + get-spice-console Get a spice console to a server. host-action Perform a power action on a host. host-update Update host settings. image-create Create a new image by taking a snapshot of a running diff --git a/novaclient/v1_1/servers.py b/novaclient/v1_1/servers.py index c93bdf78c..9a9bb1ec1 100644 --- a/novaclient/v1_1/servers.py +++ b/novaclient/v1_1/servers.py @@ -66,6 +66,14 @@ class Server(base.Resource): """ return self.manager.get_vnc_console(self, console_type) + def get_spice_console(self, console_type): + """ + Get spice console for a Server. + + :param console_type: Type of console ('spice-html5') + """ + return self.manager.get_spice_console(self, console_type) + def get_password(self, private_key): """ Get password for a Server. @@ -397,6 +405,17 @@ class ServerManager(local_base.BootingManagerWithFind): return self._action('os-getVNCConsole', server, {'type': console_type})[1] + def get_spice_console(self, server, console_type): + """ + Get a spice console for an instance + + :param server: The :class:`Server` (or its ID) to add an IP to. + :param console_type: Type of spice console to get ('spice-html5') + """ + + return self._action('os-getSPICEConsole', server, + {'type': console_type})[1] + def get_password(self, server, private_key): """ Get password for an instance diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 8c5d55945..92b77f883 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -1512,6 +1512,23 @@ def do_get_vnc_console(cs, args): utils.print_list([VNCConsole(data['console'])], ['Type', 'Url']) +@utils.arg('server', metavar='<server>', help='Name or ID of server.') +@utils.arg('console_type', + metavar='<console-type>', + help='Type of spice console ("spice-html5").') +def do_get_spice_console(cs, args): + """Get a spice console to a server.""" + server = _find_server(cs, args.server) + data = server.get_spice_console(args.console_type) + + class SPICEConsole: + def __init__(self, console_dict): + self.type = console_dict['type'] + self.url = console_dict['url'] + + utils.print_list([SPICEConsole(data['console'])], ['Type', 'Url']) + + @utils.arg('server', metavar='<server>', help='Name or ID of server.') @utils.arg('private_key', metavar='<private-key>', diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py index 795ceec18..36aafca31 100644 --- a/tests/v1_1/fakes.py +++ b/tests/v1_1/fakes.py @@ -479,6 +479,8 @@ class FakeHTTPClient(base_client.HTTPClient): return (202, {}, {'output': 'foo'}) elif action == 'os-getVNCConsole': assert body[action].keys() == ['type'] + elif action == 'os-getSPICEConsole': + assert body[action].keys() == ['type'] elif action == 'os-migrateLive': assert set(body[action].keys()) == set(['host', 'block_migration', diff --git a/tests/v1_1/test_servers.py b/tests/v1_1/test_servers.py index 1caaa422f..82a09d35f 100644 --- a/tests/v1_1/test_servers.py +++ b/tests/v1_1/test_servers.py @@ -370,6 +370,14 @@ class ServersTest(utils.TestCase): cs.servers.get_vnc_console(s, 'fake') cs.assert_called('POST', '/servers/1234/action') + def test_get_spice_console(self): + s = cs.servers.get(1234) + s.get_spice_console('fake') + cs.assert_called('POST', '/servers/1234/action') + + cs.servers.get_spice_console(s, 'fake') + cs.assert_called('POST', '/servers/1234/action') + def test_create_image(self): s = cs.servers.get(1234) s.create_image('123')