Skip to content

Commit

Permalink
Support more console types in get_server_console
Browse files Browse the repository at this point in the history
  • Loading branch information
saxtouri committed Jul 25, 2014
1 parent fd3af02 commit 06ace38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 8 additions & 2 deletions kamaki/clients/cyclades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
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,
Expand Down Expand Up @@ -133,13 +135,17 @@ def shutdown_server(self, server_id):
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']

Expand Down
13 changes: 8 additions & 5 deletions kamaki/clients/cyclades/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ def test_start_server(self, SP):
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'
Expand Down

0 comments on commit 06ace38

Please sign in to comment.