Revision c6afee48 kamaki/cli/commands/network.py

b/kamaki/cli/commands/network.py
68 68
            timeout=timeout)
69 69

  
70 70

  
71
class _port_wait(_service_wait):
72

  
73
    def _wait(self, port_id, current_status, timeout=60):
74
        super(_port_wait, self)._wait(
75
            'Port', port_id, self.client.wait_port, current_status,
76
            timeout=timeout)
77

  
78

  
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

  
71 87
class _init_network(_command_init):
72 88
    @errors.generic.all
73 89
    @addLogSettings
......
472 488

  
473 489

  
474 490
@command(port_cmds)
475
class port_create(_init_network, _optional_json):
491
class port_create(_init_network, _optional_json, _port_wait):
476 492
    """Create a new port (== connect server to network)"""
477 493

  
478 494
    arguments = dict(
......
488 504
        network_id=ValueArgument('Set the network ID', '--network-id'),
489 505
        device_id=ValueArgument(
490 506
            'The device is either a virtual server or a virtual router',
491
            '--device-id')
507
            '--device-id'),
508
        wait=FlagArgument('Wait port to be established', ('-w', '--wait')),
492 509
    )
493 510
    required = ('network_id', 'device_id')
494 511

  
......
504 521
            name=self['name'],
505 522
            security_groups=self['security_group_id'],
506 523
            fixed_ips=fixed_ips)
524
        if self['wait']:
525
            self._wait(r['id'], r['status'])
507 526
        self._print(r, self.print_dict)
508 527

  
509 528
    def main(self):
......
511 530
        self._run(network_id=self['network_id'], device_id=self['device_id'])
512 531

  
513 532

  
533
@command(port_cmds)
534
class port_wait(_init_network, _port_wait):
535
    """Wait for port to finish [PENDING, ACTIVE, DELETED]"""
536

  
537
    arguments = dict(
538
        timeout=IntArgument(
539
            'Wait limit in seconds (default: 60)', '--timeout', default=60)
540
    )
541

  
542
    @errors.generic.all
543
    @errors.cyclades.connection
544
    def _run(self, port_id, current_status):
545
        port = self.client.get_port_details(port_id)
546
        if port['status'].lower() == current_status.lower():
547
            self._wait(port_id, current_status, timeout=self['timeout'])
548
        else:
549
            self.error(
550
                'Port %s: Cannot wait for status %s, '
551
                'status is already %s' % (
552
                    port_id, current_status, port['status']))
553

  
554
    def main(self, port_id, current_status='PENDING'):
555
        super(self.__class__, self)._run()
556
        self._run(port_id=port_id, current_status=current_status)
557

  
558

  
514 559
@command(ip_cmds)
515 560
class ip_list(_init_network, _optional_json):
516 561
    """List reserved floating IPs"""

Also available in: Unified diff