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.
15 import multivimbroker.pub.exceptions as exceptions
16 from multivimbroker.pub.msapi.extsys import get_vim_by_id
20 return inspect.stack()[1][3]
23 # Which headers are hop-by-hop headers by default
24 HOP_BY_HOP = ['connection', 'keep-alive', 'proxy-authenticate',
25 'proxy-authorization', 'te', 'trailers',
26 'transfer-encoding', 'upgrade']
29 def getHeadersKeys(response):
31 hopbyhop.extend([x.strip()
32 for x in response.get('connection', '').split(',')])
33 return [header for header in response.keys() if header not in hopbyhop]
36 def findMultivimDriver(vim=None):
38 if vim and vim["type"] == "openstack":
39 if vim["version"] == "kilo":
40 multivimdriver = "multivim-kilo"
41 elif vim["version"] == "newton":
42 multivimdriver = "multivim-newton"
44 # if vim type is openstack, use latest "newton" version as default
45 multivimdriver = "multivim-newton"
46 elif vim and vim["type"] == "vmware":
47 multivimdriver = "multivim-vio"
49 raise exceptions.NotFound("Not support VIM type")
53 def getMultivimDriver(vimid, full_path=""):
56 vim = get_vim_by_id(vimid)
57 if vim["type"] and vim["version"]:
60 multivimdriver = findMultivimDriver(vim=vim)
61 return re.sub(multivim, multivimdriver, full_path)