From ece525c2e23d87dd277c53a577403e3cf1c8c182 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 16 Jul 2021 11:11:13 -0400 Subject: [PATCH] Begin work on install and filter small devices from install candidacy --- .../profiles/default/scripts/getinstalldisk | 90 +++++++++++++++++++ .../profiles/default/scripts/installimage | 4 + .../profiles/default/scripts/getinstalldisk | 2 + 3 files changed, 96 insertions(+) create mode 100644 confluent_osdeploy/el8-diskless/profiles/default/scripts/getinstalldisk create mode 100644 confluent_osdeploy/el8-diskless/profiles/default/scripts/installimage diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/el8-diskless/profiles/default/scripts/getinstalldisk new file mode 100644 index 00000000..a28c6402 --- /dev/null +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/getinstalldisk @@ -0,0 +1,90 @@ +import subprocess +import os + +class DiskInfo(object): + def __init__(self, devname): + self.name = devname + self.wwn = None + self.path = None + self.model = '' + self.size = 0 + self.driver = None + self.mdcontainer = '' + devnode = '/dev/{0}'.format(devname) + qprop = subprocess.check_output( + ['udevadm', 'info', '--query=property', devnode]) + if not isinstance(qprop, str): + qprop = qprop.decode('utf8') + for prop in qprop.split('\n'): + if '=' not in prop: + continue + k, v = prop.split('=', 1) + if k == 'DEVTYPE' and v != 'disk': + raise Exception('Not a disk') + elif k == 'DM_NAME': + raise Exception('Device Mapper') + elif k == 'ID_MODEL': + self.model = v + elif k == 'DEVPATH': + self.path = v + elif k == 'ID_WWN': + self.wwn = v + elif k == 'MD_CONTAINER': + self.mdcontainer = v + attrs = subprocess.check_output(['udevadm', 'info', '-a', devnode]) + if not isinstance(attrs, str): + attrs = attrs.decode('utf8') + for attr in attrs.split('\n'): + if '==' not in attr: + continue + k, v = attr.split('==', 1) + k = k.strip() + if k == 'ATTRS{size}': + self.size = v.replace('"', '') + elif (k == 'DRIVERS' and not self.driver + and v not in ('"sd"', '""')): + self.driver = v.replace('"', '') + if not self.driver and 'imsm' not in self.mdcontainer: + raise Exception("No driver detected") + if int(self.size) < 536870912: + raise Exception("Device too small for install") + + @property + def priority(self): + if self.model.lower() in ('thinksystem_m.2_vd', 'thinksystem m.2', 'thinksystem_m.2'): + return 0 + if 'imsm' in self.mdcontainer: + return 1 + if self.driver == 'ahci': + return 2 + if self.driver.startswith('megaraid'): + return 3 + if self.driver.startswith('mpt'): + return 4 + return 99 + + def __repr__(self): + return repr({ + 'name': self.name, + 'path': self.path, + 'wwn': self.wwn, + 'driver': self.driver, + 'size': self.size, + 'model': self.model, + }) + + +def main(): + disks = [] + for disk in sorted(os.listdir('/sys/class/block')): + try: + disk = DiskInfo(disk) + disks.append(disk) + except Exception as e: + print("Skipping {0}: {1}".format(disk, str(e))) + nd = [x.name for x in sorted(disks, key=lambda x: x.priority)] + if nd: + open('/tmp/installdisk', 'w').write(nd[0]) + +if __name__ == '__main__': + main() diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/installimage b/confluent_osdeploy/el8-diskless/profiles/default/scripts/installimage new file mode 100644 index 00000000..ae8d92ed --- /dev/null +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/installimage @@ -0,0 +1,4 @@ +#!/bin/bash +. /etc/confluent/functions +run_remote_python getinstalldisk +run_remote_parts pre.d diff --git a/confluent_osdeploy/el8/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/el8/profiles/default/scripts/getinstalldisk index 4af31c0b..a28c6402 100644 --- a/confluent_osdeploy/el8/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/el8/profiles/default/scripts/getinstalldisk @@ -46,6 +46,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') if not self.driver and 'imsm' not in self.mdcontainer: raise Exception("No driver detected") + if int(self.size) < 536870912: + raise Exception("Device too small for install") @property def priority(self):