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
18 return inspect.stack()[1][3]
23 # Which headers are hop-by-hop headers by default
24 HOP_BY_HOP = ['connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization', 'te', 'trailers', 'transfer-encoding', 'upgrade']
25 def getHeadersKeys(response):
27 hopbyhop.extend([x.strip() for x in response.get('connection', '').split(',')])
28 return [header for header in response.keys() if header not in hopbyhop]
32 def findMultivimDriver(vim=None):
34 if vim and vim["type"] == "openstack":
35 if vim["version"] == "kilo":
36 multivimdriver = "multivim-kilo"
37 elif vim["version"] == "newton":
38 multivimdriver = "multivim-newton"
40 # if vim type is openstack, use latest "newton" version as default
41 multivimdriver = "multivim-newton"
42 elif vim and vim["type"] == "vmware":
43 multivimdriver = "multivim-vio"
45 raise exceptions.NotFound("Not support VIM type")
50 def getMultivimDriver(vimid,full_path=""):
53 vim = get_vim_by_id(vimid)
54 if vim["type"] and vim["version"]:
57 multivimdriver = findMultivimDriver(vim=vim)
58 return re.sub(multivim, multivimdriver, full_path)