projects
/
kamaki
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cd0927f
)
Add "detail" to network list
author
Stavros Sachtouris
<saxtouri@admin.grnet.gr>
Wed, 6 Nov 2013 13:27:04 +0000
(15:27 +0200)
committer
Stavros Sachtouris
<saxtouri@admin.grnet.gr>
Wed, 6 Nov 2013 13:27:04 +0000
(15:27 +0200)
Refs: #4563
kamaki/cli/commands/errors.py
patch
|
blob
|
history
kamaki/cli/commands/network.py
patch
|
blob
|
history
kamaki/clients/cyclades/__init__.py
patch
|
blob
|
history
kamaki/clients/cyclades/test.py
patch
|
blob
|
history
diff --git
a/kamaki/cli/commands/errors.py
b/kamaki/cli/commands/errors.py
index
36d3ee0
..
07a377e
100644
(file)
--- a/
kamaki/cli/commands/errors.py
+++ b/
kamaki/cli/commands/errors.py
@@
-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' % (
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
assert network_type in this.net_types, msg
return foo(self, *args, **kwargs)
return _raise
diff --git
a/kamaki/cli/commands/network.py
b/kamaki/cli/commands/network.py
index
a70b57d
..
b77e671
100644
(file)
--- a/
kamaki/cli/commands/network.py
+++ b/
kamaki/cli/commands/network.py
@@
-36,8
+36,7
@@
from pydoc import pager
from kamaki.cli import command
from kamaki.cli.command_tree import CommandTree
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
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):
@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)
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()
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
@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(
"""
arguments = dict(
diff --git
a/kamaki/clients/cyclades/__init__.py
b/kamaki/clients/cyclades/__init__.py
index
45e8d64
..
a6fb717
100644
(file)
--- a/
kamaki/clients/cyclades/__init__.py
+++ b/
kamaki/clients/cyclades/__init__.py
@@
-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.cyclades.rest_api import CycladesRestClient
from kamaki.clients.network import NetworkClient
+from kamaki.clients.utils import path4url
from kamaki.clients import ClientError
from kamaki.clients import ClientError
@@
-511,6
+512,11
@@
class CycladesNetworkClient(NetworkClient):
network_types = (
'CUSTOM', 'MAC_FILTERED', 'IP_LESS_ROUTED', 'PHYSICAL_VLAN')
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:
def create_network(self, type, name=None, shared=None):
req = dict(network=dict(type=type, admin_state_up=True))
if name:
diff --git
a/kamaki/clients/cyclades/test.py
b/kamaki/clients/cyclades/test.py
index
203f73f
..
588d22e
100644
(file)
--- a/
kamaki/clients/cyclades/test.py
+++ b/
kamaki/clients/cyclades/test.py
@@
-251,8
+251,16
@@
class CycladesNetworkClient(TestCase):
FR.json = vm_recv
del self.client
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(
@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)):
return_value=FR())
def test_create_network(self, networks_post):
for name, shared in product((None, 'net name'), (None, True)):