mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
More statvfs info for mount facts rebase 12073 (#25454)
* Add more mount point statvfs info including sizes Based on https://github.com/ansible/ansible/pull/12073 facts.utils.get_mount_size() now returns a dict of most of the posix statvfs data, including block_size and inode counts. Update the facts.hardware classes that use get_mount_size() to use the new info by mount_info.update(mount_statvfs_inof) to merge. * add back unit tests for LinuxHardware mount/fs facts * add test cases for facts.utils.get_mount_size
This commit is contained in:
parent
3bba43a487
commit
56b7483b85
10 changed files with 591 additions and 46 deletions
|
@ -121,15 +121,13 @@ class FreeBSDHardware(Hardware):
|
|||
if line.startswith('#') or line.strip() == '':
|
||||
continue
|
||||
fields = re.sub(r'\s+', ' ', line).split()
|
||||
size_total, size_available = get_mount_size(fields[1])
|
||||
mount_facts['mounts'].append({
|
||||
'mount': fields[1],
|
||||
'device': fields[0],
|
||||
'fstype': fields[2],
|
||||
'options': fields[3],
|
||||
'size_total': size_total,
|
||||
'size_available': size_available
|
||||
})
|
||||
mount_statvfs_info = get_mount_size(fields[1])
|
||||
mount_info = {'mount': fields[1],
|
||||
'device': fields[0],
|
||||
'fstype': fields[2],
|
||||
'options': fields[3]}
|
||||
mount_info.update(mount_statvfs_info)
|
||||
mount_facts['mounts'].append(mount_info)
|
||||
|
||||
return mount_facts
|
||||
|
||||
|
|
|
@ -428,7 +428,7 @@ class LinuxHardware(Hardware):
|
|||
if fstype == 'none':
|
||||
continue
|
||||
|
||||
size_total, size_available = get_mount_size(mount)
|
||||
mount_statvfs_info = get_mount_size(mount)
|
||||
|
||||
if mount in bind_mounts:
|
||||
# only add if not already there, we might have a plain /etc/mtab
|
||||
|
@ -439,11 +439,10 @@ class LinuxHardware(Hardware):
|
|||
'device': device,
|
||||
'fstype': fstype,
|
||||
'options': options,
|
||||
# statvfs data
|
||||
'size_total': size_total,
|
||||
'size_available': size_available,
|
||||
'uuid': uuids.get(device, 'N/A')}
|
||||
|
||||
mount_info.update(mount_statvfs_info)
|
||||
|
||||
mounts.append(mount_info)
|
||||
|
||||
mount_facts['mounts'] = mounts
|
||||
|
|
|
@ -125,15 +125,13 @@ class NetBSDHardware(Hardware):
|
|||
if line.startswith('#') or line.strip() == '':
|
||||
continue
|
||||
fields = re.sub(r'\s+', ' ', line).split()
|
||||
size_total, size_available = get_mount_size(fields[1])
|
||||
mount_facts['mounts'].append({
|
||||
'mount': fields[1],
|
||||
'device': fields[0],
|
||||
'fstype': fields[2],
|
||||
'options': fields[3],
|
||||
'size_total': size_total,
|
||||
'size_available': size_available
|
||||
})
|
||||
mount_statvfs_info = get_mount_size(fields[1])
|
||||
mount_info = {'mount': fields[1],
|
||||
'device': fields[0],
|
||||
'fstype': fields[2],
|
||||
'options': fields[3]}
|
||||
mount_info.update(mount_statvfs_info)
|
||||
mount_facts['mounts'].append(mount_info)
|
||||
return mount_facts
|
||||
|
||||
def get_dmi_facts(self):
|
||||
|
|
|
@ -80,15 +80,13 @@ class OpenBSDHardware(Hardware):
|
|||
fields = re.sub(r'\s+', ' ', line).split()
|
||||
if fields[1] == 'none' or fields[3] == 'xx':
|
||||
continue
|
||||
size_total, size_available = get_mount_size(fields[1])
|
||||
mount_facts['mounts'].append({
|
||||
'mount': fields[1],
|
||||
'device': fields[0],
|
||||
'fstype': fields[2],
|
||||
'options': fields[3],
|
||||
'size_total': size_total,
|
||||
'size_available': size_available
|
||||
})
|
||||
mount_statvfs_info = get_mount_size(fields[1])
|
||||
mount_info = {'mount': fields[1],
|
||||
'device': fields[0],
|
||||
'fstype': fields[2],
|
||||
'options': fields[3]}
|
||||
mount_info.update(mount_statvfs_info)
|
||||
mount_facts['mounts'].append(mount_info)
|
||||
return mount_facts
|
||||
|
||||
def get_memory_facts(self):
|
||||
|
|
|
@ -154,16 +154,14 @@ class SunOSHardware(Hardware):
|
|||
if fstab:
|
||||
for line in fstab.splitlines():
|
||||
fields = line.split('\t')
|
||||
size_total, size_available = get_mount_size(fields[1])
|
||||
mount_facts['mounts'].append({
|
||||
'mount': fields[1],
|
||||
'device': fields[0],
|
||||
'fstype': fields[2],
|
||||
'options': fields[3],
|
||||
'time': fields[4],
|
||||
'size_total': size_total,
|
||||
'size_available': size_available
|
||||
})
|
||||
mount_statvfs_info = get_mount_size(fields[1])
|
||||
mount_info = {'mount': fields[1],
|
||||
'device': fields[0],
|
||||
'fstype': fields[2],
|
||||
'options': fields[3],
|
||||
'time': fields[4]}
|
||||
mount_info.update(mount_statvfs_info)
|
||||
mount_facts['mounts'].append(mount_info)
|
||||
|
||||
return mount_facts
|
||||
|
||||
|
|
|
@ -47,13 +47,24 @@ def get_file_lines(path):
|
|||
|
||||
|
||||
def get_mount_size(mountpoint):
|
||||
size_total = None
|
||||
size_available = None
|
||||
mount_size = {}
|
||||
|
||||
try:
|
||||
statvfs_result = os.statvfs(mountpoint)
|
||||
size_total = statvfs_result.f_frsize * statvfs_result.f_blocks
|
||||
size_available = statvfs_result.f_frsize * (statvfs_result.f_bavail)
|
||||
mount_size['size_total'] = statvfs_result.f_frsize * statvfs_result.f_blocks
|
||||
mount_size['size_available'] = statvfs_result.f_frsize * (statvfs_result.f_bavail)
|
||||
|
||||
# Block total/available/used
|
||||
mount_size['block_size'] = statvfs_result.f_bsize
|
||||
mount_size['block_total'] = statvfs_result.f_blocks
|
||||
mount_size['block_available'] = statvfs_result.f_bavail
|
||||
mount_size['block_used'] = mount_size['block_total'] - mount_size['block_available']
|
||||
|
||||
# Inode total/available/used
|
||||
mount_size['inode_total'] = statvfs_result.f_files
|
||||
mount_size['inode_available'] = statvfs_result.f_favail
|
||||
mount_size['inode_used'] = mount_size['inode_total'] - mount_size['inode_available']
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
return size_total, size_available
|
||||
return mount_size
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue