Add: flask api include resource type, resource pool, resource and deployment manager
[pti/o2.git] / o2ims / views / ocloud_route.py
1 # Copyright (C) 2021 Wind River Systems, Inc.
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 from flask import jsonify
16
17 from o2ims import config
18 from o2ims.views import ocloud_view
19
20
21 apibase = config.get_o2ims_api_base()
22
23
24 def configure_routes(app, bus):
25
26     # ----------  OClouds ---------- #
27     @app.route(apibase, methods=["GET"])
28     def oclouds():
29         result = ocloud_view.oclouds(bus.uow)
30         return jsonify(result), 200
31
32     # ----------  ResourceTypes ---------- #
33
34     @app.route(apibase + "/resourceTypes", methods=["GET"])
35     def resource_types():
36         result = ocloud_view.resource_types(bus.uow)
37         return jsonify(result), 200
38
39     @app.route(apibase + "/resourceTypes", methods=["POST", "PUT", "PATCH",
40                                                     "DELETE"])
41     def resource_types_not_allow():
42         return "Method Not Allowed", 405
43
44     @app.route(apibase + "/resourceTypes/<resourceTypeID>", methods=["GET"])
45     def resource_types_one(resourceTypeID):
46         result = ocloud_view.resource_type_one(resourceTypeID, bus.uow)
47         if result is None:
48             return "", 200
49         return jsonify(result), 200
50
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
55
56     # ----------  ResourcePools ---------- #
57
58     @app.route(apibase + "/resourcePools", methods=["GET"])
59     def resource_pools():
60         result = ocloud_view.resource_pools(bus.uow)
61         return jsonify(result), 200
62
63     @app.route(apibase + "/resourcePools", methods=["POST", "PUT", "PATCH",
64                                                     "DELETE"])
65     def resource_pools_not_allow():
66         return "Method Not Allowed", 405
67
68     @app.route(apibase + "/resourcePools/<resourcePoolID>", methods=["GET"])
69     def resource_pools_one(resourcePoolID):
70         result = ocloud_view.resource_pool_one(resourcePoolID, bus.uow)
71         if result is None:
72             return "", 200
73         return jsonify(result), 200
74
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
79
80     # ----------  Resources ---------- #
81
82     @app.route(apibase + "/resourcePools/<resourcePoolID>/resources",
83                methods=["GET"])
84     def resources(resourcePoolID):
85         result = ocloud_view.resources(resourcePoolID, bus.uow)
86         return jsonify(result), 200
87
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
92
93     @app.route(apibase +
94                "/resourcePools/<resourcePoolID>/resources/<resourceID>",
95                methods=["GET"])
96     def resources_one(resourcePoolID, resourceID):
97         result = ocloud_view.resource_one(resourceID, bus.uow)
98         if result is None:
99             return "", 200
100         return jsonify(result), 200
101
102     @app.route(apibase +
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
107
108     # ----------  DeploymentManagers ---------- #
109
110     @app.route(apibase + "/deploymentManagers", methods=["GET"])
111     def deployment_managers():
112         result = ocloud_view.deployment_managers(bus.uow)
113         return jsonify(result), 200
114
115     @app.route(apibase + "/deploymentManagers",
116                methods=["POST", "PUT", "PATCH", "DELETE"])
117     def deployment_managers_not_allow():
118         return "Method Not Allowed", 405
119
120     @app.route(apibase + "/deploymentManagers/<deploymentManagerID>",
121                methods=["GET"])
122     def deployment_manager_one(deploymentManagerID):
123         result = ocloud_view.deployment_manager_one(
124             deploymentManagerID, bus.uow)
125         if result is None:
126             return "", 200
127         return jsonify(result), 200
128
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