Commit 0e27687b authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Add "detail" to network list

Refs: #4563
parent cd0927f7
......@@ -246,7 +246,7 @@ class cyclades(object):
def _raise(self, *args, **kwargs):
network_type = kwargs.get('network_type', None)
msg = 'Invalid network type %s.\nValid types: %s' % (
network_type, ' , '.join(this.net_types))
network_type, ' '.join(this.net_types))
assert network_type in this.net_types, msg
return foo(self, *args, **kwargs)
return _raise
......
......@@ -36,8 +36,7 @@ from pydoc import pager
from kamaki.cli import command
from kamaki.cli.command_tree import CommandTree
from kamaki.cli.errors import (
CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument)
from kamaki.cli.errors import CLISyntaxError, CLIBaseUrlError
from kamaki.clients.cyclades import CycladesNetworkClient
from kamaki.cli.argument import FlagArgument, ValueArgument
from kamaki.cli.commands import _command_init, errors, addLogSettings
......@@ -101,11 +100,9 @@ class network_list(_init_network, _optional_json, _name_filter, _id_filter):
@errors.generic.all
@errors.cyclades.connection
def _run(self):
nets = self.client.list_networks()
nets = self.client.list_networks(detail=self['detail'])
nets = self._filter_by_name(nets)
nets = self._filter_by_id(nets)
if not self['detail']:
nets = [dict(id=net['id'], name=net['name']) for net in nets]
kwargs = dict()
if self['more']:
kwargs['out'] = StringIO()
......@@ -138,7 +135,7 @@ class network_info(_init_network, _optional_json):
@command(network_cmds)
class network_create(_init_network, _optional_json):
"""Create a new network
Valid network types: CUSTOM, MAC_FILTERED, IP_LESS_ROUTED, PHYSICAL_VLAN
Valid network types: CUSTOM MAC_FILTERED IP_LESS_ROUTED PHYSICAL_VLAN
"""
arguments = dict(
......
......@@ -35,6 +35,7 @@ from time import sleep
from kamaki.clients.cyclades.rest_api import CycladesRestClient
from kamaki.clients.network import NetworkClient
from kamaki.clients.utils import path4url
from kamaki.clients import ClientError
......@@ -511,6 +512,11 @@ class CycladesNetworkClient(NetworkClient):
network_types = (
'CUSTOM', 'MAC_FILTERED', 'IP_LESS_ROUTED', 'PHYSICAL_VLAN')
def list_networks(self, detail=None):
path = path4url('networks', 'detail' if detail else '')
r = self.get(path, success=200)
return r.json['networks']
def create_network(self, type, name=None, shared=None):
req = dict(network=dict(type=type, admin_state_up=True))
if name:
......
......@@ -251,8 +251,16 @@ class CycladesNetworkClient(TestCase):
FR.json = vm_recv
del self.client
@patch('kamaki.clients.Client.get', return_value=FR)
def test_list_networks(self, get):
FR.json = dict(networks='ret val')
for detail in (True, None):
self.assertEqual(self.client.list_networks(detail), 'ret val')
path = '/networks/detail' if detail else '/networks'
self.assertEqual(get.mock_calls[-1], call(path, success=200))
@patch(
'kamaki.clients.network.NetworkClient.networks_post',
'kamaki.clients.network.rest_api.NetworkRestClient.networks_post',
return_value=FR())
def test_create_network(self, networks_post):
for name, shared in product((None, 'net name'), (None, True)):
......
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