Revision 67dfe4a2 kamaki/cli/commands/network.py
b/kamaki/cli/commands/network.py | ||
---|---|---|
60 | 60 |
\n* to set authentication token: /config set cloud.<cloud>.token <token>' |
61 | 61 |
|
62 | 62 |
|
63 |
class _network_wait(_service_wait): |
|
64 |
|
|
65 |
def _wait(self, net_id, current_status, timeout=60): |
|
66 |
super(_network_wait, self)._wait( |
|
67 |
'Network', net_id, self.client.wait_network, current_status, |
|
68 |
timeout=timeout) |
|
69 |
|
|
70 |
|
|
71 | 63 |
class _port_wait(_service_wait): |
72 | 64 |
|
73 | 65 |
def _wait(self, port_id, current_status, timeout=60): |
... | ... | |
76 | 68 |
timeout=timeout) |
77 | 69 |
|
78 | 70 |
|
79 |
class _port_wait(_service_wait): |
|
80 |
|
|
81 |
def _wait(self, net_id, current_status, timeout=60): |
|
82 |
super(_network_wait, self)._wait( |
|
83 |
'Network', net_id, self.client.wait_network, current_status, |
|
84 |
timeout=timeout) |
|
85 |
|
|
86 |
|
|
87 | 71 |
class _init_network(_command_init): |
88 | 72 |
@errors.generic.all |
89 | 73 |
@addLogSettings |
... | ... | |
190 | 174 |
|
191 | 175 |
|
192 | 176 |
@command(network_cmds) |
193 |
class network_create(_init_network, _optional_json, _network_wait):
|
|
177 |
class network_create(_init_network, _optional_json): |
|
194 | 178 |
"""Create a new network""" |
195 | 179 |
|
196 | 180 |
arguments = dict( |
... | ... | |
199 | 183 |
'Make network shared (special privileges required)', '--shared'), |
200 | 184 |
network_type=NetworkTypeArgument( |
201 | 185 |
'Valid network types: %s' % (', '.join(NetworkTypeArgument.types)), |
202 |
'--type'), |
|
203 |
wait=FlagArgument('Wait network to build', ('-w', '--wait')), |
|
186 |
'--type') |
|
204 | 187 |
) |
205 | 188 |
required = ('network_type', ) |
206 | 189 |
|
... | ... | |
210 | 193 |
def _run(self, network_type): |
211 | 194 |
net = self.client.create_network( |
212 | 195 |
network_type, name=self['name'], shared=self['shared']) |
213 |
if self['wait']: |
|
214 |
self._wait(net['id'], net['status']) |
|
215 | 196 |
self._print(net, self.print_dict) |
216 | 197 |
|
217 | 198 |
def main(self): |
... | ... | |
254 | 235 |
self._run(network_id=network_id) |
255 | 236 |
|
256 | 237 |
|
257 |
@command(network_cmds) |
|
258 |
class network_wait(_init_network, _network_wait): |
|
259 |
"""Wait for network to finish [PENDING, ACTIVE, DELETED]""" |
|
260 |
|
|
261 |
arguments = dict( |
|
262 |
timeout=IntArgument( |
|
263 |
'Wait limit in seconds (default: 60)', '--timeout', default=60) |
|
264 |
) |
|
265 |
|
|
266 |
@errors.generic.all |
|
267 |
@errors.cyclades.connection |
|
268 |
@errors.cyclades.network_id |
|
269 |
def _run(self, network_id, current_status): |
|
270 |
net = self.client.get_network_details(network_id) |
|
271 |
if net['status'].lower() == current_status.lower(): |
|
272 |
self._wait(network_id, current_status, timeout=self['timeout']) |
|
273 |
else: |
|
274 |
self.error( |
|
275 |
'Network %s: Cannot wait for status %s, ' |
|
276 |
'status is already %s' % ( |
|
277 |
network_id, current_status, net['status'])) |
|
278 |
|
|
279 |
def main(self, network_id, current_status='PENDING'): |
|
280 |
super(self.__class__, self)._run() |
|
281 |
self._run(network_id=network_id, current_status=current_status) |
|
282 |
|
|
283 |
|
|
284 | 238 |
@command(subnet_cmds) |
285 | 239 |
class subnet_list(_init_network, _optional_json, _name_filter, _id_filter): |
286 | 240 |
"""List subnets |
... | ... | |
532 | 486 |
|
533 | 487 |
@command(port_cmds) |
534 | 488 |
class port_wait(_init_network, _port_wait): |
535 |
"""Wait for port to finish [PENDING, ACTIVE, DELETED]"""
|
|
489 |
"""Wait for port to finish [ACTIVE, DOWN, BUILD, ERROR]"""
|
|
536 | 490 |
|
537 | 491 |
arguments = dict( |
538 | 492 |
timeout=IntArgument( |
... | ... | |
551 | 505 |
'status is already %s' % ( |
552 | 506 |
port_id, current_status, port['status'])) |
553 | 507 |
|
554 |
def main(self, port_id, current_status='PENDING'):
|
|
508 |
def main(self, port_id, current_status='BUILD'):
|
|
555 | 509 |
super(self.__class__, self)._run() |
556 | 510 |
self._run(port_id=port_id, current_status=current_status) |
557 | 511 |
|
Also available in: Unified diff