Commit 03cc64ad authored by Stavros Sachtouris's avatar Stavros Sachtouris

Support more console types in get_server_console

Refs #36

New types: vnc-ws, vnc-wss
parent 26e46754
......@@ -41,6 +41,8 @@ from kamaki.clients import ClientError, Waiter
class CycladesComputeClient(CycladesComputeRestClient, Waiter):
"""Synnefo Cyclades Compute API client"""
CONSOLE_TYPES = ('vnc', 'vnc-ws', 'vnc-wss')
def create_server(
self, name, flavor_id, image_id,
metadata=None, personality=None, networks=None, project_id=None,
......@@ -133,13 +135,17 @@ class CycladesComputeClient(CycladesComputeRestClient, Waiter):
r = self.servers_action_post(server_id, json_data=req, success=202)
return r.headers
def get_server_console(self, server_id):
def get_server_console(self, server_id, console_type='vnc'):
"""
:param server_id: integer (str or int)
:param console_type: str (vnc, vnc-ws, vnc-wss, default: vnc)
:returns: (dict) info to set a VNC connection to virtual server
"""
req = {'console': {'type': 'vnc'}}
ct = self.CONSOLE_TYPES
assert console_type in ct, '%s not in %s' % (console_type, ct)
req = {'console': {'type': console_type}}
r = self.servers_action_post(server_id, json_data=req, success=200)
return r.json['console']
......
......@@ -229,11 +229,14 @@ class CycladesComputeClient(TestCase):
def test_get_server_console(self, SP):
cnsl = dict(console=dict(info1='i1', info2='i2', info3='i3'))
FR.json = cnsl
vm_id = vm_recv['server']['id']
r = self.client.get_server_console(vm_id)
SP.assert_called_once_with(
vm_id, json_data=dict(console=dict(type='vnc')), success=200)
self.assert_dicts_are_equal(r, cnsl['console'])
vm_id, foo = vm_recv['server']['id'], self.client.get_server_console
self.assertRaises(AssertionError, foo, vm_id, None)
self.assertRaises(AssertionError, foo, vm_id, 'Invalid console type')
for ctype in self.client.CONSOLE_TYPES:
r = foo(vm_id, ctype)
self.assertEqual(SP.mock_calls[-1], call(
vm_id, json_data=dict(console=dict(type=ctype)), success=200))
self.assert_dicts_are_equal(r, cnsl['console'])
clients_pkg = 'kamaki.clients.Client'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment