Commit 2f611b3b authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Move command-wait class to kamaki.cli.cmds

Move and rename:
kamaki.cli.cmds.cyclades._service_wait --> kamaki.cli.cmds.Wait

The class is now accessible to all commands, therefore it is not
an internal class for cyclades module. The name of the class
changed to conform with pep8 suggestions for classes
parent 10632870
......@@ -35,7 +35,7 @@ from kamaki.cli.logger import get_logger
from kamaki.cli.utils import (
print_list, print_dict, print_json, print_items, ask_user, pref_enc,
filter_dicts_by_dict)
from kamaki.cli.argument import ValueArgument
from kamaki.cli.argument import ValueArgument, ProgressBarArgument
from kamaki.cli.errors import CLIInvalidArgument, CLIBaseUrlError
from sys import stdin, stdout, stderr
......@@ -366,3 +366,31 @@ class IDFilter(object):
def _filter_by_id(self, items):
return self._non_exact_id_filter(self._exact_id_filter(items))
class Wait(object):
wait_arguments = dict(
progress_bar=ProgressBarArgument(
'do not show progress bar', ('-N', '--no-progress-bar'), False)
)
def _wait(
self, service, service_id, status_method, current_status,
countdown=True, timeout=60):
(progress_bar, wait_cb) = self._safe_progress_bar(
'%s %s: status is still %s' % (
service, service_id, current_status),
countdown=countdown, timeout=timeout)
try:
new_mode = status_method(
service_id, current_status, max_wait=timeout, wait_cb=wait_cb)
if new_mode:
self.error('%s %s: status is now %s' % (
service, service_id, new_mode))
else:
self.error('%s %s: status is still %s' % (
service, service_id, current_status))
except KeyboardInterrupt:
self.error('\n- canceled')
finally:
self._safe_progress_bar_finish(progress_bar)
......@@ -45,9 +45,9 @@ from kamaki.cli.errors import (
from kamaki.clients.cyclades import CycladesClient
from kamaki.cli.argument import (
FlagArgument, ValueArgument, KeyValueArgument, RepeatableArgument,
ProgressBarArgument, DateArgument, IntArgument, StatusArgument)
DateArgument, IntArgument, StatusArgument)
from kamaki.cli.cmds import (
CommandInit, dataModification, OptionalOutput, NameFilter, IDFilter,
CommandInit, dataModification, OptionalOutput, NameFilter, IDFilter, Wait,
errors, addLogSettings, )
......@@ -73,37 +73,7 @@ howto_personality = [
server_states = ('BUILD', 'ACTIVE', 'STOPPED', 'REBOOT')
class _service_wait(object):
wait_arguments = dict(
progress_bar=ProgressBarArgument(
'do not show progress bar', ('-N', '--no-progress-bar'), False)
)
def _wait(
self, service, service_id, status_method, current_status,
countdown=True, timeout=60):
(progress_bar, wait_cb) = self._safe_progress_bar(
'%s %s: status is still %s' % (
service, service_id, current_status),
countdown=countdown, timeout=timeout)
try:
new_mode = status_method(
service_id, current_status, max_wait=timeout, wait_cb=wait_cb)
if new_mode:
self.error('%s %s: status is now %s' % (
service, service_id, new_mode))
else:
self.error('%s %s: status is still %s' % (
service, service_id, current_status))
except KeyboardInterrupt:
self.error('\n- canceled')
finally:
self._safe_progress_bar_finish(progress_bar)
class _server_wait(_service_wait):
class _server_wait(Wait):
def _wait(self, server_id, current_status, timeout=60):
super(_server_wait, self)._wait(
......
......@@ -45,7 +45,7 @@ from kamaki.cli.argument import (
StatusArgument)
from kamaki.cli.cmds import (
CommandInit, OptionalOutput, NameFilter, IDFilter, errors, addLogSettings)
from kamaki.cli.cmds.cyclades import _service_wait
from kamaki.cli.cmds import Wait
network_cmds = CommandTree('network', 'Network API network commands')
......@@ -63,7 +63,7 @@ about_authentication = '\nUser Authentication:\
port_states = ('BUILD', 'ACTIVE', 'DOWN', 'ERROR')
class _port_wait(_service_wait):
class _port_wait(Wait):
def _wait(self, port_id, current_status, timeout=60):
super(_port_wait, self)._wait(
......
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