Commit e19dd03a authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Translate no-vnc console types from CLI to API

Fixes #36

The terms "no-vnc" and "no-vnc-encrypted" are expected to be easily
understood by users, while the equivalent terms vnc-ws and vnc-wss
(respectively) are used in Compute API. Kamaki CLI will now
accept both terms by internally translating the former to the later.
parent bb97ec22
......@@ -834,23 +834,37 @@ class server_shutdown(_CycladesInit, _ServerWait):
_basic_cons = CycladesComputeClient.CONSOLE_TYPES
class ConsoleTypeArgument(ValueArgument):
TRANSLATE = {'no-vnc': 'vnc-ws', 'no-vnc-encrypted': 'vnc-wss'}
def value(self):
return getattr(self, '_value', None)
def value(self, new_value):
global _basic_cons
if new_value:
v = new_value.lower()
if v in CycladesComputeClient.CONSOLE_TYPES:
v = self.TRANSLATE.get(v, v)
if v in _basic_cons:
self._value = v
ctypes = set(_basic_cons).difference(self.TRANSLATE.values())
ctypes = list(ctypes) + [
'%s (aka %s)' % (a, t) for t, a in self.TRANSLATE.items()]
raise CLIInvalidArgument(
'Invalid console type %s' % new_value, details=[
'Valid console types: %s' % (
', '.join(CycladesComputeClient.CONSOLE_TYPES)), ])
'Valid console types: %s' % (', '.join(ctypes)), ])
_translated = ConsoleTypeArgument.TRANSLATE
VALID_CONSOLE_TYPES = list(set(_basic_cons).difference(_translated.values()))
VALID_CONSOLE_TYPES += ['%s (aka %s)' % (a, t) for t, a in _translated.items()]
......@@ -860,8 +874,7 @@ class server_console(_CycladesInit, OptionalOutput):
arguments = dict(
'Valid values: %s Default: %s' % (
', '.join(CycladesComputeClient.CONSOLE_TYPES),
......@@ -870,7 +883,7 @@ class server_console(_CycladesInit, OptionalOutput):
def _run(self, server_id):
self.error('The following credentials will be invalidated shortly')
ctype = self['console_type'] or CycladesComputeClient.CONSOLE_TYPES[0]
ctype = self['console_type'] or VALID_CONSOLE_TYPES[0]
self.client.get_server_console(server_id, ctype), self.print_dict)
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