1 # Copyright (c) 2017 Wind River Systems, Inc.
2 # Copyright (c) 2017-2018 VMware, Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # 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.
18 import multivimbroker.pub.exceptions as exceptions
19 from multivimbroker.pub.msapi.extsys import get_vim_by_id
23 return inspect.stack()[1][3]
26 # Which headers are hop-by-hop headers by default
27 HOP_BY_HOP = ['connection', 'keep-alive', 'proxy-authenticate',
28 'proxy-authorization', 'te', 'trailers',
29 'transfer-encoding', 'upgrade']
32 def getHeadersKeys(response):
34 hopbyhop.extend([x.strip()
35 for x in response.get('connection', '').split(',')])
36 return [header for header in response.keys() if header not in hopbyhop]
39 # trim out 'HTTP_' prefix part and replace "_" wiht "-".
40 def originHeaders(request):
41 regex = re.compile('^HTTP_')
42 return dict((regex.sub('', header).replace("_", "-"), value)
43 for (header, value) in request.META.items()
44 if header.startswith('HTTP_'))
47 def findMultivimDriver(vim=None):
48 json_file = os.path.join(os.path.dirname(__file__),
49 '../config/provider-plugin.json')
50 with open(json_file, "r") as f:
51 plugins = json.load(f)
52 if not vim or vim.get("type") not in plugins.keys():
53 raise exceptions.NotFound("Not support VIM type")
54 plugin = plugins[vim["type"]]
55 if vim.get("version") in plugin["versions"].keys():
56 return plugin["versions"][vim["version"]]["provider_plugin"]
57 return plugin["provider_plugin"]
60 def getMultivimDriver(vimid, full_path=""):
61 multcloud = "multicloud"
62 vim = get_vim_by_id(vimid)
63 multclouddriver = findMultivimDriver(vim=vim)
64 return re.sub(multcloud, multclouddriver, full_path)
68 # Fix here unless we have plugin registry
69 json_file = os.path.join(os.path.dirname(__file__),
70 '../config/provider-plugin.json')
71 with open(json_file, "r") as f:
72 plugins = json.load(f)
74 for k, v in plugins.items():
76 item["vim_type"] = v.get("vim_type")
77 item["versions"] = [k for k in v.get('versions', {})]