Add hardware type for Ampere Hawk server
[ta/hw-detector.git] / src / hw_detector / hw_type.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 re
16
17 class HWType(object):
18     def __init__(self):
19         self.by_path = '/dev/disk/by-path'
20         self.matches = {}
21         self.hwtype = 'Generic'
22         self.vendor_name = 'Generic'
23         self.productfamily = 'Unknown'
24         self.disk_map = {'os' : '', 'osd': []}
25
26     def get_disk_by_name(self, name):
27         return self.disk_map.get(name, None)
28
29     @property
30     def vendor(self):
31         return self.vendor_name
32
33     @property
34     def product_family(self):
35         return self.productfamily
36
37     @property
38     def hw_type(self):
39         return self.hwtype
40
41     def match(self, info):
42         criteria_matches = 0
43         for key, value in self.matches.iteritems():
44             #Exact match has more value than regexp
45             if info.get(key, '') == value:
46                 criteria_matches += 10
47             elif re.match(value, info.get(key, '')):
48                 criteria_matches += 1
49             else:
50                 criteria_matches = 0
51                 break
52
53         return criteria_matches