filesystem - migrate LVM.get_fs_size() to use CmdRunner (#11888)

* filesystem - migrate LVM.get_fs_size() to use CmdRunner

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

* filesystem - add changelog fragment for #11888

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Alexei Znamensky
2026-04-20 19:26:27 +12:00
committed by GitHub
parent 180da98a7c
commit 5b409facbe
2 changed files with 10 additions and 6 deletions

View File

@@ -0,0 +1,2 @@
minor_changes:
- filesystem - migrate ``LVM.get_fs_size()`` to use ``CmdRunner``, ensuring locale-independent output parsing (https://github.com/ansible-collections/community.general/pull/11888).

View File

@@ -154,6 +154,7 @@ import stat
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils._lvm import pvs_runner
from ansible_collections.community.general.plugins.module_utils.version import LooseVersion
@@ -569,14 +570,15 @@ class LVM(Filesystem):
CHANGE_UUID_OPTION = "-u"
CHANGE_UUID_OPTION_HAS_ARG = False
def __init__(self, module):
super().__init__(module)
self._pvs = pvs_runner(module)
def get_fs_size(self, dev):
"""Get and return PV size, in bytes."""
cmd = self.module.get_bin_path(self.INFO, required=True)
dummy, size, dummy = self.module.run_command(
[cmd, "--noheadings", "-o", "pv_size", "--units", "b", "--nosuffix", str(dev)], check_rc=True
)
pv_size = int(size)
return pv_size
with self._pvs("noheadings nosuffix units fields devices") as ctx:
dummy, size, dummy = ctx.run(units="b", fields="pv_size", devices=[str(dev)])
return int(size.strip())
class Swap(Filesystem):