Revision c6afee48

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"""
b/kamaki/clients/cyclades/__init__.py
399 399
    def wait_network(
400 400
            self, net_id,
401 401
            current_status='PENDING', delay=1, max_wait=100, wait_cb=None):
402
        """Wait for network while its status is current_status
403

  
404
        :param net_id: integer (str or int)
405

  
406
        :param current_status: (str) PENDING | ACTIVE | DELETED
407 402

  
408
        :param delay: time interval between retries
409

  
410
        :max_wait: (int) timeout in secconds
403
        def get_status(self, net_id):
404
            r = self.get_network_details(net_id)
405
            return r['status'], None
411 406

  
412
        :param wait_cb: if set a progressbar is used to show progress
407
        return self._wait(
408
            net_id, current_status, get_status, delay, max_wait, wait_cb)
413 409

  
414
        :returns: (str) the new mode if succesfull, (bool) False if timed out
415
        """
410
    def wait_port(
411
            self, port_id,
412
            current_status='PENDING', delay=1, max_wait=100, wait_cb=None):
416 413

  
417 414
        def get_status(self, net_id):
418
            r = self.get_network_details(net_id)
415
            r = self.get_port_details(port_id)
419 416
            return r['status'], None
420 417

  
421 418
        return self._wait(
422
            net_id, current_status, get_status, delay, max_wait, wait_cb)
419
            port_id, current_status, get_status, delay, max_wait, wait_cb)

Also available in: Unified diff