Debian Codegraph @

networking_l2gw/l2gatewayclient/l2gw_client_ext/_l2_gateway_connection.py

raw
1 # Copyright 2015 OpenStack Foundation.
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.common import extension
18 from neutronclient.neutron import v2_0 as l2gatewayV20
19
20 from networking_l2gw._i18n import _
21
22
23 class L2GatewayConnection(extension.NeutronClientExtension):
24 resource = 'l2_gateway_connection'
25 resource_plural = 'l2_gateway_connections'
26 path = 'l2-gateway-connections'
27 object_path = '/%s' % path
28 resource_path = '/%s/%%s' % path
29 versions = ['2.0']
30
31
32 class L2GatewayConnectionCreate(extension.ClientExtensionCreate,
33 L2GatewayConnection):
34 """Create l2gateway-connection information."""
35
36 shell_command = 'l2-gateway-connection-create'
37
38 def retrieve_ids(self, client, args):
39 gateway_id = l2gatewayV20.find_resourceid_by_name_or_id(
40 client, 'l2_gateway', args.gateway_name)
41 network_id = l2gatewayV20.find_resourceid_by_name_or_id(
42 client, 'network', args.network)
43 return (gateway_id, network_id)
44
45 def get_parser(self, parser):
46 parser = super(l2gatewayV20.CreateCommand,
47 self).get_parser(parser)
48 parser.add_argument(
49 'gateway_name', metavar='<GATEWAY-NAME/UUID>',
50 help=_('Descriptive name for logical gateway.'))
51 parser.add_argument(
52 'network', metavar='<NETWORK-NAME/UUID>',
53 help=_('Network name or uuid.'))
54 parser.add_argument(
55 '--default-segmentation-id',
56 dest='seg_id',
57 help=_('default segmentation-id that will '
58 'be applied to the interfaces for which '
59 'segmentation id was not specified '
60 'in l2-gateway-create command.'))
61 return parser
62
63 def args2body(self, args):
64
65 neutron_client = self.get_client()
66 (gateway_id, network_id) = self.retrieve_ids(neutron_client,
67 args)
68
69 body = {'l2_gateway_connection':
70 {'l2_gateway_id': gateway_id,
71 'network_id': network_id}}
72 if args.seg_id:
73 body['l2_gateway_connection']['segmentation_id'] = args.seg_id
74
75 return body
76
77
78 class L2GatewayConnectionList(extension.ClientExtensionList,
79 L2GatewayConnection):
80 """List l2gateway-connections."""
81
82 shell_command = 'l2-gateway-connection-list'
83 list_columns = ['id', 'l2_gateway_id', 'network_id', 'segmentation_id']
84 pagination_support = True
85 sorting_support = True
86
87
88 class L2GatewayConnectionShow(extension.ClientExtensionShow,
89 L2GatewayConnection):
90 """Show information of a given l2gateway-connection."""
91
92 shell_command = 'l2-gateway-connection-show'
93 allow_names = False
94
95
96 class L2GatewayConnectionDelete(extension.ClientExtensionDelete,
97 L2GatewayConnection):
98 """Delete a given l2gateway-connection."""
99
100 shell_command = 'l2-gateway-connection-delete'
101 allow_names = False