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
|
# Copyright (c) 2017-2018 VMware, Inc.
#
# 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.
import logging
from rest_framework import status
from rest_framework.response import Response
from vio.swagger.views.proxyplugin.httpclient import BaseClient
from vio.pub.config.config import MSB_SERVICE_PORT, MSB_SERVICE_IP
logger = logging.getLogger(__name__)
MSB_ADDRESS = MSB_SERVICE_IP + ":" + MSB_SERVICE_PORT + "/api"
class NetworkVersionLink(BaseClient):
serverType = 'neutron'
def get(self, request, vimid):
(url, headers, _) = self.buildRequest(request, vimid, tail=None,
method="GET")
try:
res = self._request(url, method="GET", headers=headers)
if res.status_code != status.HTTP_200_OK:
return Response(data={"error": res.data},
status=res.status_code)
res = res.data
# replace neutron endpoint url with multicloud
# endpoint url.
for item in res['versions']:
version = item['id']
item['links'][0]['href'] = \
"http://" + MSB_ADDRESS + "/multicloud-vio/v0/" \
+ vimid + "/neutron/" + version + "/"
except Exception as e:
logging.exception("error %s" % e)
return Response(data={"error": str(e)},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data=res, status=status.HTTP_200_OK)
class NetworkVersionLinkV1(NetworkVersionLink):
serverType = 'neutron'
def get(self, request, cloud_owner, cloud_region):
return super(NetworkVersionLinkV1, self).get(
request, cloud_owner + "_" + cloud_region)
class NetWorkServer(BaseClient):
serverType = "neutron"
def get(self, request, vimid, other=None):
(url, headers, _) = self.buildRequest(request, vimid, tail=other,
method="GET")
return self._request(url, method="GET", headers=headers)
def post(self, request, vimid, other):
return self.send(request=request, method="POST",
vimid=vimid, other=other)
def patch(self, request, vimid, other):
return self.send(request=request, method="PATCH",
vimid=vimid, other=other)
def put(self, request, vimid, other):
return self.send(request=request, method="PUT",
vimid=vimid, other=other)
def delete(self, request, vimid, other):
return self.send(request=request, method="DELETE",
vimid=vimid, other=other)
class NetWorkServerV1(NetWorkServer):
serverType = 'neutron'
def get(self, request, cloud_owner, cloud_region, other=None):
return super(NetWorkServerV1, self).get(
request, cloud_owner + "_" + cloud_region, other)
def post(self, request, cloud_owner, cloud_region, other):
return super(NetWorkServerV1, self).post(
request, cloud_owner + "_" + cloud_region, other)
def patch(self, request, cloud_owner, cloud_region, other):
return super(NetWorkServerV1, self).patch(
request, cloud_owner + "_" + cloud_region, other)
def put(self, request, cloud_owner, cloud_region, other):
return super(NetWorkServerV1, self).put(
request, cloud_owner + "_" + cloud_region, other)
def delete(self, request, cloud_owner, cloud_region, other):
return super(NetWorkServerV1, self).delete(
request, cloud_owner + "_" + cloud_region, other)
|