1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from flask import jsonify
17 from o2ims import config
18 from o2ims.views import ocloud_view
21 apibase = config.get_o2ims_api_base()
24 def configure_routes(app, bus):
26 # ---------- OClouds ---------- #
27 @app.route(apibase, methods=["GET"])
29 result = ocloud_view.oclouds(bus.uow)
30 return jsonify(result), 200
32 # ---------- ResourceTypes ---------- #
34 @app.route(apibase + "/resourceTypes", methods=["GET"])
36 result = ocloud_view.resource_types(bus.uow)
37 return jsonify(result), 200
39 @app.route(apibase + "/resourceTypes", methods=["POST", "PUT", "PATCH",
41 def resource_types_not_allow():
42 return "Method Not Allowed", 405
44 @app.route(apibase + "/resourceTypes/<resourceTypeID>", methods=["GET"])
45 def resource_types_one(resourceTypeID):
46 result = ocloud_view.resource_type_one(resourceTypeID, bus.uow)
49 return jsonify(result), 200
51 @app.route(apibase + "/resourceTypes/<resourceTypeID>",
52 methods=["POST", "PUT", "PATCH", "DELETE"])
53 def resource_types_one_not_allow(resourceTypeID):
54 return "Method Not Allowed", 405
56 # ---------- ResourcePools ---------- #
58 @app.route(apibase + "/resourcePools", methods=["GET"])
60 result = ocloud_view.resource_pools(bus.uow)
61 return jsonify(result), 200
63 @app.route(apibase + "/resourcePools", methods=["POST", "PUT", "PATCH",
65 def resource_pools_not_allow():
66 return "Method Not Allowed", 405
68 @app.route(apibase + "/resourcePools/<resourcePoolID>", methods=["GET"])
69 def resource_pools_one(resourcePoolID):
70 result = ocloud_view.resource_pool_one(resourcePoolID, bus.uow)
73 return jsonify(result), 200
75 @app.route(apibase + "/resourcePools/<resourcePoolID>",
76 methods=["POST", "PUT", "PATCH", "DELETE"])
77 def resource_pools_one_not_allow(resourcePoolID):
78 return "Method Not Allowed", 405
80 # ---------- Resources ---------- #
82 @app.route(apibase + "/resourcePools/<resourcePoolID>/resources",
84 def resources(resourcePoolID):
85 result = ocloud_view.resources(resourcePoolID, bus.uow)
86 return jsonify(result), 200
88 @app.route(apibase + "/resourcePools/<resourcePoolID>/resources",
89 methods=["POST", "PUT", "PATCH", "DELETE"])
90 def resource_not_allow(resourcePoolID):
91 return "Method Not Allowed", 405
94 "/resourcePools/<resourcePoolID>/resources/<resourceID>",
96 def resources_one(resourcePoolID, resourceID):
97 result = ocloud_view.resource_one(resourceID, bus.uow)
100 return jsonify(result), 200
103 "/resourcePools/<resourcePoolID>/resources/<resourceID>",
104 methods=["POST", "PUT", "PATCH", "DELETE"])
105 def resource_one_not_allow(resourcePoolID, resourceID):
106 return "Method Not Allowed", 405
108 # ---------- DeploymentManagers ---------- #
110 @app.route(apibase + "/deploymentManagers", methods=["GET"])
111 def deployment_managers():
112 result = ocloud_view.deployment_managers(bus.uow)
113 return jsonify(result), 200
115 @app.route(apibase + "/deploymentManagers",
116 methods=["POST", "PUT", "PATCH", "DELETE"])
117 def deployment_managers_not_allow():
118 return "Method Not Allowed", 405
120 @app.route(apibase + "/deploymentManagers/<deploymentManagerID>",
122 def deployment_manager_one(deploymentManagerID):
123 result = ocloud_view.deployment_manager_one(
124 deploymentManagerID, bus.uow)
127 return jsonify(result), 200
129 @app.route(apibase + "/deploymentManagers/<deploymentManagerID>",
130 methods=["POST", "PUT", "PATCH", "DELETE"])
131 def deployment_manager_one_not_allow(deploymentManagerID):
132 return "Method Not Allowed", 405