Coverage for lib/ansible/utils/vars.py : 66%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
global cur_id node_mac[0:8], node_mac[8:12], random_int[0:4], random_int[4:8], ("%012x" % cur_id)[:12], ])
""" Internal convenience function to ensure arguments are MutableMappings
This checks that all arguments are MutableMappings or raises an error
:raises AnsibleError: if one of the arguments is not a MutableMapping """
# If this becomes generally needed, change the signature to operate on # a variable number of arguments instead.
myvars = [] for x in [a, b]: try: myvars.append(dumps(x)) except: myvars.append(to_native(x)) raise AnsibleError("failed to combine variables, expected dicts but got a '{0}' and a '{1}': \n{2}\n{3}".format( a.__class__.__name__, b.__class__.__name__, myvars[0], myvars[1]) )
""" Return a copy of dictionaries of variables based on configured hash behavior """
return merge_hash(a, b) else: # HASH_BEHAVIOUR == 'replace'
""" Recursively merges hash b into a so that keys from b take precedence over keys from a """
# if a is empty or equal to b, return b
# if b is empty the below unfolds quickly result = a.copy()
# next, iterate over b keys and values for k, v in iteritems(b): # if there's already such key in a # and that key contains a MutableMapping if k in result and isinstance(result[k], MutableMapping) and isinstance(v, MutableMapping): # merge those dicts recursively result[k] = merge_hash(result[k], v) else: # otherwise, just copy the value from b to a result[k] = v
return result
# Argument is a YAML file (JSON is a subset of YAML) # Arguments as YAML data = loader.load(extra_vars_opt) else: # Arguments as Key-value
else: raise AnsibleOptionsError("Invalid extra vars data supplied. '%s' could not be made into a dictionary" % extra_vars_opt)
'diff': 'diff_mode', 'inventory': 'inventory_sources', 'subset': 'limit', 'tags': 'run_tags'}
""" Determines, if string is valid Python identifier using the ast module. Originally posted at: http://stackoverflow.com/a/29586366 """
return False
except SyntaxError: return False
return False
return False
return False
return False
return False
|