Commit e19dd03a authored by Stavros Sachtouris's avatar Stavros Sachtouris

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):
self._run(server_id=server_id)
_basic_cons = CycladesComputeClient.CONSOLE_TYPES
class ConsoleTypeArgument(ValueArgument):
TRANSLATE = {'no-vnc': 'vnc-ws', 'no-vnc-encrypted': 'vnc-wss'}
@property
def value(self):
return getattr(self, '_value', None)
@value.setter
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
else:
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()]
@command(server_cmds)
......@@ -860,8 +874,7 @@ class server_console(_CycladesInit, OptionalOutput):
arguments = dict(
console_type=ConsoleTypeArgument(
'Valid values: %s Default: %s' % (
', '.join(CycladesComputeClient.CONSOLE_TYPES),
CycladesComputeClient.CONSOLE_TYPES[0]),
', '.join(VALID_CONSOLE_TYPES), VALID_CONSOLE_TYPES[0]),
'--type'),
)
......@@ -870,7 +883,7 @@ class server_console(_CycladesInit, OptionalOutput):
@errors.Cyclades.server_id
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.print_(
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