Correct key names in network-related http bodies
[kamaki] / kamaki / cli / commands / cyclades.py
index e434d78..1849fc1 100644 (file)
@@ -109,23 +109,6 @@ class _server_wait(_service_wait):
             timeout=timeout if current_status not in ('BUILD', ) else 100)
 
 
-class _network_wait(_service_wait):
-
-    def _wait(self, net_id, current_status, timeout=60):
-        super(_network_wait, self)._wait(
-            'Network', net_id, self.client.wait_network, current_status,
-            timeout=timeout)
-
-
-class _firewall_wait(_service_wait):
-
-    def _wait(self, server_id, current_status, timeout=60):
-        super(_firewall_wait, self)._wait(
-            'Firewall of server',
-            server_id, self.client.wait_firewall, current_status,
-            timeout=timeout)
-
-
 class _init_cyclades(_command_init):
     @errors.generic.all
     @addLogSettings
@@ -278,26 +261,49 @@ class server_list(_init_cyclades, _optional_json, _name_filter, _id_filter):
 
 @command(server_cmds)
 class server_info(_init_cyclades, _optional_json):
-    """Detailed information on a Virtual Machine
-    Contains:
-    - name, id, status, create/update dates
-    - network interfaces
-    - metadata (e.g., os, superuser) and diagnostics
-    - hardware flavor and os image ids
-    """
+    """Detailed information on a Virtual Machine"""
+
+    arguments = dict(
+        addr=FlagArgument(
+            'Show only the network interfaces of this virtual server',
+            '--nics'),
+        vnc=FlagArgument(
+            'Show VNC connection information (valid for a short period)',
+            '--vnc-credentials'),
+        stats=FlagArgument('Get URLs for server statistics', '--stats')
+    )
 
     @errors.generic.all
     @errors.cyclades.connection
     @errors.cyclades.server_id
     def _run(self, server_id):
         vm = self.client.get_server_details(server_id)
-        uuids = self._uuids2usernames([vm['user_id'], vm['tenant_id']])
-        vm['user_id'] += ' (%s)' % uuids[vm['user_id']]
-        vm['tenant_id'] += ' (%s)' % uuids[vm['tenant_id']]
-        self._print(vm, self.print_dict)
+        if self['addr']:
+            self._print(vm.get('attachments', []))
+        elif self['vnc']:
+            self.error(
+                '(!) For security reasons, the following credentials are '
+                'invalidated\nafter a short time period, depending on the '
+                'server settings\n')
+            self._print(
+                self.client.get_server_console(server_id), self.print_dict)
+        elif self['stats']:
+            self._print(
+                self.client.get_server_stats(server_id), self.print_dict)
+        else:
+            uuids = self._uuids2usernames([vm['user_id'], vm['tenant_id']])
+            vm['user_id'] += ' (%s)' % uuids[vm['user_id']]
+            vm['tenant_id'] += ' (%s)' % uuids[vm['tenant_id']]
+            self._print(vm, self.print_dict)
 
     def main(self, server_id):
         super(self.__class__, self)._run()
+        choose_one = ('addr', 'vnc', 'stats')
+        count = len([a for a in choose_one if self[a]])
+        if count > 1:
+            raise CLIInvalidArgument('Invalid argument compination', details=[
+                'Arguments %s cannot be used simultaneously' % ', '.join(
+                    [self.arguments[a].lvalue for a in choose_one])])
         self._run(server_id=server_id)
 
 
@@ -386,7 +392,7 @@ class NetworkIpArgument(RepeatableArgument):
                         self.parsed_name[0])])
             self._value = getattr(self, '_value', list())
             self._value.append(
-                dict(network=net_and_ip[0], fixed_ip=net_and_ip[1]))
+                dict(uuid=net_and_ip[0], fixed_ip=net_and_ip[1]))
 
 
 @command(server_cmds)
@@ -423,7 +429,7 @@ class server_create(_init_cyclades, _optional_json, _server_wait):
         if self['automatic_ip']:
             networks = []
         else:
