~ubuntu-branches/ubuntu/saucy/python-quantumclient/saucy

« back to all changes in this revision

Viewing changes to quantumclient/quantum/v2_0/network.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Adam Gandelman, Chuck Short
  • Date: 2013-03-07 11:14:49 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20130307111449-08nu53xwd4bc5if2
Tags: 1:2.1.2-0ubuntu1
[ Adam Gandelman ]
* debian/control: Drop 'Provides: ${python:Provides}'.

[ Chuck Short ]
* New upstream release.
* debian/control: Add python-testtools and python-fixtures as build
  deps.
* debian/patches/override_cliff_version.patch: Dropped, no longer needed.
* debian/control: Add python-iso8601 build-depends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
import argparse
19
19
import logging
20
20
 
 
21
from quantumclient.common import utils
21
22
from quantumclient.quantum.v2_0 import CreateCommand
22
23
from quantumclient.quantum.v2_0 import DeleteCommand
23
24
from quantumclient.quantum.v2_0 import ListCommand
 
25
from quantumclient.quantum.v2_0 import ShowCommand
24
26
from quantumclient.quantum.v2_0 import UpdateCommand
25
 
from quantumclient.quantum.v2_0 import ShowCommand
26
27
 
27
28
 
28
29
def _format_subnets(network):
29
30
    try:
30
 
        return '\n'.join(network['subnets'])
 
31
        return '\n'.join([' '.join([s['id'], s.get('cidr', '')])
 
32
                          for s in network['subnets']])
31
33
    except Exception:
32
34
        return ''
33
35
 
40
42
    _formatters = {'subnets': _format_subnets, }
41
43
    list_columns = ['id', 'name', 'subnets']
42
44
 
 
45
    def extend_list(self, data, parsed_args):
 
46
        """Add subnet information to a network list"""
 
47
        quantum_client = self.get_client()
 
48
        search_opts = {'fields': ['id', 'cidr']}
 
49
        subnets = quantum_client.list_subnets(**search_opts).get('subnets', [])
 
50
        subnet_dict = dict([(s['id'], s) for s in subnets])
 
51
        for n in data:
 
52
            if 'subnets' in n:
 
53
                n['subnets'] = [(subnet_dict.get(s) or {"id": s})
 
54
                                for s in n['subnets']]
 
55
 
 
56
 
 
57
class ListExternalNetwork(ListNetwork):
 
58
    """List external networks that belong to a given tenant"""
 
59
 
 
60
    log = logging.getLogger(__name__ + '.ListExternalNetwork')
 
61
 
 
62
    def retrieve_list(self, parsed_args):
 
63
        external = '--router:external=True'
 
64
        if external not in self.values_specs:
 
65
            self.values_specs.append('--router:external=True')
 
66
        return super(ListExternalNetwork, self).retrieve_list(parsed_args)
 
67
 
43
68
 
44
69
class ShowNetwork(ShowCommand):
45
70
    """Show information of a given network."""
69
94
            default=argparse.SUPPRESS,
70
95
            help='Set the network as shared')
71
96
        parser.add_argument(
72
 
            'name', metavar='name',
 
97
            'name', metavar='NAME',
73
98
            help='Name of network to create')
74
99
 
75
100
    def args2body(self, parsed_args):