Revision 4c33b869

b/kamaki/cli/commands/cyclades.py
301 301
        nics=FlagArgument(
302 302
            'Show only the network interfaces of this virtual server',
303 303
            '--nics'),
304
        network_id=ValueArgument(
305
            'Show the connection details to that network', '--network-id'),
306 304
        stats=FlagArgument('Get URLs for server statistics', '--stats'),
307 305
        diagnostics=FlagArgument('Diagnostic information', '--diagnostics')
308 306
    )
......
314 312
        if self['nics']:
315 313
            self._print(
316 314
                self.client.get_server_nics(server_id), self.print_dict)
317
        elif self['network_id']:
318
            self._print(
319
                self.client.get_server_network_nics(
320
                    server_id, self['network_id']), self.print_dict)
321 315
        elif self['stats']:
322 316
            self._print(
323 317
                self.client.get_server_stats(server_id), self.print_dict)
......
587 581
        'server_name', 'flavor_id', 'firewall_profile', 'metadata_to_set',
588 582
        'metadata_to_delete']
589 583

  
584
    def _set_firewall_profile(self, server_id):
585
        vm = self._restruct_server_info(
586
            self.client.get_server_details(server_id))
587
        ports = [p for p in vm['ports'] if 'firewallProfile' in p]
588
        pick_port = self.arguments['public_network_port_id']
589
        if pick_port.value:
590
            ports = [p for p in ports if pick_port.value in (
591
                '*', '%s' % p['id'])]
592
        elif len(ports) > 1:
593
            port_strings = ['Server %s ports to public networks:' % server_id]
594
            for p in ports:
595
                port_strings.append('  %s' % p['id'])
596
                for k in ('network_id', 'ipv4', 'ipv6', 'firewallProfile'):
597
                    v = p.get(k)
598
                    if v:
599
                        port_strings.append('\t%s: %s' % (k, v))
600
            raiseCLIError(
601
                'Multiple public connections on server %s' % (
602
                    server_id), details=port_strings + [
603
                        'To select one:',
604
                        '  %s <port id>' % pick_port.lvalue,
605
                        'To set all:',
606
                        '  %s *' % pick_port.lvalue, ])
607
        if not ports:
608
            pp = pick_port.value
609
            raiseCLIError(
610
                'No *public* networks attached on server %s%s' % (
611
                    server_id, ' through port %s' % pp if pp else ''),
612
                details=[
613
                    'To see all networks:',
614
                    '  kamaki network list',
615
                    'To connect to a network:',
616
                    '  kamaki network connect <net id> --device-id %s' % (
617
                        server_id)])
618
        for port in ports:
619
            self.error('Set port %s firewall to %s' % (
620
                port['id'], self['firewall_profile']))
621
            self.client.set_firewall_profile(
622
                server_id=server_id,
623
                profile=self['firewall_profile'],
624
                port_id=port['id'])
625

  
590 626
    @errors.generic.all
591 627
    @errors.cyclades.connection
592 628
    @errors.cyclades.server_id
......
596 632
        if self['flavor_id']:
597 633
            self.client.resize_server(server_id, self['flavor_id'])
598 634
        if self['firewall_profile']:
599
            vm = self._restruct_server_info(
600
                self.client.get_server_details(server_id))
601
            ports = [p for p in vm['ports'] if 'firewallProfile' in p]
602
            pick_port = self.arguments['public_network_port_id']
603
            if pick_port.value:
604
                ports = [p for p in ports if pick_port.value in (
605
                    '*', '%s' % p['id'])]
606
            elif len(ports) > 1:
607
                raiseCLIError(
608
                    'Multiple public connections on server %s' % (
609
                        server_id), details=[
610
                            'To select one:',
611
                            '  %s <port id>' % pick_port.lvalue,
612
                            'To set all:',
613
                            '  %s *' % pick_port.lvalue,
614
                            'Ports to public networks on server %s:' % (
615
                                server_id),
616
                            ','.join([' %s' % p['id'] for p in ports])])
617
            if not ports:
618
                pp = pick_port.value
619
                raiseCLIError(
620
                    'No *public* networks attached on server %s%s' % (
621
                        server_id, ' through port %s' % pp if pp else ''),
622
                    details=[
623
                        'To see all networks:',
624
                        '  kamaki network list',
625
                        'To connect to a network:',
626
                        '  kamaki network connect <net id> --device-id %s' % (
627
                            server_id)])
628
            for port in ports:
629
                self.error('Set port %s firewall to %s' % (
630
                    port['id'], self['firewall_profile']))
631
                self.client.set_firewall_profile(
632
                    server_id=server_id,
633
                    profile=self['firewall_profile'],
634
                    port_id=port['id'])
635
            self._set_firewall_profile(server_id)
635 636
        if self['metadata_to_set']:
636 637
            self.client.update_server_metadata(
637 638
                server_id, **self['metadata_to_set'])

Also available in: Unified diff