Add hardware type for Ampere Hawk server
[ta/hw-detector.git] / src / hw_detector / hw_detect_lib.py
1 # Copyright 2019 Nokia
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 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 import hw_detector.hw_utils as hw_utils
16
17 def get_local_hw_type():
18     return hw_utils.get_type()
19
20 def get_hw_type(ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level='ADMINISTRATOR', detect_virtual=True):
21     return hw_utils.get_type(ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level, detect_virtual)
22
23 def get_os_hd(hw_type):
24     return hw_utils.os_hd(hw_type)
25
26 def get_hd_with_usage(hw_type, hd_type):
27     return hw_utils.hd_with_type(hw_type, hd_type)
28
29 def get_local_os_hd():
30     return get_os_hd(get_local_hw_type())
31
32 def get_local_osd_hd():
33     return get_hd_with_usage(get_local_hw_type(), 'osd')
34
35 def get_remote_os_hd(ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level='ADMINISTRATOR', detect_virtual=True):
36     return get_os_hd(get_hw_type(ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level, detect_virtual))
37
38 def get_vendor(hw_type):
39     return hw_utils.get_vendor(hw_type)
40
41 def get_product_family(hw_type):
42     return hw_utils.get_product_family(hw_type)
43
44 def _populate_data(hw_type, data_source, ipmi_addr=None, ipmi_user=None, ipmi_pass=None, ipmi_priv_level='ADMINISTRATOR', detect_virtual=True):
45     data = {}
46     data['hw_type'] = hw_type
47     data['os_hd'] = get_os_hd(hw_type)
48     data['osd_hd'] = get_hd_with_usage(hw_type, 'osd')
49     data['vendor'] = get_vendor(hw_type)
50     data['product_family'] = get_product_family(hw_type)
51     data['info'] = hw_utils.get_info(ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level, detect_virtual)
52     data['data_source'] = data_source
53     if data_source == 'remote':
54         data['ipmi_addr'] = ipmi_addr
55         data['ipmi_user'] = ipmi_user
56         data['ipmi_pass'] = ipmi_pass
57         data['ipmi_priv_level'] = ipmi_priv_level
58     return data
59
60 def get_local_hw_data():
61     hw_type = get_local_hw_type()
62     return _populate_data(hw_type, 'local')
63
64 def get_hw_data(ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level='ADMINISTRATOR', detect_virtual=True):
65     hw_type = get_hw_type(ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level, detect_virtual)
66     return _populate_data(hw_type, 'remote', ipmi_addr, ipmi_user, ipmi_pass, ipmi_priv_level, detect_virtual)