Revision c788a761
b/kamaki/cli/commands/cyclades.py | ||
---|---|---|
39 | 39 |
from kamaki.cli import command |
40 | 40 |
from kamaki.cli.command_tree import CommandTree |
41 | 41 |
from kamaki.cli.utils import remove_from_items, filter_dicts_by_dict |
42 |
from kamaki.cli.errors import raiseCLIError, CLISyntaxError, CLIBaseUrlError |
|
42 |
from kamaki.cli.errors import ( |
|
43 |
raiseCLIError, CLISyntaxError, CLIBaseUrlError, CLIInvalidArgument) |
|
43 | 44 |
from kamaki.clients.cyclades import CycladesClient, ClientError |
44 | 45 |
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument |
45 | 46 |
from kamaki.cli.argument import ProgressBarArgument, DateArgument, IntArgument |
... | ... | |
116 | 117 |
timeout=timeout) |
117 | 118 |
|
118 | 119 |
|
120 |
class _firewall_wait(_service_wait): |
|
121 |
|
|
122 |
def _wait(self, server_id, current_status, timeout=60): |
|
123 |
super(_firewall_wait, self)._wait( |
|
124 |
'Firewall of server', |
|
125 |
server_id, self.client.wait_firewall, current_status, |
|
126 |
timeout=timeout) |
|
127 |
|
|
128 |
|
|
119 | 129 |
class _init_cyclades(_command_init): |
120 | 130 |
@errors.generic.all |
121 | 131 |
@addLogSettings |
... | ... | |
552 | 562 |
|
553 | 563 |
|
554 | 564 |
@command(server_cmds) |
555 |
class server_firewall_set(_init_cyclades, _optional_output_cmd): |
|
565 |
class server_firewall_set( |
|
566 |
_init_cyclades, _optional_output_cmd, _firewall_wait): |
|
556 | 567 |
"""Set the firewall profile on virtual server public network |
557 | 568 |
Values for profile: |
558 | 569 |
- DISABLED: Shutdown firewall |
... | ... | |
560 | 571 |
- PROTECTED: Firewall in secure mode |
561 | 572 |
""" |
562 | 573 |
|
574 |
arguments = dict( |
|
575 |
wait=FlagArgument('Wait server firewall to build', ('-w', '--wait')), |
|
576 |
timeout=IntArgument( |
|
577 |
'Set wait timeout in seconds (default: 60)', '--timeout', |
|
578 |
default=60) |
|
579 |
) |
|
580 |
|
|
563 | 581 |
@errors.generic.all |
564 | 582 |
@errors.cyclades.connection |
565 | 583 |
@errors.cyclades.server_id |
566 | 584 |
@errors.cyclades.firewall |
567 | 585 |
def _run(self, server_id, profile): |
568 |
self._optional_output(self.client.set_firewall_profile( |
|
569 |
server_id=int(server_id), profile=('%s' % profile).upper())) |
|
586 |
if self['timeout'] and not self['wait']: |
|
587 |
raise CLIInvalidArgument('Invalid use of --timeout', details=[ |
|
588 |
'Timeout is used only along with -w/--wait']) |
|
589 |
old_profile = self.client.get_firewall_profile(server_id) |
|
590 |
if old_profile.lower() == profile.lower(): |
|
591 |
self.error('Firewall of server %s: allready in status %s' % ( |
|
592 |
server_id, old_profile)) |
|
593 |
else: |
|
594 |
self._optional_output(self.client.set_firewall_profile( |
|
595 |
server_id=int(server_id), profile=('%s' % profile).upper())) |
|
596 |
if self['wait']: |
|
597 |
self._wait(server_id, old_profile, timeout=self['timeout']) |
|
570 | 598 |
|
571 | 599 |
def main(self, server_id, profile): |
572 | 600 |
super(self.__class__, self)._run() |
b/kamaki/clients/cyclades/__init__.py | ||
---|---|---|
342 | 342 |
|
343 | 343 |
:param delay: time interval between retries |
344 | 344 |
|
345 |
:max_wait: (int) timeout in secconds |
|
346 |
|
|
345 | 347 |
:param wait_cb: if set a progressbar is used to show progress |
346 | 348 |
|
347 | 349 |
:returns: (str) the new mode if succesfull, (bool) False if timed out |
... | ... | |
366 | 368 |
|
367 | 369 |
:param delay: time interval between retries |
368 | 370 |
|
371 |
:max_wait: (int) timeout in secconds |
|
372 |
|
|
369 | 373 |
:param wait_cb: if set a progressbar is used to show progress |
370 | 374 |
|
371 | 375 |
:returns: (str) the new mode if succesfull, (bool) False if timed out |
... | ... | |
378 | 382 |
return self._wait( |
379 | 383 |
net_id, current_status, get_status, delay, max_wait, wait_cb) |
380 | 384 |
|
385 |
def wait_firewall( |
|
386 |
self, server_id, |
|
387 |
current_status='DISABLED', delay=1, max_wait=100, wait_cb=None): |
|
388 |
"""Wait while the public network firewall status is current_status |
|
389 |
|
|
390 |
:param server_id: integer (str or int) |
|
391 |
|
|
392 |
:param current_status: (str) DISABLED | ENABLED | PROTECTED |
|
393 |
|
|
394 |
:param delay: time interval between retries |
|
395 |
|
|
396 |
:max_wait: (int) timeout in secconds |
|
397 |
|
|
398 |
:param wait_cb: if set a progressbar is used to show progress |
|
399 |
|
|
400 |
:returns: (str) the new mode if succesfull, (bool) False if timed out |
|
401 |
""" |
|
402 |
|
|
403 |
def get_status(self, server_id): |
|
404 |
return self.get_firewall_profile(server_id), None |
|
405 |
|
|
406 |
return self._wait( |
|
407 |
server_id, current_status, get_status, delay, max_wait, wait_cb) |
|
408 |
|
|
381 | 409 |
def get_floating_ip_pools(self): |
382 | 410 |
""" |
383 | 411 |
:returns: (dict) {floating_ip_pools:[{name: ...}, ...]} |
Also available in: Unified diff