Skip to content

Commit

Permalink
facts: Update RAID devices regex for FreeBSD (#82081)
Browse files Browse the repository at this point in the history
Added support FreeBSD RAID devices and regex to match partitions as well as slices. 
RAID device list is taken from here: https://github.com/freebsd/freebsd-src/blob/main/usr.sbin/bsdconfig/share/device.subr
  • Loading branch information
lostsoulparty committed May 6, 2024
1 parent aed8c08 commit 417db21
Show file tree
Hide file tree
Showing 5 changed files with 608 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/freebsd_disk_regex.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfixes:
- freebsd - update disk and slices regex for fact gathering (https://github.com/ansible/ansible/pull/82081).
43 changes: 40 additions & 3 deletions lib/ansible/module_utils/facts/hardware/freebsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,50 @@ def get_device_facts(self):

sysdir = '/dev'
device_facts['devices'] = {}
drives = re.compile(r'(ada?\d+|da\d+|a?cd\d+)') # TODO: rc, disks, err = self.module.run_command("/sbin/sysctl kern.disks")
slices = re.compile(r'(ada?\d+s\d+\w*|da\d+s\d+\w*)')
# TODO: rc, disks, err = self.module.run_command("/sbin/sysctl kern.disks")
drives = re.compile(
r"""(?x)(
(?:
ada? # ATA/SATA disk device
|da # SCSI disk device
|a?cd # SCSI CDROM drive
|amrd # AMI MegaRAID drive
|idad # Compaq RAID array
|ipsd # IBM ServeRAID RAID array
|md # md(4) disk device
|mfid # LSI MegaRAID SAS array
|mlxd # Mylex RAID disk
|twed # 3ware ATA RAID array
|vtbd # VirtIO Block Device
)\d+
)
"""
)

slices = re.compile(
r"""(?x)(
(?:
ada? # ATA/SATA disk device
|a?cd # SCSI CDROM drive
|amrd # AMI MegaRAID drive
|da # SCSI disk device
|idad # Compaq RAID array
|ipsd # IBM ServeRAID RAID array
|md # md(4) disk device
|mfid # LSI MegaRAID SAS array
|mlxd # Mylex RAID disk
|twed # 3ware ATA RAID array
|vtbd # VirtIO Block Device
)\d+[ps]\d+\w*
)
"""
)

if os.path.isdir(sysdir):
dirlist = sorted(os.listdir(sysdir))
for device in dirlist:
d = drives.match(device)
if d:
if d and d.group(1) not in device_facts['devices']:
device_facts['devices'][d.group(1)] = []
s = slices.match(device)
if s:
Expand Down

0 comments on commit 417db21

Please sign in to comment.