Debian Codegraph @

neutronclient/neutron/v2_0/address_scope.py

raw
1 # Copyright 2015 Huawei Technologies India Pvt. Ltd..
2 # All Rights Reserved
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15 #
16
17 from neutronclient._i18n import _
18 from neutronclient.common import utils
19 from neutronclient.neutron import v2_0 as neutronV20
20
21
22 class ListAddressScope(neutronV20.ListCommand):
23 """List address scopes that belong to a given tenant."""
24
25 resource = 'address_scope'
26 list_columns = ['id', 'name', 'ip_version']
27 pagination_support = True
28 sorting_support = True
29
30
31 class ShowAddressScope(neutronV20.ShowCommand):
32 """Show information about an address scope."""
33
34 resource = 'address_scope'
35
36
37 class CreateAddressScope(neutronV20.CreateCommand):
38 """Create an address scope for a given tenant."""
39
40 resource = 'address_scope'
41
42 def add_known_arguments(self, parser):
43 parser.add_argument(
44 '--shared',
45 action='store_true',
46 help=_('Set the address scope as shared.'))
47 parser.add_argument(
48 'name',
49 metavar='NAME',
50 help=_('Specify the name of the address scope.'))
51 parser.add_argument(
52 'ip_version',
53 metavar='IP_VERSION',
54 type=int,
55 choices=[4, 6],
56 help=_('Specify the address family of the address scope.'))
57
58 def args2body(self, parsed_args):
59 body = {'name': parsed_args.name,
60 'ip_version': parsed_args.ip_version}
61 if parsed_args.shared:
62 body['shared'] = True
63 neutronV20.update_dict(parsed_args, body, ['tenant_id'])
64 return {self.resource: body}
65
66
67 class DeleteAddressScope(neutronV20.DeleteCommand):
68 """Delete an address scope."""
69
70 resource = 'address_scope'
71
72
73 class UpdateAddressScope(neutronV20.UpdateCommand):
74 """Update an address scope."""
75
76 resource = 'address_scope'
77
78 def add_known_arguments(self, parser):
79 parser.add_argument('--name',
80 help=_('Updated name of the address scope.'))
81 utils.add_boolean_argument(
82 parser, '--shared',
83 help=_('Set sharing of address scope. '
84 '(True means shared)'))
85
86 def args2body(self, parsed_args):
87 body = {}
88 neutronV20.update_dict(parsed_args, body, ['name', 'shared'])
89 return {self.resource: body}