/
vpcroutetable.py
201 lines (171 loc) · 6.62 KB
/
vpcroutetable.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2012 OpenStack Foundation.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from abc import ABCMeta
from abc import abstractmethod
try:
from oslo.config import cfg
except ImportError:
from oslo_config import cfg
try:
from neutron_lib.api import extensions
except ImportError:
from neutron.api import extensions
from neutron.api.v2 import attributes as attr
from neutron.api.v2 import base
try:
from neutron_lib import exceptions as exc
except ImportError:
from neutron.common import exceptions as exc
from neutron import manager
try:
from neutron.quota import resource_registry as quota
except ImportError:
from neutron.quota import QUOTAS as quota
try:
from neutron.openstack.common import uuidutils
except ImportError:
from oslo_utils import uuidutils
# Route table Exceptions
class RouteTableNotFound(exc.NotFound):
message = _("Route table %(id)s does not exist")
# Attribute Map
RESOURCE_ATTRIBUTE_MAP = {
'route_tables': {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True,
'primary_key': True},
'name': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': '',
'validate': {'type:name_not_default': None}},
'fq_name': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': '',
'validate': {'type:name_not_default': None}},
'routes': {'allow_post': True, 'allow_put': True,
'is_visible': True, 'default': ''},
'tenant_id': {'allow_post': True, 'allow_put': False,
'required_by_policy': True,
'is_visible': True},
},
'nat_instances': {
'id': {'allow_post': False, 'allow_put': False,
'validate': {'type:uuid': None},
'is_visible': True,
'primary_key': True},
'name': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': '',
'validate': {'type:name_not_default': None}},
'fq_name': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': '',
'validate': {'type:name_not_default': None}},
'internal_net': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': ''},
'internal_ip': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': ''},
'external_net': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': ''},
'external_ip': {'allow_post': True, 'allow_put': False,
'is_visible': True, 'default': ''},
'tenant_id': {'allow_post': True, 'allow_put': False,
'required_by_policy': True,
'is_visible': True},
},
}
EXTENDED_ATTRIBUTES_2_0 = {
'networks': {
'vpc:route_table': {'allow_post': True,
'allow_put': True,
'default': '',
'is_visible': True},
}
}
class Vpcroutetable(extensions.ExtensionDescriptor):
""" Route table extension"""
@classmethod
def get_name(cls):
return "route-table"
@classmethod
def get_alias(cls):
return "route-table"
@classmethod
def get_description(cls):
return "VPC route tables extension."
@classmethod
def get_namespace(cls):
# todo
return "http://docs.openstack.org/ext/routetables/api/v2.0"
@classmethod
def get_updated(cls):
return "2013-07-24T10:00:00-00:00"
@classmethod
def get_resources(cls):
""" Returns Ext Resources """
my_plurals = [(key, key[:-1]) for key in RESOURCE_ATTRIBUTE_MAP.keys()]
attr.PLURALS.update(dict(my_plurals))
exts = []
plugin = manager.NeutronManager.get_plugin()
for resource_name in ['route_table', 'nat_instance']:
collection_name = resource_name.replace('_', '-') + "s"
params = RESOURCE_ATTRIBUTE_MAP.get(resource_name + "s", dict())
quota.register_resource_by_name(resource_name)
controller = base.create_resource(collection_name,
resource_name,
plugin, params, allow_bulk=True,
allow_pagination=True,
allow_sorting=True)
ex = extensions.ResourceExtension(collection_name,
controller,
attr_map=params)
exts.append(ex)
return exts
def get_extended_resources(self, version):
if version == "2.0":
return EXTENDED_ATTRIBUTES_2_0
else:
return {}
class RouteTablePluginBase(object):
__metaclass__ = ABCMeta
@abstractmethod
def create_route_table(self, context, route_table):
pass
@abstractmethod
def delete_route_table(self, context, id):
pass
@abstractmethod
def update_route_table(self, context, id, route_table):
pass
@abstractmethod
def get_route_tables(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None,
page_reverse=False):
pass
@abstractmethod
def get_route_table(self, context, id, fields=None):
pass
@abstractmethod
def create_nat_instance(self, context, nat_instance):
pass
@abstractmethod
def delete_nat_instance(self, context, id):
pass
@abstractmethod
def get_nat_instances(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None,
page_reverse=False):
pass
@abstractmethod
def get_nat_instance(self, context, id, fields=None):
pass