Debian Codegraph @

neutronclient/neutron/v2_0/network_ip_availability.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12 #
13
14 from cliff import show
15
16 from neutronclient._i18n import _
17 from neutronclient.neutron import v2_0 as neutronV20
18
19
20 class ListIpAvailability(neutronV20.ListCommand):
21 """List IP usage of networks"""
22
23 resource = 'network_ip_availability'
24 resource_plural = 'network_ip_availabilities'
25 list_columns = ['network_id', 'network_name', 'total_ips', 'used_ips']
26 paginations_support = True
27 sorting_support = True
28
29 filter_attrs = [
30 {'name': 'ip_version',
31 'help': _('Returns IP availability for the network subnets '
32 'with a given IP version. Default: 4'),
33 'argparse_kwargs': {'type': int,
34 'choices': [4, 6],
35 'default': 4}
36 },
37 {'name': 'network_id',
38 'help': _('Returns IP availability for the network '
39 'matching a given network ID.')},
40 {'name': 'network_name',
41 'help': _('Returns IP availability for the network '
42 'matching a given name.')},
43 {'name': 'tenant_id',
44 'help': _('Returns IP availability for the networks '
45 'with a given tenant ID.')},
46 ]
47
48
49 class ShowIpAvailability(neutronV20.NeutronCommand, show.ShowOne):
50 """Show IP usage of specific network"""
51
52 resource = 'network_ip_availability'
53
54 def get_parser(self, prog_name):
55 parser = super(ShowIpAvailability, self).get_parser(prog_name)
56 parser.add_argument(
57 'network_id', metavar='NETWORK',
58 help=_('ID or name of network to look up.'))
59 return parser
60
61 def take_action(self, parsed_args):
62 self.log.debug('run(%s)', parsed_args)
63 neutron_client = self.get_client()
64 _id = neutronV20.find_resourceid_by_name_or_id(
65 neutron_client, 'network', parsed_args.network_id)
66 data = neutron_client.show_network_ip_availability(_id)
67 self.format_output_data(data)
68 resource = data[self.resource]
69 if self.resource in data:
70 return zip(*sorted(resource.items()))
71 else:
72 return None