-            networks = [dict(network=netid) for netid in (
+            networks = [dict(uuid=netid) for netid in (
                 (self['network_id'] or []) + (self['network_id_and_ip'] or [])
             )] or None
         servers = [dict(
@@ -545,7 +551,7 @@ class server_modify(_init_cyclades, _optional_output_cmd):
         if self['metadata_to_set']:
             self.client.update_server_metadata(
                 server_id, **self['metadata_to_set'])
-        for key in self['metadata_to_delete']:
+        for key in (self['metadata_to_delete'] or []):
             errors.cyclades.metadata(
                 self.client.delete_server_metadata)(server_id, key=key)
         if self['with_output']:
@@ -701,60 +707,43 @@ class server_shutdown(_init_cyclades, _optional_output_cmd, _server_wait):
 
 
 @command(server_cmds)
-class server_console(_init_cyclades, _optional_json):
-    """Get a VNC console to access an existing virtual server
-    Console connection information provided (at least):
-    - host: (url or address) a VNC host
-    - port: (int) the gateway to enter virtual server on host
-    - password: for VNC authorization
-    """
+class server_addr(_init_cyclades):
+    """DEPRECATED, use: [kamaki] server info SERVER_ID --nics"""
 
-    @errors.generic.all
-    @errors.cyclades.connection
-    @errors.cyclades.server_id
-    def _run(self, server_id):
-        self._print(
-            self.client.get_server_console(int(server_id)), self.print_dict)
-
-    def main(self, server_id):
-        super(self.__class__, self)._run()
-        self._run(server_id=server_id)
+    def main(self, *args):
+        raiseCLIError('DEPRECATED since v0.12', importance=3, details=[
+            'Replaced by',
+            '  [kamaki] server info <SERVER_ID> --nics'])
 
 
 @command(server_cmds)
-class server_addr(_init_cyclades, _optional_json):
-    """List the addresses of all network interfaces on a virtual server"""
+class server_console(_init_cyclades, _optional_json):
+    """DEPRECATED, use: [kamaki] server info SERVER_ID --vnc-credentials"""
 
-    arguments = dict(
-        enum=FlagArgument('Enumerate results', '--enumerate')
-    )
+    def main(self, *args):
+        raiseCLIError('DEPRECATED since v0.12', importance=3, details=[
+            'Replaced by',
+            '  [kamaki] server info <SERVER_ID> --vnc-credentials'])
 
-    @errors.generic.all
-    @errors.cyclades.connection
-    @errors.cyclades.server_id
-    def _run(self, server_id):
-        reply = self.client.list_server_nics(int(server_id))
-        self._print(reply, with_enumeration=self['enum'] and (reply) > 1)
 
-    def main(self, server_id):
-        super(self.__class__, self)._run()
-        self._run(server_id=server_id)
+@command(server_cmds)
+class server_rename(_init_cyclades, _optional_json):
+    """DEPRECATED, use: [kamaki] server modify SERVER_ID --name=NEW_NAME"""
+
+    def main(self, *args):
+        raiseCLIError('DEPRECATED since v0.12', importance=3, details=[
+            'Replaced by',
+            '  [kamaki] server info <SERVER_ID> --stats'])
 
 
 @command(server_cmds)
 class server_stats(_init_cyclades, _optional_json):
-    """Get virtual server statistics"""
+    """DEPRECATED, use: [kamaki] server info SERVER_ID --stats"""
 
-    @errors.generic.all
-    @errors.cyclades.connection
-    @errors.cyclades.server_id
-    def _run(self, server_id):
-        self._print(
-            self.client.get_server_stats(int(server_id)), self.print_dict)
-
-    def main(self, server_id):
-        super(self.__class__, self)._run()
-        self._run(server_id=server_id)
+    def main(self, *args):
+        raiseCLIError('DEPRECATED since v0.12', importance=3, details=[
+            'Replaced by',
+            '  [kamaki] server info <SERVER_ID> --stats'])
 
 
 @command(server_cmds)
@@ -877,30 +866,3 @@ def _add_name(self, net):
                 net['user_id'] += ' (%s)' % usernames[user_id]
             if tenant_id:
                 net['tenant_id'] += ' (%s)' % usernames[tenant_id]
-
-
-@command(network_cmds)
-class network_wait(_init_cyclades, _network_wait):
-    """Wait for server to finish [PENDING, ACTIVE, DELETED]"""
-
-    arguments = dict(
-        timeout=IntArgument(
-            'Wait limit in seconds (default: 60)', '--timeout', default=60)
-    )
-
-    @errors.generic.all
-    @errors.cyclades.connection
-    @errors.cyclades.network_id
-    def _run(self, network_id, current_status):
-        net = self.client.get_network_details(network_id)
-        if net['status'].lower() == current_status.lower():
-            self._wait(network_id, current_status, timeout=self['timeout'])
-        else:
-            self.error(
-                'Network %s: Cannot wait for status %s, '
-                'status is already %s' % (
-                    network_id, current_status, net['status']))
-
-    def main(self, network_id, current_status='PENDING'):
-        super(self.__class__, self)._run()
-        self._run(network_id=network_id, current_status=current_status)