MCPcopy
hub / github.com/saltstack/salt / remove

Function remove

salt/modules/grains.py:385–425  ·  view source on GitHub ↗

.. versionadded:: 0.17.0 Remove a value from a list in the grains config file key The grain key to remove. val The value to remove. delimiter The key can be a nested dict key. Use this parameter to specify the delimiter you use, instead of the

(key, val, delimiter=DEFAULT_TARGET_DELIM)

Source from the content-addressed store, hash-verified

383
384
385def remove(key, val, delimiter=DEFAULT_TARGET_DELIM):
386 """
387 .. versionadded:: 0.17.0
388
389 Remove a value from a list in the grains config file
390
391 key
392 The grain key to remove.
393
394 val
395 The value to remove.
396
397 delimiter
398 The key can be a nested dict key. Use this parameter to
399 specify the delimiter you use, instead of the default ``:``.
400 You can now append values to a list in nested dictionary grains. If the
401 list doesn't exist at this level, it will be created.
402
403 .. versionadded:: 2015.8.2
404
405 CLI Example:
406
407 .. code-block:: bash
408
409 salt '*' grains.remove key val
410 """
411 grains = get(key, [], delimiter)
412 if not isinstance(grains, list):
413 return f"The key {key} is not a valid list"
414 if val not in grains:
415 return f"The val {val} was not in the list {key}"
416 grains.remove(val)
417
418 while delimiter in key:
419 key, rest = key.rsplit(delimiter, 1)
420 _grain = get(key, None, delimiter)
421 if isinstance(_grain, dict):
422 _grain.update({rest: grains})
423 grains = _grain
424
425 return setval(key, grains)
426
427
428def delkey(key, force=False):

Callers

nothing calls this directly

Calls 4

getFunction · 0.70
setvalFunction · 0.70
removeMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected