add pep8 check
[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
18
19 def fun_name():
20     return inspect.stack()[1][3]
21
22
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']
27
28
29 def getHeadersKeys(response):
30     hopbyhop = HOP_BY_HOP
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]
34
35
36 def findMultivimDriver(vim=None):
37
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"
43         else:
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"
48     else:
49         raise exceptions.NotFound("Not support VIM type")
50     return multivimdriver
51
52
53 def getMultivimDriver(vimid, full_path=""):
54
55     multivim = "multivim"
56     vim = get_vim_by_id(vimid)
57     if vim["type"] and vim["version"]:
58         pass
59
60     multivimdriver = findMultivimDriver(vim=vim)
61     return re.sub(multivim, multivimdriver, full_path)