Seed code for hw-detector
[ta/hw-detector.git] / src / hw_detector / hw_type.py
diff --git a/src/hw_detector/hw_type.py b/src/hw_detector/hw_type.py
new file mode 100644 (file)
index 0000000..45f81c1
--- /dev/null
@@ -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