Revision 099b433b kamaki/cli/commands/network.py

b/kamaki/cli/commands/network.py
40 40
    CLIBaseUrlError, CLIInvalidArgument, raiseCLIError)
41 41
from kamaki.clients.cyclades import CycladesNetworkClient, ClientError
42 42
from kamaki.cli.argument import (
43
    FlagArgument, ValueArgument, RepeatableArgument, IntArgument)
43
    FlagArgument, ValueArgument, RepeatableArgument, IntArgument,
44
    StatusArgument)
44 45
from kamaki.cli.commands import _command_init, errors, addLogSettings
45 46
from kamaki.cli.commands import (
46 47
    _optional_output_cmd, _optional_json, _name_filter, _id_filter)
......
59 60
    \n  to set authentication token: \
60 61
    [kamaki] config set cloud.<CLOUD>.token <TOKEN>'
61 62

  
63
port_states = ('BUILD', 'ACTIVE', 'DOWN', 'ERROR')
64

  
62 65

  
63 66
class _port_wait(_service_wait):
64 67

  
......
484 487
        self._run(port_id=port_id)
485 488

  
486 489

  
487
class PortStatusArgument(ValueArgument):
488

  
489
    valid = ('BUILD', 'ACTIVE', 'DOWN', 'ERROR')
490

  
491
    @property
492
    def value(self):
493
        return getattr(self, '_value', None)
494

  
495
    @value.setter
496
    def value(self, new_status):
497
        if new_status:
498
            new_status = new_status.upper()
499
            if new_status in self.valid:
500
                raise CLIInvalidArgument(
501
                    'Invalid argument %s' % new_status, details=[
502
                    'Status valid values: %s'] % ', '.join(self.valid))
503
            self._value = new_status
504

  
505

  
506 490
class _port_create(_init_network, _optional_json, _port_wait):
507 491

  
508 492
    def connect(self, network_id, device_id):
......
557 541

  
558 542
@command(port_cmds)
559 543
class port_wait(_init_network, _port_wait):
560
    """Wait for port to finish [ACTIVE, DOWN, BUILD, ERROR]"""
544
    """Wait for port to finish (default: BUILD)"""
561 545

  
562 546
    arguments = dict(
563
        current_status=PortStatusArgument(
564
            'Wait while in this status', '--status'),
547
        port_status=StatusArgument(
548
            'Wait while in this status (%s, default: %s)' % (
549
                ', '.join(port_states), port_states[0]),
550
            '--status',
551
            valid_states=port_states),
565 552
        timeout=IntArgument(
566 553
            'Wait limit in seconds (default: 60)', '--timeout', default=60)
567 554
    )
568 555

  
569 556
    @errors.generic.all
570 557
    @errors.cyclades.connection
571
    def _run(self, port_id, current_status):
558
    def _run(self, port_id, port_status):
572 559
        port = self.client.get_port_details(port_id)
573
        if port['status'].lower() == current_status.lower():
574
            self._wait(port_id, current_status, timeout=self['timeout'])
560
        if port['status'].lower() == port_status.lower():
561
            self._wait(port_id, port_status, timeout=self['timeout'])
575 562
        else:
576 563
            self.error(
577 564
                'Port %s: Cannot wait for status %s, '
578 565
                'status is already %s' % (
579
                    port_id, current_status, port['status']))
566
                    port_id, port_status, port['status']))
580 567

  
581 568
    def main(self, port_id):
582 569
        super(self.__class__, self)._run()
583
        current_status = self['current_status'] or self.arguments[
584
            'current_status'].valid[0]
585
        self._run(port_id=port_id, current_status=current_status)
570
        port_status = self['port_status'] or port_states[0]
571
        self._run(port_id=port_id, port_status=port_status)
586 572

  
587 573

  
588 574
@command(ip_cmds)

Also available in: Unified diff