07606bfd200a60ae11f01a1e705f5c555c657c8c
[multicloud/framework.git] / multivimbroker / multivimbroker / pub / utils / syscomm.py
1 # Copyright (c) 2017 Wind River Systems, Inc.
2 #
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
7 #
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.
11
12 import inspect
13 import re
14
15 import multivimbroker.pub.exceptions as  exceptions
16 from multivimbroker.pub.msapi.extsys import get_vim_by_id
17 def fun_name():
18     return inspect.stack()[1][3]
19
20
21
22
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):
26     hopbyhop = HOP_BY_HOP
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]
29
30
31
32 def findMultivimDriver(vim=None):
33
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"
39         else:
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"
44     else:
45         raise  exceptions.NotFound("Not support VIM type")
46     return  multivimdriver
47
48
49
50 def  getMultivimDriver(vimid,full_path=""):
51
52     multivim = "multivim"
53     vim = get_vim_by_id(vimid)
54     if vim["type"] and vim["version"]:
55         pass
56
57     multivimdriver = findMultivimDriver(vim=vim)
58     return re.sub(multivim, multivimdriver, full_path)