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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
#
# 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.
import routes
from heat.api.openstack.v1 import stacks
from heat.api.openstack.v1 import resources
from heat.api.openstack.v1 import events
from heat.api.openstack.v1 import actions
from heat.api.openstack.v1 import build_info
from heat.api.openstack.v1 import software_configs
from heat.api.openstack.v1 import software_deployments
from heat.common import wsgi
from heat.openstack.common import log as logging
logger = logging.getLogger(__name__)
class API(wsgi.Router):
"""
WSGI router for Heat v1 ReST API requests.
"""
def __init__(self, conf, **local_conf):
self.conf = conf
mapper = routes.Mapper()
# Stacks
stacks_resource = stacks.create_resource(conf)
with mapper.submapper(controller=stacks_resource,
path_prefix="/{tenant_id}") as stack_mapper:
# Template handling
stack_mapper.connect("template_validate",
"/validate",
action="validate_template",
conditions={'method': 'POST'})
stack_mapper.connect("resource_types",
"/resource_types",
action="list_resource_types",
conditions={'method': 'GET'})
stack_mapper.connect("resource_schema",
"/resource_types/{type_name}",
action="resource_schema",
conditions={'method': 'GET'})
stack_mapper.connect("generate_template",
"/resource_types/{type_name}/template",
action="generate_template",
conditions={'method': 'GET'})
# Stack collection
stack_mapper.connect("stack_index",
"/stacks",
action="index",
conditions={'method': 'GET'})
stack_mapper.connect("stack_create",
"/stacks",
action="create",
conditions={'method': 'POST'})
stack_mapper.connect("stack_preview",
"/stacks/preview",
action="preview",
conditions={'method': 'POST'})
stack_mapper.connect("stack_detail",
"/stacks/detail",
action="detail",
conditions={'method': 'GET'})
# Stack data
stack_mapper.connect("stack_lookup",
"/stacks/{stack_name}",
action="lookup")
# \x3A matches on a colon.
# Routes treats : specially in its regexp
stack_mapper.connect("stack_lookup",
r"/stacks/{stack_name:arn\x3A.*}",
action="lookup")
subpaths = ['resources', 'events', 'template', 'actions']
path = "{path:%s}" % '|'.join(subpaths)
stack_mapper.connect("stack_lookup_subpath",
"/stacks/{stack_name}/" + path,
action="lookup",
conditions={'method': 'GET'})
stack_mapper.connect("stack_lookup_subpath_post",
"/stacks/{stack_name}/" + path,
action="lookup",
conditions={'method': 'POST'})
stack_mapper.connect("stack_show",
"/stacks/{stack_name}/{stack_id}",
action="show",
conditions={'method': 'GET'})
stack_mapper.connect("stack_template",
"/stacks/{stack_name}/{stack_id}/template",
action="template",
conditions={'method': 'GET'})
# Stack update/delete
stack_mapper.connect("stack_update",
"/stacks/{stack_name}/{stack_id}",
action="update",
conditions={'method': 'PUT'})
stack_mapper.connect("stack_delete",
"/stacks/{stack_name}/{stack_id}",
action="delete",
conditions={'method': 'DELETE'})
# Stack abandon
stack_mapper.connect("stack_abandon",
"/stacks/{stack_name}/{stack_id}/abandon",
action="abandon",
conditions={'method': 'DELETE'})
# Resources
resources_resource = resources.create_resource(conf)
stack_path = "/{tenant_id}/stacks/{stack_name}/{stack_id}"
with mapper.submapper(controller=resources_resource,
path_prefix=stack_path) as res_mapper:
# Resource collection
res_mapper.connect("resource_index",
"/resources",
action="index",
conditions={'method': 'GET'})
# Resource data
res_mapper.connect("resource_show",
"/resources/{resource_name}",
action="show",
conditions={'method': 'GET'})
res_mapper.connect("resource_metadata_show",
"/resources/{resource_name}/metadata",
action="metadata",
conditions={'method': 'GET'})
res_mapper.connect("resource_signal",
"/resources/{resource_name}/signal",
action="signal",
conditions={'method': 'POST'})
# Events
events_resource = events.create_resource(conf)
with mapper.submapper(controller=events_resource,
path_prefix=stack_path) as ev_mapper:
# Stack event collection
ev_mapper.connect("event_index_stack",
"/events",
action="index",
conditions={'method': 'GET'})
# Resource event collection
ev_mapper.connect("event_index_resource",
"/resources/{resource_name}/events",
action="index",
conditions={'method': 'GET'})
# Event data
ev_mapper.connect("event_show",
"/resources/{resource_name}/events/{event_id}",
action="show",
conditions={'method': 'GET'})
# Actions
actions_resource = actions.create_resource(conf)
with mapper.submapper(controller=actions_resource,
path_prefix=stack_path) as ac_mapper:
ac_mapper.connect("action_stack",
"/actions",
action="action",
conditions={'method': 'POST'})
# Info
info_resource = build_info.create_resource(conf)
with mapper.submapper(controller=info_resource,
path_prefix="/{tenant_id}") as info_mapper:
info_mapper.connect('build_info',
'/build_info',
action='build_info',
conditions={'method': 'GET'})
# Software configs
software_config_resource = software_configs.create_resource(conf)
with mapper.submapper(
controller=software_config_resource,
path_prefix="/{tenant_id}/software_configs"
) as sc_mapper:
sc_mapper.connect("software_config_create",
"",
action="create",
conditions={'method': 'POST'})
sc_mapper.connect("software_config_show",
"/{config_id}",
action="show",
conditions={'method': 'GET'})
sc_mapper.connect("software_config_delete",
"/{config_id}",
action="delete",
conditions={'method': 'DELETE'})
# Software deployments
sd_resource = software_deployments.create_resource(conf)
with mapper.submapper(
controller=sd_resource,
path_prefix='/{tenant_id}/software_deployments'
) as sa_mapper:
sa_mapper.connect("software_deployment_index",
"",
action="index",
conditions={'method': 'GET'})
sa_mapper.connect("software_deployment_metadata",
"/metadata/{server_id}",
action="metadata",
conditions={'method': 'GET'})
sa_mapper.connect("software_deployment_create",
"",
action="create",
conditions={'method': 'POST'})
sa_mapper.connect("software_deployment_show",
"/{deployment_id}",
action="show",
conditions={'method': 'GET'})
sa_mapper.connect("software_deployment_update",
"/{deployment_id}",
action="update",
conditions={'method': 'PUT'})
sa_mapper.connect("software_deployment_delete",
"/{deployment_id}",
action="delete",
conditions={'method': 'DELETE'})
super(API, self).__init__(mapper)
|