--- /dev/null
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
--- /dev/null
+# 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.
+
+Name: hw-detector
+Version: %{_version}
+Release: 1%{?dist}
+Summary: Hardware detector
+Group: Nokia
+License: %{_platform_licence}
+Source0: %{name}-%{version}.tar.gz
+Vendor: %{_platform_vendor}
+
+Requires: python
+BuildRequires: python
+BuildRequires: python-setuptools
+
+%description
+Hardware detector for different hardware types
+
+%prep
+%autosetup
+
+%build
+
+%install
+rm -rf $RPM_BUILD_ROOT
+mkdir -p %{buildroot}/%{_python_site_packages_path}/hw_detector
+
+cd src && python setup.py install --root %{buildroot} --no-compile --install-purelib %{_python_site_packages_path} --install-scripts /usr/local/bin && cd -
+
+%files
+%defattr(0755,root,root)
+%{_python_site_packages_path}/hw_detector*
+
+%pre
+
+%post
+
+%postun
--- /dev/null
+# 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.
--- /dev/null
+#!/usr/bin/python
+
+# 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 sys
+import argparse
+import pprint
+import hw_detector.hw_detect_lib as hw
+from hw_detector.hw_exception import HWException
+
+def dump_data(data):
+ pp = pprint.PrettyPrinter(indent=4)
+ pp.pprint(data)
+
+def local_dump(args):
+ data = hw.get_local_hw_data()
+ dump_data(data)
+
+def remote_dump(args):
+ ip = args.ip
+ user = args.user
+ passw = args.passwd
+ try:
+ data = hw.get_hw_data(ip, user, passw, False)
+ except HWException as e:
+ data = "Detect failed: {}".format(str(e))
+ dump_data(data)
+
+def main():
+ parser = argparse.ArgumentParser(description='HW detector cli')
+ subparsers = parser.add_subparsers()
+ local_group = subparsers.add_parser('local')
+ remote_group = subparsers.add_parser('remote')
+
+ remote_group.add_argument('--ip', type=str, required=True, help='IP')
+ remote_group.add_argument('--user', type=str, required=True, help='User')
+ remote_group.add_argument('--passwd', type=str, required=True, help='Password')
+
+ local_group.set_defaults(func=local_dump)
+ remote_group.set_defaults(func=remote_dump)
+
+ args = parser.parse_args(sys.argv[1:])
+ args.func(args)
+if __name__ == '__main__':
+ main()
--- /dev/null
+# 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 hw_detector.hw_utils as hw_utils
+
+def get_local_hw_type():
+ return hw_utils.get_type()
+
+def get_hw_type(ipmi_addr, ipmi_user, ipmi_pass, detect_virtual=True):
+ return hw_utils.get_type(ipmi_addr, ipmi_user, ipmi_pass, detect_virtual)
+
+def get_os_hd(hw_type):
+ return hw_utils.os_hd(hw_type)
+
+def get_hd_with_usage(hw_type, hd_type):
+ return hw_utils.hd_with_type(hw_type, hd_type)
+
+def get_local_os_hd():
+ return get_os_hd(get_local_hw_type())
+
+def get_local_osd_hd():
+ return get_hd_with_usage(get_local_hw_type(), 'osd')
+
+def get_remote_os_hd(ipmi_addr, ipmi_user, ipmi_pass, detect_virtual=True):
+ return get_os_hd(get_hw_type(ipmi_addr, ipmi_user, ipmi_pass, detect_virtual))
+
+def get_vendor(hw_type):
+ return hw_utils.get_vendor(hw_type)
+
+def get_product_family(hw_type):
+ return hw_utils.get_product_family(hw_type)
+
+def _populate_data(hw_type, data_source, ipmi_addr=None, ipmi_user=None, ipmi_pass=None, detect_virtual=True):
+ data = {}
+ data['hw_type'] = hw_type
+ data['os_hd'] = get_os_hd(hw_type)
+ data['osd_hd'] = get_hd_with_usage(hw_type, 'osd')
+ data['vendor'] = get_vendor(hw_type)
+ data['product_family'] = get_product_family(hw_type)
+ data['info'] = hw_utils.get_info(ipmi_addr, ipmi_user, ipmi_pass, detect_virtual)
+ data['data_source'] = data_source
+ if data_source == 'remote':
+ data['ipmi_addr'] = ipmi_addr
+ data['ipmi_user'] = ipmi_user
+ data['ipmi_pass'] = ipmi_pass
+ return data
+
+def get_local_hw_data():
+ hw_type = get_local_hw_type()
+ return _populate_data(hw_type, 'local')
+
+def get_hw_data(ipmi_addr, ipmi_user, ipmi_pass, detect_virtual=True):
+ hw_type = get_hw_type(ipmi_addr, ipmi_user, ipmi_pass, detect_virtual)
+ return _populate_data(hw_type, 'remote', ipmi_addr, ipmi_user, ipmi_pass, detect_virtual)
--- /dev/null
+# 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.
+
+class HWException(Exception):
+ pass
--- /dev/null
+# 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 subprocess
+import os
+
+from hw_detector.hw_exception import HWException
+
+def get_ipmi_info(ipmi_addr, ipmi_user, ipmi_pass):
+ command = "ipmitool -I lanplus -H %s -U %s -P %s fru print 0" % (ipmi_addr, ipmi_user, ipmi_pass)
+ info = ipmi_info(command)
+
+ command = "ipmitool -I lanplus -H %s -U %s -P %s lan print" % (ipmi_addr, ipmi_user, ipmi_pass)
+ info.update(ipmi_info(command))
+
+ return info
+
+def _load_ipmi_drivers():
+ with open(os.devnull, 'w') as devnull:
+ subprocess.call('modprobe ipmi_msghandler', stderr=devnull, shell=True)
+ subprocess.call('modprobe ipmi_devintf', stderr=devnull, shell=True)
+ subprocess.call('modprobe ipmi_si', stderr=devnull, shell=True)
+
+def get_local_ipmi_info():
+ _load_ipmi_drivers()
+ info = ipmi_info("ipmitool fru print 0")
+ info.update(ipmi_info("ipmitool lan print"))
+ return info
+
+def ipmi_info(command):
+ out = None
+ p = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ out, _ = p.communicate()
+
+ if p.returncode:
+ raise HWException(out)
+
+ info = {}
+ for line in out.split('\n'):
+ spl = line.find(':')
+ if spl == -1:
+ continue
+ else:
+ key = line[0:spl].strip()
+ if key == '':
+ continue
+ info[line[0:spl].strip()] = line[spl+1:].strip()
+ return info
--- /dev/null
+# 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
--- /dev/null
+# 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 os
+import sys
+import inspect
+import hw_detector.hw_type as hwbase_type
+
+def _import_classes(module_name, module_type):
+ classes = []
+ try:
+ __import__(module_name)
+ except ImportError as e:
+ print("Failed import in {0} skipping {1}".format(module_name, e))
+ return None
+ module = sys.modules[module_name]
+ for obj_name in dir(module):
+ # Skip objects that are meant to be private.
+ if obj_name.startswith('_'):
+ continue
+ elif obj_name == module_type.__name__:
+ continue
+ itm = getattr(module, obj_name)
+ if inspect.isclass(itm) and issubclass(itm, module_type):
+ classes.append(itm)
+ return classes
+
+def get_libs(directory, module_type):
+ classes = []
+ if directory not in sys.path:
+ sys.path.append(directory)
+
+ for fname in os.listdir(directory):
+ root, ext = os.path.splitext(fname)
+ if ext != '.py' or root == '__init__':
+ continue
+ module_name = "%s" % (root)
+ for iclass in _import_classes(module_name, module_type):
+ classes.append(iclass())
+ return classes
+
+types = get_libs('%s/hw_types' % os.path.dirname(hwbase_type.__file__), hwbase_type.HWType)
--- /dev/null
+# 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.
+
+from hw_detector.hw_type import HWType
+
+class HWDELL(HWType):
+ def __init__(self):
+ super(HWDELL, self).__init__()
+ self.matches = {'Product Manufacturer' : 'DELL'}
+ self.hwtype = 'DELL'
+ self.vendor_name = 'DELL'
+ self.productfamily = 'DELL'
+ self.disk_map = {'os': '/dev/sda',
+ 'osd' : ['/dev/sdb',
+ '/dev/sdc',
+ '/dev/sdd'
+ ]
+ }
+
--- /dev/null
+# 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.
+
+from hw_detector.hw_type import HWType
+
+
+class HWHP(HWType):
+ def __init__(self):
+ super(HWHP, self).__init__()
+ self.matches = {'Product Manufacturer' : 'HP'}
+ self.hwtype = 'HP'
+ self.vendor_name = 'HP'
+ self.productfamily = 'HP'
+ self.disk_map = {'os': '/dev/sda',
+ 'osd' : ['/dev/sdb',
+ '/dev/sdc',
+ '/dev/sdd'
+ ]
+ }
+
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWOE19(NokiaHWType):
+ def __init__(self):
+ super(HWOE19, self).__init__()
+ self.matches = {'Board Product' : 'AE-SER1U-A/AF1801.*'}
+ self.hwtype = 'OE19'
+ self.productfamily = 'OE19'
+ self.disk_map = {'os' : '%s/pci-0000:00:11.5-ata-3.0' %self.by_path,
+ 'osd': ['%s/pci-0000:00:17.0-ata-1.0' %self.by_path,
+ '%s/pci-0000:00:17.0-ata-2.0' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWOE192U(NokiaHWType):
+ def __init__(self):
+ super(HWOE192U, self).__init__()
+ self.matches = {'Board Product' : 'AE-SER2U-A/AF1804.01'}
+ self.hwtype = 'OE192U'
+ self.productfamily = 'OE19'
+ self.disk_map = {'os' : '%s/pci-0000:00:11.5-ata-3' %self.by_path,
+ 'osd': ['%s/pci-0000:00:17.0-ata-1' %self.by_path,
+ '%s/pci-0000:00:17.0-ata-2' %self.by_path,
+ '%s/pci-0000:00:17.0-ata-3' %self.by_path,
+ '%s/pci-0000:00:17.0-ata-4' %self.by_path
+ ]
+ }
+
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWOR17(NokiaHWType):
+ def __init__(self):
+ super(HWOR17, self).__init__()
+ self.matches = {'Board Product' : 'AO-F06G-A'}
+ self.hwtype = 'OR17'
+ self.productfamily = 'HW17'
+ self.disk_map = {'os' : '%s/pci-0000:00:1f.2-ata-1' %self.by_path,
+ 'osd': ['%s/pci-0000:00:1f.2-ata-2' %self.by_path,
+ '%s/pci-0000:00:1f.2-ata-3' %self.by_path,
+ '%s/pci-0000:00:1f.2-ata-4' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWOR18(NokiaHWType):
+ def __init__(self):
+ super(HWOR18, self).__init__()
+ self.matches = {'Board Product' : 'AO-SER2U-AS/AF2115.01'}
+ self.hwtype = 'OR18'
+ self.productfamily = 'OR18'
+ self.disk_map = {'os' : '%s/pci-0000:00:11.5-ata-3' %self.by_path,
+ 'osd': ['%s/pci-0000:00:11.5-ata-5' %self.by_path,
+ '%s/pci-0000:00:11.5-ata-6' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWOR18CORE(NokiaHWType):
+ def __init__(self):
+ super(HWOR18CORE, self).__init__()
+ self.matches = {'Board Product' : 'AO-SER2U-AS/AF2115.01',
+ 'Product Name' : 'Compute', # Misleading but Controller is storage controller
+ 'Product Part Number' : 'HYV-S-NCAC0211010'}
+ self.hwtype = 'OR18CORE'
+ self.productfamily = 'OR18'
+ self.disk_map = {'os' : '%s/pci-0000:00:11.5-ata-5' %self.by_path,
+ 'osd': ['%s/pci-0000:00:11.5-ata-6' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWOR18CORESTORAGE(NokiaHWType):
+ def __init__(self):
+ super(HWOR18CORESTORAGE, self).__init__()
+ self.matches = {'Board Product' : 'AO-SER2U-AS/AF2115.01',
+ 'Product Name' : 'Controller'}
+ self.hwtype = 'OR18CORESTORAGE'
+ self.productfamily = 'OR18'
+ self.disk_map = {'os' : '%s/pci-0000:3b:00.0-scsi-0:2:0:0' %self.by_path,
+ 'osd': ['%s/pci-0000:18:00.0-nvme-1' %self.by_path,
+ '%s/pci-0000:19:00.0-nvme-1' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWRM16(NokiaHWType):
+ def __init__(self):
+ super(HWRM16, self).__init__()
+ self.matches = {'Board Product' : 'AR-D51B1U1-A (dual 1G LoM)'}
+ self.hwtype = 'RM16'
+ self.productfamily = 'HW17' #Lie... This has the same BMC
+ self.disk_map = {'os' : '%s/pci-0000:00:1f.2-ata-3' %self.by_path,
+ 'osd': ['%s/pci-0000:00:1f.2-ata-4' %self.by_path,
+ '%s/pci-0000:00:1f.2-ata-5' %self.by_path,
+ '%s/pci-0000:00:1f.2-ata-6' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWRM17(NokiaHWType):
+ def __init__(self):
+ super(HWRM17, self).__init__()
+ self.matches = {'Board Product' : 'S2BP-MB (dual 10G LoM)'}
+ self.hwtype = 'RM17'
+ self.productfamily = 'HW17'
+ self.disk_map = {'os' : '%s/pci-0000:81:00.0-sas-phy0-lun-0' %self.by_path,
+ 'osd': ['%s/pci-0000:81:00.0-sas-phy1-lun-0' %self.by_path,
+ '%s/pci-0000:81:00.0-sas-phy2-lun-0' %self.by_path,
+ '%s/pci-0000:81:00.0-sas-phy3-lun-0' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.hw_types.hw_rm17 import HWRM17
+
+class HWRM17COMBO(HWRM17):
+ def __init__(self):
+ super(HWRM17COMBO, self).__init__()
+ self.matches = {'Board Product' : 'AR-D51BP10-A (dual 10G LoM)'}
+ self.hwtype = 'RM17COMBO'
--- /dev/null
+# 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.
+
+from hw_detector.hw_types.hw_rm17 import HWRM17
+
+class HWRM17COMBO(HWRM17):
+ def __init__(self):
+ super(HWRM17COMBO, self).__init__()
+ self.matches = {'Board Product' : 'AR-D51BP1-A (dual 1G LoM)'}
+ self.hwtype = 'RM17COMBO1G'
--- /dev/null
+# 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.
+
+from hw_detector.hw_types.hw_rm16 import HWRM16
+
+class HWRM17GEN(HWRM16):
+ def __init__(self):
+ super(HWRM17GEN, self).__init__()
+ self.matches = {'Board Product' : 'AR-D51B1U.*'}
+ self.hwtype = 'RM17GEN'
--- /dev/null
+# 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.
+
+from hw_detector.hw_types.hw_rm17 import HWRM17
+
+class HWRM17GENSAS(HWRM17):
+ def __init__(self):
+ super(HWRM17GENSAS, self).__init__()
+ self.matches = {'Board Product' : 'AR-D51BP10.*'}
+ self.hwtype = 'RM17GENSAS'
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWRM17SAS(NokiaHWType):
+ def __init__(self):
+ super(HWRM17SAS, self).__init__()
+ self.matches = {'Board Product' : 'S2BP-MB (dual 1G LoM)'}
+ self.hwtype = 'RM17-sas'
+ self.productfamily = 'HW17'
+ self.disk_map = {'os' : '%s/pci-0000:81:00.0-scsi-0:1:0:0' %self.by_path,
+ 'osd': ['%s/pci-0000:81:00.0-sas-phy2-lun-0' %self.by_path,
+ '%s/pci-0000:81:00.0-sas-phy3-lun-0' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.nokia_hw_type import NokiaHWType
+
+class HWRM18(NokiaHWType):
+ def __init__(self):
+ super(HWRM18, self).__init__()
+ self.matches = {'Board Product' : 'AR-D52B1-D/AF0315.01'}
+ self.hwtype = 'RM18'
+ self.productfamily = 'RM18'
+ self.disk_map = {'os' : '%s/pci-0000:00:11.5-ata-3' %self.by_path,
+ 'osd': ['%s/pci-0000:00:11.5-ata-4' %self.by_path,
+ '%s/pci-0000:00:11.5-ata-5' %self.by_path,
+ '%s/pci-0000:00:11.5-ata-6' %self.by_path
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.hw_type import HWType
+
+
+class HWUnknown(HWType):
+ def __init__(self):
+ super(HWUnknown, self).__init__()
+ self.matches = {'Board Product' : 'Unknown'} # Not used
+ self.hwtype = 'Unknown'
+ self.disk_map = {'os': '/dev/sda',
+ 'osd' : ['/dev/sdb',
+ '/dev/sdc',
+ '/dev/sdd'
+ ]
+ }
--- /dev/null
+# 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.
+
+from hw_detector.hw_type import HWType
+
+
+class HWVirtual(HWType):
+ def __init__(self):
+ super(HWVirtual, self).__init__()
+ self.matches = {'Board Product' : 'VIRTUAL'} # Not used
+ self.hwtype = 'VIRTUAL'
+ self.disk_map = {'os': '%s/pci-0000:00:0a.0-scsi-0:0:0:0' %self.by_path,
+ 'osd' : ['%s/pci-0000:00:0a.0-scsi-0:0:0:1' %self.by_path,
+ '%s/pci-0000:00:0a.0-scsi-0:0:0:2' %self.by_path,
+ '%s/pci-0000:00:0a.0-scsi-0:0:0:3' %self.by_path
+ ]
+ }
+
--- /dev/null
+# 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 hw_detector.hw_ipmi_lib as hw_ipmi_lib
+import hw_detector.hw_types as hw_types
+
+info = {}
+
+def get_match(info):
+ matches = {}
+
+ for hw in hw_types.types:
+ amount = hw.match(info)
+ if amount != 0:
+ matches[hw.hw_type] = amount
+
+ if matches:
+ return sorted(matches, key=matches.get, reverse=True)[0]
+
+ return 'Unknown'
+
+def get_info(ipmi_addr=None, ipmi_user=None, ipmi_pass=None, detect_virtual=True):
+ global info
+ if is_virtual(detect_virtual):
+ return {'Board Product' : 'VIRTUAL'}
+ if info.get(ipmi_addr, False):
+ return info[ipmi_addr]
+ if ipmi_addr:
+ info[ipmi_addr] = hw_ipmi_lib.get_ipmi_info(ipmi_addr, ipmi_user, ipmi_pass)
+ else:
+ return hw_ipmi_lib.get_local_ipmi_info()
+ if ipmi_addr and not info.get(ipmi_addr):
+ info[ipmi_addr] = {}
+
+ return info[ipmi_addr]
+
+def get_type(ipmi_addr=None, ipmi_user=None, ipmi_pass=None, detect_virtual=True):
+ info = get_info(ipmi_addr, ipmi_user, ipmi_pass, detect_virtual)
+ if not info:
+ return 'Unknown'
+
+ matches = get_match(info)
+ return matches
+
+def is_virtual(detect_virtual):
+ if not detect_virtual:
+ return False
+ with open('/proc/cpuinfo') as f:
+ for line in f.readlines():
+ if line.startswith('flags') and 'hypervisor' in line:
+ return True
+ return False
+
+def _get_hw_with_hw_type(hw_type):
+ for hw in hw_types.types:
+ if hw.hw_type == hw_type:
+ return hw
+
+def get_product_family(hw_type):
+ hw = _get_hw_with_hw_type(hw_type)
+ if hw:
+ return hw.product_family
+ return None
+
+
+def get_vendor(hw_type):
+ hw = _get_hw_with_hw_type(hw_type)
+ if hw:
+ return hw.vendor
+ return None
+
+def hd_with_type(hw_type, hd_type):
+ hw = _get_hw_with_hw_type(hw_type)
+ if hw:
+ return hw.get_disk_by_name(hd_type)
+ #Default behaviour hardware that is not detected
+ return None
+
+def os_hd(hw_type):
+ disk = hd_with_type(hw_type, 'os')
+ return disk if disk else '/dev/sda'
--- /dev/null
+# 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 hw_detector.hw_detect_lib as hw_detect
+
+try:
+ with open('/run/initramfs/hw_detect.log', 'w') as fp:
+ fp.write('hw : {0}\n'.format(hw_detect.get_local_hw_type()))
+ fp.write('os : {0}\n'.format(hw_detect.get_local_os_hd()))
+ fp.write('osd : {0}\n'.format(hw_detect.get_local_osd_hd()))
+except Exception:
+ pass
+
+print hw_detect.get_local_os_hd()
+
--- /dev/null
+# 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.
+
+from hw_detector.hw_type import HWType
+
+class NokiaHWType(HWType):
+ def __init__(self):
+ super(NokiaHWType, self).__init__()
+ self.vendor_name = 'Nokia'
--- /dev/null
+# 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.
+
+from setuptools import setup, find_packages
+setup(
+ name='hw_detector',
+ version='1.0',
+ license='Apache v2.0',
+ author='Janne Suominen',
+ author_email='janne.suominen@nokia.com',
+ namespace_packages=[],
+ packages=find_packages(),
+ include_package_data=True,
+ description='Hardware detection lib',
+ zip_safe=False,
+ )