1 # Copyright (c) 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:
6 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 import multivimbroker.pub.exceptions as exceptions
18 from multivimbroker.pub.msapi.extsys import get_vim_by_id
22 return inspect.stack()[1][3]
25 # Which headers are hop-by-hop headers by default
26 HOP_BY_HOP = ['connection', 'keep-alive', 'proxy-authenticate',
27 'proxy-authorization', 'te', 'trailers',
28 'transfer-encoding', 'upgrade']
31 def getHeadersKeys(response):
33 hopbyhop.extend([x.strip()
34 for x in response.get('connection', '').split(',')])
35 return [header for header in response.keys() if header not in hopbyhop]
38 def findMultivimDriver(vim=None):
39 json_file = os.path.join(os.path.dirname(__file__),
40 '../config/provider-plugin.json')
41 with open(json_file, "r") as f:
42 plugins = json.load(f)
43 if not vim or vim.get("type") not in plugins.keys():
44 raise exceptions.NotFound("Not support VIM type")
45 plugin = plugins[vim["type"]]
46 if vim.get("version") in plugin["versions"].keys():
47 return plugin["versions"][vim["version"]]["provider_plugin"]
48 return plugin["provider_plugin"]
51 def getMultivimDriver(vimid, full_path=""):
52 multcloud = "multicloud"
53 vim = get_vim_by_id(vimid)
54 multclouddriver = findMultivimDriver(vim=vim)
55 return re.sub(multcloud, multclouddriver, full_path)