X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=ta%2Fhw-detector.git;a=blobdiff_plain;f=src%2Fhw_detector%2Fhw_type.py;fp=src%2Fhw_detector%2Fhw_type.py;h=45f81c1ef8296273a35188989294bfedf31f15b8;hp=0000000000000000000000000000000000000000;hb=16a99da97d1b95a14514ab8e7c0f75e43ba8c184;hpb=d772f6a70748051542c72cbcd9098f40a258cc2d diff --git a/src/hw_detector/hw_type.py b/src/hw_detector/hw_type.py new file mode 100644 index 0000000..45f81c1 --- /dev/null +++ b/src/hw_detector/hw_type.py @@ -0,0 +1,53 @@ +# Copyright 2019 Nokia + +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import re + +class HWType(object): + def __init__(self): + self.by_path = '/dev/disk/by-path' + self.matches = {} + self.hwtype = 'Generic' + self.vendor_name = 'Generic' + self.productfamily = 'Unknown' + self.disk_map = {'os' : '', 'osd': []} + + def get_disk_by_name(self, name): + return self.disk_map.get(name, None) + + @property + def vendor(self): + return self.vendor_name + + @property + def product_family(self): + return self.productfamily + + @property + def hw_type(self): + return self.hwtype + + def match(self, info): + criteria_matches = 0 + for key, value in self.matches.iteritems(): + #Exact match has more value than regexp + if info.get(key, '') == value: + criteria_matches += 10 + elif re.match(value, info.get(key, '')): + criteria_matches += 1 + else: + criteria_matches = 0 + break + + return criteria_matches