Skip to content

Commit

Permalink
Control the collection of lvm grains via config
Browse files Browse the repository at this point in the history
lvm grain collection can take a long time on systems with a lot of
volumes and volume groups. On one server we measured ~3 minutes, which
is way too long for grains.

This change is backwards-compatible, leaving the lvm grain collection
enabled by default. Users with a lot of lvm volumes/volume groups can
disable these grains in the minion config by adding "lvm" to
disabled_grains:

disabled_grains:
   ...
   - lvm
  • Loading branch information
agraul committed Dec 22, 2023
1 parent 1a66f28 commit 7afe6b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/63114.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Control the collection of lvm grains via disabled_grains.
25 changes: 19 additions & 6 deletions salt/grains/lvm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
"""
Detect LVM Volumes
.. versionchanged:: 3008.0
To disable these grains add "lvm" to "disabled_grains" in the minion config.
.. code-block:: yaml
disabled_grains:
- lvm
"""

import logging
Expand All @@ -16,6 +25,12 @@

log = logging.getLogger(__name__)

__virtualname__ = "lvm"


def __virtual__():
return __virtualname__ not in __opts__.get("disabled_grains", [])


def lvm():
"""
Expand All @@ -33,14 +48,12 @@ def _linux_lvm():
ret = {}
cmd = salt.utils.path.which("lvm")
if cmd:
vgs = __salt__["cmd.run_all"]("{} vgs -o vg_name --noheadings".format(cmd))
vgs = __salt__["cmd.run_all"](f"{cmd} vgs -o vg_name --noheadings")

for vg in vgs["stdout"].splitlines():
vg = vg.strip()
ret[vg] = []
lvs = __salt__["cmd.run_all"](
"{} lvs -o lv_name --noheadings {}".format(cmd, vg)
)
lvs = __salt__["cmd.run_all"](f"{cmd} lvs -o lv_name --noheadings {vg}")
for lv in lvs["stdout"].splitlines():
ret[vg].append(lv.strip())

Expand All @@ -52,11 +65,11 @@ def _linux_lvm():
def _aix_lvm():
ret = {}
cmd = salt.utils.path.which("lsvg")
vgs = __salt__["cmd.run"]("{}".format(cmd))
vgs = __salt__["cmd.run"](f"{cmd}")

for vg in vgs.splitlines():
ret[vg] = []
lvs = __salt__["cmd.run"]("{} -l {}".format(cmd, vg))
lvs = __salt__["cmd.run"](f"{cmd} -l {vg}")
for lvline in lvs.splitlines()[2:]:
lv = lvline.split(" ", 1)[0]
ret[vg].append(lv)
Expand Down

0 comments on commit 7afe6b8

Please sign in to comment.