Revision 0e27687b

b/kamaki/cli/commands/errors.py
246 246
        def _raise(self, *args, **kwargs):
247 247
            network_type = kwargs.get('network_type', None)
248 248
            msg = 'Invalid network type %s.\nValid types: %s' % (
249
                network_type, ' , '.join(this.net_types))
249
                network_type, ' '.join(this.net_types))
250 250
            assert network_type in this.net_types, msg
251 251
            return foo(self, *args, **kwargs)
252 252
        return _raise
b/kamaki/cli/commands/network.py
36 36

  
37 37
from kamaki.cli import command
38 38
from kamaki.cli.command_tree import CommandTree
39
from kamaki.cli.errors import (
40
    CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument)
39
from kamaki.cli.errors import CLISyntaxError, CLIBaseUrlError
41 40
from kamaki.clients.cyclades import CycladesNetworkClient
42 41
from kamaki.cli.argument import FlagArgument, ValueArgument
43 42
from kamaki.cli.commands import _command_init, errors, addLogSettings
......
101 100
    @errors.generic.all
102 101
    @errors.cyclades.connection
103 102
    def _run(self):
104
        nets = self.client.list_networks()
103
        nets = self.client.list_networks(detail=self['detail'])
105 104
        nets = self._filter_by_name(nets)
106 105
        nets = self._filter_by_id(nets)
107
        if not self['detail']:
108
            nets = [dict(id=net['id'], name=net['name']) for net in nets]
109 106
        kwargs = dict()
110 107
        if self['more']:
111 108
            kwargs['out'] = StringIO()
......
138 135
@command(network_cmds)
139 136
class network_create(_init_network, _optional_json):
140 137
    """Create a new network
141
    Valid network types: CUSTOM, MAC_FILTERED, IP_LESS_ROUTED, PHYSICAL_VLAN
138
    Valid network types: CUSTOM MAC_FILTERED IP_LESS_ROUTED PHYSICAL_VLAN
142 139
    """
143 140

  
144 141
    arguments = dict(
b/kamaki/clients/cyclades/__init__.py
35 35

  
36 36
from kamaki.clients.cyclades.rest_api import CycladesRestClient
37 37
from kamaki.clients.network import NetworkClient
38
from kamaki.clients.utils import path4url
38 39
from kamaki.clients import ClientError
39 40

  
40 41

  
......
511 512
    network_types = (
512 513
        'CUSTOM', 'MAC_FILTERED', 'IP_LESS_ROUTED', 'PHYSICAL_VLAN')
513 514

  
515
    def list_networks(self, detail=None):
516
        path = path4url('networks', 'detail' if detail else '')
517
        r = self.get(path, success=200)
518
        return r.json['networks']
519

  
514 520
    def create_network(self, type, name=None, shared=None):
515 521
        req = dict(network=dict(type=type, admin_state_up=True))
516 522
        if name:
b/kamaki/clients/cyclades/test.py
251 251
        FR.json = vm_recv
252 252
        del self.client
253 253

  
254
    @patch('kamaki.clients.Client.get', return_value=FR)
255
    def test_list_networks(self, get):
256
        FR.json = dict(networks='ret val')
257
        for detail in (True, None):
258
            self.assertEqual(self.client.list_networks(detail), 'ret val')
259
            path = '/networks/detail' if detail else '/networks'
260
            self.assertEqual(get.mock_calls[-1], call(path, success=200))
261

  
254 262
    @patch(
255
        'kamaki.clients.network.NetworkClient.networks_post',
263
        'kamaki.clients.network.rest_api.NetworkRestClient.networks_post',
256 264
        return_value=FR())
257 265
    def test_create_network(self, networks_post):
258 266
        for name, shared in product((None, 'net name'), (None, True)):

Also available in: Unified diff