1 # Copyright 2017 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.
17 from django.http import HttpResponse
18 from django.views.decorators.csrf import csrf_exempt
20 from rest_framework import status
22 from multivimbroker.pub.utils.restcall import req_by_msb
23 from multivimbroker.pub.msapi.extsys import get_vim_by_id
25 logger = logging.getLogger(__name__)
29 def route(request, vimid=''):
30 """ get vim info from vimid from local cache first
31 and then to ESR if cache miss
34 status_code = status.HTTP_200_OK
36 vim = get_vim_by_id(vimid)
38 # if vim type is openstack, use latest "newton" version as default
39 if vim["type"] == "openstack":
40 vim["type"] = "multivim-newton"
42 route_uri = re.sub('multivim', vim["type"], request.get_full_path())
43 retcode, content, status_code = \
44 req_by_msb(route_uri, request.method, request.body)
46 # Execptions are handled within req_by_msb
47 logger.error("Status code is %s, detail is %s.",
49 except Exception as e:
51 status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
52 return HttpResponse(content, status_code)