Debian Codegraph @

networking_l2gw/extensions/l2gateway.py

raw
1 # Copyright 2015 OpenStack Foundation
2 # Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
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 import abc
17
18 from neutron_lib.api import extensions as api_extensions
19 from neutron_lib.api import validators
20
21 from neutron.api import extensions
22 from neutron.api.v2 import resource_helper
23 from neutron.common import config as common_config
24
25 from networking_l2gw import extensions as l2gw_extensions
26 from networking_l2gw.services.l2gateway.common import constants
27 from networking_l2gw.services.l2gateway.common import l2gw_validators
28
29 common_config.register_common_config_options()
30 extensions.append_api_extensions_path(l2gw_extensions.__path__)
31
32 RESOURCE_ATTRIBUTE_MAP = {
33 constants.L2_GATEWAYS: {
34 'id': {'allow_post': False, 'allow_put': False,
35 'is_visible': True},
36 'name': {'allow_post': True, 'allow_put': True,
37 'validate': {'type:string': None},
38 'is_visible': True, 'default': ''},
39 'devices': {'allow_post': True, 'allow_put': True,
40 'validate': {'type:l2gwdevice_list': None},
41 'is_visible': True},
42 'tenant_id': {'allow_post': True, 'allow_put': False,
43 'validate': {'type:string': None},
44 'required_by_policy': True,
45 'is_visible': True}
46 },
47 }
48
49 validators.add_validator('l2gwdevice_list',
50 l2gw_validators.validate_gwdevice_list)
51
52
53 class L2gateway(api_extensions.ExtensionDescriptor):
54
55 """API extension for Layer-2 Gateway support."""
56
57 @classmethod
58 def get_name(cls):
59 return "L2 Gateway"
60
61 @classmethod
62 def get_alias(cls):
63 return "l2-gateway"
64
65 @classmethod
66 def get_description(cls):
67 return "Connects Neutron networks with external networks at layer 2."
68
69 @classmethod
70 def get_updated(cls):
71 return "2015-01-01T00:00:00-00:00"
72
73 @classmethod
74 def get_resources(cls):
75 """Returns Ext Resources."""
76 plural_mappings = resource_helper.build_plural_mappings(
77 {}, RESOURCE_ATTRIBUTE_MAP)
78 resources = resource_helper.build_resource_info(plural_mappings,
79 RESOURCE_ATTRIBUTE_MAP,
80 constants.L2GW)
81
82 return resources
83
84 def get_extended_resources(self, version):
85 if version == "2.0":
86 return RESOURCE_ATTRIBUTE_MAP
87 else:
88 return {}
89
90
91 class L2GatewayPluginBase:
92
93 @abc.abstractmethod
94 def create_l2_gateway(self, context, l2_gateway):
95 pass
96
97 @abc.abstractmethod
98 def get_l2_gateway(self, context, id, fields=None):
99 pass
100
101 @abc.abstractmethod
102 def delete_l2_gateway(self, context, id):
103 pass
104
105 @abc.abstractmethod
106 def get_l2_gateways(self, context, filters=None, fields=None,
107 sorts=None, limit=None, marker=None,
108 page_reverse=False):
109 pass
110
111 @abc.abstractmethod
112 def update_l2_gateway(self, context, id, l2_gateway):
113 pass