Revision 17cfc2f0 kamaki/cli/commands/network.py
b/kamaki/cli/commands/network.py | ||
---|---|---|
447 | 447 |
self._run(port_id=port_id) |
448 | 448 |
|
449 | 449 |
|
450 |
class _port_create(_init_network): |
|
450 |
class _port_create(_init_network, _optional_json, _port_wait):
|
|
451 | 451 |
|
452 |
@errors.generic.all |
|
453 |
@errors.cyclades.connection |
|
454 |
@errors.cyclades.network_id |
|
455 |
def _run(self, network_id, device_id): |
|
452 |
def connect(self, network_id, device_id): |
|
456 | 453 |
fixed_ips = [dict( |
457 | 454 |
subnet_id=self['subnet_id'], ip_address=self['ip_address'])] if ( |
458 | 455 |
self['subnet_id']) else None |
... | ... | |
467 | 464 |
|
468 | 465 |
|
469 | 466 |
@command(port_cmds) |
470 |
class port_create(_init_network, _optional_json, _port_wait):
|
|
467 |
class port_create(_init_network): |
|
471 | 468 |
"""Create a new port (== connect server to network)""" |
472 | 469 |
|
473 | 470 |
arguments = dict( |
... | ... | |
488 | 485 |
) |
489 | 486 |
required = ('network_id', 'device_id') |
490 | 487 |
|
488 |
@errors.generic.all |
|
489 |
@errors.cyclades.connection |
|
490 |
@errors.cyclades.network_id |
|
491 |
@errors.cyclades.server_id |
|
492 |
def _run(self, network_id, server_id): |
|
493 |
self.connect(network_id, server_id) |
|
494 |
|
|
491 | 495 |
def main(self): |
492 | 496 |
super(self.__class__, self)._run() |
493 |
self._run(network_id=self['network_id'], device_id=self['device_id'])
|
|
497 |
self._run(network_id=self['network_id'], server_id=self['device_id'])
|
|
494 | 498 |
|
495 | 499 |
|
496 | 500 |
@command(port_cmds) |
... | ... | |
592 | 596 |
"""Connect a network with a device (server or router)""" |
593 | 597 |
|
594 | 598 |
arguments = dict( |
595 |
name=ValueArgument('A human readable name', '--name'), |
|
599 |
name=ValueArgument('A human readable name for the port', '--name'),
|
|
596 | 600 |
security_group_id=RepeatableArgument( |
597 | 601 |
'Add a security group id (can be repeated)', |
598 | 602 |
('-g', '--security-group')), |
... | ... | |
601 | 605 |
'--subnet-id'), |
602 | 606 |
ip_address=ValueArgument( |
603 | 607 |
'IP address for subnet id (used with --subnet-id', '--ip-address'), |
604 |
wait=FlagArgument('Wait port to be established', ('-w', '--wait')),
|
|
608 |
wait=FlagArgument('Wait network to connect', ('-w', '--wait')),
|
|
605 | 609 |
) |
606 | 610 |
|
611 |
@errors.generic.all |
|
612 |
@errors.cyclades.connection |
|
613 |
@errors.cyclades.network_id |
|
614 |
@errors.cyclades.server_id |
|
615 |
def _run(self, network_id, server_id): |
|
616 |
self.connect(network_id, server_id) |
|
617 |
|
|
607 | 618 |
def main(self, network_id, device_id): |
608 | 619 |
super(self.__class__, self)._run() |
609 | 620 |
self._run(network_id=network_id, device_id=device_id) |
610 | 621 |
|
611 | 622 |
|
612 | 623 |
@command(network_cmds) |
613 |
class network_disconnect(_init_network, _optional_json): |
|
624 |
class network_disconnect(_init_network, _port_wait, _optional_json):
|
|
614 | 625 |
"""Disconnnect a network from a device""" |
615 | 626 |
|
616 | 627 |
def _cyclades_client(self): |
... | ... | |
620 | 631 |
from kamaki.clients.cyclades import CycladesClient |
621 | 632 |
return CycladesClient(URL, self.client.token) |
622 | 633 |
|
634 |
arguments = dict( |
|
635 |
wait=FlagArgument('Wait network to disconnect', ('-w', '--wait')) |
|
636 |
) |
|
637 |
|
|
623 | 638 |
@errors.generic.all |
624 | 639 |
@errors.cyclades.connection |
625 | 640 |
@errors.cyclades.network_id |
... | ... | |
633 | 648 |
network_id, device_id)) |
634 | 649 |
for net in nets: |
635 | 650 |
self.client.port_delete(net['id']) |
636 |
self.error('Deleted connection:')
|
|
651 |
self.error('Deleting this connection:')
|
|
637 | 652 |
self.print_dict(net) |
653 |
if self['wait']: |
|
654 |
self._wait(net['id'], net['status']) |
|
638 | 655 |
|
639 | 656 |
def main(self, network_id, device_id): |
640 | 657 |
super(self.__class__, self)._run() |
Also available in: Unified diff