Revision 7e57e590 kamaki/cli/commands/network.py
b/kamaki/cli/commands/network.py | ||
---|---|---|
42 | 42 |
from kamaki.cli.commands import _command_init, errors, addLogSettings |
43 | 43 |
from kamaki.cli.commands import ( |
44 | 44 |
_optional_output_cmd, _optional_json, _name_filter, _id_filter) |
45 |
from kamaki.cli.utils import filter_dicts_by_dict |
|
45 | 46 |
|
46 | 47 |
|
47 | 48 |
network_cmds = CommandTree('network', 'Networking API network commands') |
... | ... | |
95 | 96 |
more=FlagArgument( |
96 | 97 |
'output results in pages (-n to set items per page, default 10)', |
97 | 98 |
'--more'), |
99 |
user_id=ValueArgument( |
|
100 |
'show only networks belonging to user with this id', '--user-id') |
|
98 | 101 |
) |
99 | 102 |
|
103 |
def _filter_by_user_id(self, nets): |
|
104 |
return filter_dicts_by_dict(nets, dict(user_id=self['user_id'])) if ( |
|
105 |
self['user_id']) else nets |
|
106 |
|
|
100 | 107 |
@errors.generic.all |
101 | 108 |
@errors.cyclades.connection |
102 | 109 |
def _run(self): |
103 |
nets = self.client.list_networks(detail=self['detail']) |
|
110 |
detail = self['detail'] or self['user_id'] |
|
111 |
nets = self.client.list_networks(detail=detail) |
|
112 |
nets = self._filter_by_user_id(nets) |
|
104 | 113 |
nets = self._filter_by_name(nets) |
105 | 114 |
nets = self._filter_by_id(nets) |
115 |
if detail and not self['detail']: |
|
116 |
nets = [dict( |
|
117 |
id=n['id'], name=n['name'], links=n['links']) for n in nets] |
|
106 | 118 |
kwargs = dict() |
107 | 119 |
if self['more']: |
108 | 120 |
kwargs['out'] = StringIO() |
Also available in: Unified diff