MCPcopy Index your code
hub / github.com/saltstack/salt / tune

Function tune

salt/modules/disk.py:324–390  ·  view source on GitHub ↗

Set attributes for the specified device CLI Example: .. code-block:: bash salt '*' disk.tune /dev/sda1 read-ahead=1024 read-write=True Valid options are: ``read-ahead``, ``filesystem-read-ahead``, ``read-only``, ``read-write``. For ``read-only`` and ``read-write

(device, **kwargs)

Source from the content-addressed store, hash-verified

322
323
324def tune(device, **kwargs):
325 """
326 Set attributes for the specified device
327
328 CLI Example:
329
330 .. code-block:: bash
331
332 salt '*' disk.tune /dev/sda1 read-ahead=1024 read-write=True
333
334 Valid options are: ``read-ahead``, ``filesystem-read-ahead``,
335 ``read-only``, ``read-write``.
336
337 For ``read-only`` and ``read-write``, the value must be set to ``True``.
338
339 See the ``blockdev(8)`` manpage for a more complete description of these
340 options.
341 """
342
343 kwarg_map = {
344 "read-ahead": "setra",
345 "filesystem-read-ahead": "setfra",
346 "read-only": "setro",
347 "read-write": "setrw",
348 }
349 opts = ""
350 args = []
351 invalid_kwargs = {}
352
353 for key, value in kwargs.items():
354 # Check for invalid kwargs but ignore dunder args
355 if key not in kwarg_map and not key.startswith("__"):
356 invalid_kwargs[key] = value
357 continue
358
359 # Check that read-only and read-write have a value of True
360 # they do not accept other values
361 if key in ("read-only", "read-write") and not (
362 value == "True" or value is True
363 ):
364 invalid_kwargs[key] = value
365 continue
366
367 if key in kwarg_map:
368 switch = kwarg_map[key]
369 if key != "read-write":
370 args.append(switch.replace("set", "get"))
371 else:
372 args.append("getro")
373 if key in ("read-only", "read-write"):
374 opts += f"--{switch} "
375 else:
376 opts += f"--{switch} {value} "
377
378 # Raise error if any invalid kwargs were found
379 if invalid_kwargs:
380 invalid_kwargs_str = ", ".join(f"{k}={v}" for k, v in invalid_kwargs.items())
381 raise SaltInvocationError(f"Invalid keyword arguments: {invalid_kwargs_str}")

Callers

nothing calls this directly

Calls 5

SaltInvocationErrorClass · 0.90
dumpFunction · 0.70
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected