From 48a0c21300913e57c0cce105b2d28571b797099e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 1 Aug 2025 09:00:25 -0400 Subject: [PATCH] Refine getinstalldisk Reduce obvious output about skipped devices. Rule out any read-only device. Amend minimum size to 2GB. Among same priority devices, select the smallest target. --- .../profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- .../el7/profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- .../profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- .../el8/profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- .../profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- .../profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- .../suse15/profiles/hpc/scripts/getinstalldisk | 17 +++++++++++++---- .../profiles/server/scripts/getinstalldisk | 17 +++++++++++++---- .../profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- .../profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- .../profiles/default/scripts/getinstalldisk | 17 +++++++++++++---- 11 files changed, 143 insertions(+), 44 deletions(-) diff --git a/confluent_osdeploy/el7-diskless/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/el7-diskless/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/el7-diskless/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/el7-diskless/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/el7/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/el7/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/el7/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/el7/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/el8-diskless/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/el8/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/el8/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/el8/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/el8/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/el9-diskless/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/rhvh4/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/rhvh4/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/rhvh4/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/rhvh4/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/suse15/profiles/hpc/scripts/getinstalldisk b/confluent_osdeploy/suse15/profiles/hpc/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/suse15/profiles/hpc/scripts/getinstalldisk +++ b/confluent_osdeploy/suse15/profiles/hpc/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/suse15/profiles/server/scripts/getinstalldisk b/confluent_osdeploy/suse15/profiles/server/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/suse15/profiles/server/scripts/getinstalldisk +++ b/confluent_osdeploy/suse15/profiles/server/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/ubuntu20.04/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/ubuntu20.04/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/ubuntu20.04/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/ubuntu20.04/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0]) diff --git a/confluent_osdeploy/ubuntu22.04/profiles/default/scripts/getinstalldisk b/confluent_osdeploy/ubuntu22.04/profiles/default/scripts/getinstalldisk index 71a97e8e..dec536b7 100644 --- a/confluent_osdeploy/ubuntu22.04/profiles/default/scripts/getinstalldisk +++ b/confluent_osdeploy/ubuntu22.04/profiles/default/scripts/getinstalldisk @@ -2,6 +2,9 @@ import subprocess import os +class SilentException(Exception): + pass + class DiskInfo(object): def __init__(self, devname): if devname.startswith('nvme') and 'c' in devname: @@ -24,9 +27,11 @@ class DiskInfo(object): continue k, v = prop.split('=', 1) if k == 'DEVTYPE' and v != 'disk': + if v == 'partition': + raise SilentException('Partition') raise Exception('Not a disk') elif k == 'DM_NAME': - raise Exception('Device Mapper') + raise SilentException('Device Mapper') elif k == 'ID_MODEL': self.model = v elif k == 'DEVPATH': @@ -50,6 +55,8 @@ class DiskInfo(object): self.driver = v.replace('"', '') elif k == 'ATTRS{subsystype}': self.subsystype = v.replace('"', '') + elif k == 'ATTR{ro}' and v == '"1"': + raise Exception("Device is read-only") if not self.driver and 'imsm' not in self.mdcontainer and self.subsystype != 'nvm': raise Exception("No driver detected") if self.driver == 'sr': @@ -57,8 +64,8 @@ class DiskInfo(object): if os.path.exists('/sys/block/{0}/size'.format(self.name)): with open('/sys/block/{0}/size'.format(self.name), 'r') as sizesrc: self.size = int(sizesrc.read()) * 512 - if int(self.size) < 536870912: - raise Exception("Device too small for install") + if int(self.size) < 2147483648: + raise Exception("Device too small for install ({}MiB)".format(int(self.size)/1024/1024)) @property def priority(self): @@ -91,9 +98,11 @@ def main(): try: disk = DiskInfo(disk) disks.append(disk) + except SilentException: + pass 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)] + nd = [x.name for x in sorted(disks, key=lambda x: [x.priority, x.size])] if nd: open('/tmp/installdisk', 'w').write(nd[0])