Setup micro-service of multivim broker
[multicloud/framework.git] / multivimbroker / multivimbroker / swagger / views.py
1 # Copyright (c) 2017 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 #       http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
12 import json
13 import logging
14 import os
15 import traceback
16
17 from rest_framework import status
18 from rest_framework.response import Response
19 from rest_framework.views import APIView
20
21 from multivimbroker.pub.exceptions import VimBrokerException
22
23 logger = logging.getLogger(__name__)
24
25
26 class SwaggerJsonView(APIView):
27     def get(self, request):
28         json_file = os.path.join(os.path.dirname(__file__), 'multivim.flavor.swagger.json')
29         f = open(json_file)
30         json_data = json.JSONDecoder().decode(f.read())
31         f.close()
32         json_file = os.path.join(os.path.dirname(__file__), 'multivim.image.swagger.json')
33         f = open(json_file)
34         json_data_temp = json.JSONDecoder().decode(f.read())
35         f.close()
36         json_data["paths"].update(json_data_temp["paths"])
37         json_data["definitions"].update(json_data_temp["definitions"])
38         json_file = os.path.join(os.path.dirname(__file__), 'multivim.network.swagger.json')
39         f = open(json_file)
40         json_data_temp = json.JSONDecoder().decode(f.read())
41         f.close()
42         json_data["paths"].update(json_data_temp["paths"])
43         json_data["definitions"].update(json_data_temp["definitions"])
44         json_file = os.path.join(os.path.dirname(__file__), 'multivim.subnet.swagger.json')
45         f = open(json_file)
46         json_data_temp = json.JSONDecoder().decode(f.read())
47         f.close()
48         json_data["paths"].update(json_data_temp["paths"])
49         json_data["definitions"].update(json_data_temp["definitions"])
50         json_file = os.path.join(os.path.dirname(__file__), 'multivim.server.swagger.json')
51         f = open(json_file)
52         json_data_temp = json.JSONDecoder().decode(f.read())
53         f.close()
54         json_data["paths"].update(json_data_temp["paths"])
55         json_data["definitions"].update(json_data_temp["definitions"])
56         json_file = os.path.join(os.path.dirname(__file__), 'multivim.volume.swagger.json')
57         f = open(json_file)
58         json_data_temp = json.JSONDecoder().decode(f.read())
59         f.close()
60         json_data["paths"].update(json_data_temp["paths"])
61         json_data["definitions"].update(json_data_temp["definitions"])
62         json_file = os.path.join(os.path.dirname(__file__), 'multivim.vport.swagger.json')
63         f = open(json_file)
64         json_data_temp = json.JSONDecoder().decode(f.read())
65         f.close()
66         json_data["paths"].update(json_data_temp["paths"])
67         json_data["definitions"].update(json_data_temp["definitions"])
68         json_file = os.path.join(os.path.dirname(__file__), 'multivim.tenant.swagger.json')
69         f = open(json_file)
70         json_data_temp = json.JSONDecoder().decode(f.read())
71         f.close()
72         json_data["paths"].update(json_data_temp["paths"])
73         json_data["definitions"].update(json_data_temp["definitions"])
74         json_file = os.path.join(os.path.dirname(__file__), 'multivim.host.swagger.json')
75         f = open(json_file)
76         json_data_temp = json.JSONDecoder().decode(f.read())
77         f.close()
78         json_data["paths"].update(json_data_temp["paths"])
79         json_data["definitions"].update(json_data_temp["definitions"])
80         json_file = os.path.join(os.path.dirname(__file__), 'multivim.limit.swagger.json')
81         f = open(json_file)
82         json_data_temp = json.JSONDecoder().decode(f.read())
83         f.close()
84         json_data["paths"].update(json_data_temp["paths"])
85         json_data["definitions"].update(json_data_temp["definitions"])
86         return Response(json_data)
87