mc_utils / Some usefull small tools¶
-
mc_states.modules.mc_utils.
assert_good_grains
(grains)¶ ‘ no time to search/debug why, but sometimes grains dict is empty depending on the call context grains loading bug retriggered (i fixed once, do not remember where, FU SALT ...
-
mc_states.modules.mc_utils.
cache_check
(*args, **kw)¶ Wrapper for
invalidate_memoize_cache()
to set __opts__
-
mc_states.modules.mc_utils.
copy_dictupdate
(dict1, dict2)¶ Similar to dictupdate but with deepcopy of two merged dicts first.
-
mc_states.modules.mc_utils.
cyaml_dump
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.cyaml_dump()
-
mc_states.modules.mc_utils.
cyaml_load
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.cyaml_load()
-
mc_states.modules.mc_utils.
defaults
(prefix, datadict, ignored_keys=None, overridden=None, noresolve=False, firstcall=True)¶ Magic defaults settings configuration getter
- Get the “prefix” value from the configuration (pillar/grain)
- Then overrides or append to it with the corresponding
key in the given “datadict” if value is a dict or a list.
- If we get from pillar/grains/local from the curent key in the form: “{prefix}-overrides: it overrides totally the original value.
- if the datadict contains a key “{prefix}-append and the value is a list, it appends to the original value
- If the datadict contains a key “{prefix}”:
- If a list: override to the list the default list in conf
- Elif a dict: update the default dictionnary with the one in conf
- Else take that as a value if the value is not a mapping or a list
-
mc_states.modules.mc_utils.
dictupdate
(dict1, dict2)¶ Merge two dictionnaries recursively
test:
salt '*' mc_utils.dictupdate '{foobar: {toto: tata, toto2: tata2},titi: tutu}' '{bar: toto, foobar: {toto2: arg, toto3: arg2}}' ---------- bar: toto foobar: ---------- toto: tata toto2: arg toto3: arg2 titi: tutu
-
mc_states.modules.mc_utils.
epdb
(**kw)¶ add a network attachable breakpoint
-
mc_states.modules.mc_utils.
file_read
(fic)¶ read the content a file
-
mc_states.modules.mc_utils.
format_resolve
(value, original_dict=None, this_call=0, topdb=False, **kwargs)¶ Resolve a dict of formatted strings, mappings & list to a valued dict Please also read the associated test:
{"a": ["{b}", "{c}", "{e}"], "b": 1, "c": "{d}", "d": "{b}", "e": "{d}", } ====> {"a": ["1", "1", "{e}"], "b": 1, "c": "{d}", "d": "{b}", "e": "{d}", }
-
mc_states.modules.mc_utils.
generate_stored_password
(key, length=None, force=False, value=None)¶ Generate and store a password. At soon as one is stored with a specific key, it will never be renegerated unless you set force to true.
-
mc_states.modules.mc_utils.
get
(key, default='', local_registry=None, registry_format='pack', delimiter=<class 'DEFAULT_TARGET_DELIM'>)¶ Same as ‘config.get’ but with different retrieval order.
This routine traverses these data stores in this order:
- Local minion config (opts)
- Minion’s pillar
- Dict:
- passed in local_registry argument
- or automaticly loaded global registries
- Minion’s grains
- Master config
CLI Example:
salt '*' mc_utils.get pkg:apache
-
mc_states.modules.mc_utils.
get_container
(pid)¶ On a main host context, for a non containerized process this return MAIN_HOST
On a container context, this return MAIN_HOST On a hpot context, this return MAIN_HOST
-
mc_states.modules.mc_utils.
get_local_cache
(*args)¶ Wrapper for
get_local_cache()
-
mc_states.modules.mc_utils.
get_mc_server
(*args, **kw)¶ Wrapper for
get_local_cache()
-
mc_states.modules.mc_utils.
get_uniq_keys_for
(prefix)¶ Return keys for prefix:
- if prefix is in conf
- All other keys of depth + 1
With makina.foo prefix:
- returns makina.foo
- returns makina.foo.1
- dont returns makina.foo.1.1
- dont returns makina
- dont returns makina.other
-
mc_states.modules.mc_utils.
hash
(string, typ='md5', func='hexdigest')¶ Return the hash of a string CLI Examples:
salt-call --local mc_utils.hash foo salt-call --local mc_utils.hash foo md5 salt-call --local mc_utils.hash foo sha1 salt-call --local mc_utils.hash foo sha224 salt-call --local mc_utils.hash foo sha256 salt-call --local mc_utils.hash foo sha384 salt-call --local mc_utils.hash foo sha512
-
mc_states.modules.mc_utils.
invalidate_memoize_cache
(*args, **kw)¶ Wrapper for
invalidate_memoize_cache()
to set __opts__
-
mc_states.modules.mc_utils.
is_a_bool
(value)¶ is the value a bool
-
mc_states.modules.mc_utils.
is_a_complex
(value)¶ is the value a complex
-
mc_states.modules.mc_utils.
is_a_dict
(value)¶ is the value a dict
-
mc_states.modules.mc_utils.
is_a_float
(value)¶ is the value a float
-
mc_states.modules.mc_utils.
is_a_int
(value)¶ is the value an int
-
mc_states.modules.mc_utils.
is_a_list
(value)¶ is the value a list
-
mc_states.modules.mc_utils.
is_a_long
(value)¶ is the value a long
-
mc_states.modules.mc_utils.
is_a_number
(value)¶ is the value a number
-
mc_states.modules.mc_utils.
is_a_set
(value)¶ is the value a set
-
mc_states.modules.mc_utils.
is_a_str
(value)¶ is the value a stirng
-
mc_states.modules.mc_utils.
is_a_tuple
(value)¶ is the value a tuple
-
mc_states.modules.mc_utils.
is_iter
(value)¶ is the value iterable (list, set, dict tuple)
-
mc_states.modules.mc_utils.
iyaml_dump
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.iyaml_dump()
-
mc_states.modules.mc_utils.
json_dump
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.old_json_dump()
-
mc_states.modules.mc_utils.
json_load
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.json_load()
-
mc_states.modules.mc_utils.
list_cache_keys
(*args, **kw)¶ Wrapper for
list_cache_keys()
to set __opts__
-
mc_states.modules.mc_utils.
local_minion_id
(force=False)¶ search in running config root then in well known config salt root then use regular salt function
-
mc_states.modules.mc_utils.
magicstring
(thestr)¶ Convert any string to UTF-8 ENCODED one
-
mc_states.modules.mc_utils.
manage_file
(name, **kwargs)¶ Easier wrapper to file.manage_file
-
mc_states.modules.mc_utils.
memoize_cache
(*args, **kw)¶ Wrapper for
memoize_cache()
to set __opts__CLI Examples:
salt-call -lall mc_pillar.memoize_cache test.ping
-
mc_states.modules.mc_utils.
msgpack_dump
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.old_msgpack_dump()
-
mc_states.modules.mc_utils.
msgpack_load
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.msgpack_load()
-
mc_states.modules.mc_utils.
msr
()¶ get salt root from either pillar or opts (minion or master)
-
mc_states.modules.mc_utils.
nyaml_dump
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.yaml_dump()
-
mc_states.modules.mc_utils.
old_yaml_dump
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.old_yaml_dump()
-
mc_states.modules.mc_utils.
output
(mapping, raw=False, outputter='highstate')¶ This return a formatted output
-
mc_states.modules.mc_utils.
pdb
(**kw)¶ Add a breakpoint
-
mc_states.modules.mc_utils.
purge_memoize_cache
(*args, **kw)¶ Wrapper for
invalidate_memoize_cache()
to set __opts__
-
mc_states.modules.mc_utils.
register_memcache_first
(pattern)¶ Wrapper for
invalidate_memoize_cache()
to set __opts__
-
mc_states.modules.mc_utils.
remove_cache_entry
(*args, **kw)¶ Wrapper for
remove_cache_entry()
to set __opts__
-
mc_states.modules.mc_utils.
remove_entry
(*args, **kw)¶ Wrapper for
remove_cache_entry()
to set __opts__
-
mc_states.modules.mc_utils.
salt_root
()¶ get salt root from either pillar or opts (minion or master)
-
mc_states.modules.mc_utils.
test_cache
(ttl=120)¶ .
-
mc_states.modules.mc_utils.
traverse_dict
(data, key, delimiter=<class 'DEFAULT_TARGET_DELIM'>)¶ Handle the fact to traverse dicts with ‘.’ as it was an old default and makina-states relies a lot on it
This restore the old behavior of something that can be traversed
- makina-states.foo:
- bar:
- c: true
can be traversed with makina-states.foo.bar.c
-
mc_states.modules.mc_utils.
uncached_get
(key, default='', local_registry=None, registry_format='pack', delimiter=<class 'DEFAULT_TARGET_DELIM'>)¶ Same as ‘config.get’ but with different retrieval order.
This routine traverses these data stores in this order:
- Local minion config (opts)
- Minion’s pillar
- Dict:
- passed in local_registry argument
- or automaticly loaded global registries
- Minion’s grains
- Master config
CLI Example:
salt '*' mc_utils.get pkg:apache
-
mc_states.modules.mc_utils.
unix_crypt
(passwd)¶ Encrypt the stringed password in the unix crypt format (/etc/shadow)
-
mc_states.modules.mc_utils.
update_no_list
(dest, upd, recursive_update=True)¶ Recursive version of the default dict.update
Merges upd recursively into dest But instead of merging lists, it overrides them from target dict
-
mc_states.modules.mc_utils.
yaml_dump
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.old_yaml_dump()
-
mc_states.modules.mc_utils.
yaml_load
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.yaml_load()
-
mc_states.modules.mc_utils.
yencode
(*args, **kw)¶ Retro compat to
mc_states.modules.mc_dump.yencode()