Merge "Return append status, use it for accurate logging"
This commit is contained in:
commit
91f9e4a608
@ -213,8 +213,9 @@ def _parse_belongs_to(key, belongs_to, inventory):
|
|||||||
"""
|
"""
|
||||||
for item in belongs_to:
|
for item in belongs_to:
|
||||||
if key not in inventory[item]['children']:
|
if key not in inventory[item]['children']:
|
||||||
logger.debug("Adding %s to %s", key, item)
|
appended = append_if(array=inventory[item]['children'], item=key)
|
||||||
append_if(array=inventory[item]['children'], item=key)
|
if appended:
|
||||||
|
logger.debug("Added %s to %s", key, item)
|
||||||
|
|
||||||
|
|
||||||
def _build_container_hosts(container_affinity, container_hosts, type_and_name,
|
def _build_container_hosts(container_affinity, container_hosts, type_and_name,
|
||||||
@ -266,12 +267,14 @@ def _build_container_hosts(container_affinity, container_hosts, type_and_name,
|
|||||||
"hosts": [],
|
"hosts": [],
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug("Adding container %s to %s",
|
appended = append_if(
|
||||||
container_host_name, container_host_type)
|
|
||||||
append_if(
|
|
||||||
array=inventory[container_host_type]["hosts"],
|
array=inventory[container_host_type]["hosts"],
|
||||||
item=container_host_name
|
item=container_host_name
|
||||||
)
|
)
|
||||||
|
if appended:
|
||||||
|
logger.debug("Added container %s to %s",
|
||||||
|
container_host_name, container_host_type)
|
||||||
|
|
||||||
append_if(array=container_hosts, item=container_host_name)
|
append_if(array=container_hosts, item=container_host_name)
|
||||||
else:
|
else:
|
||||||
if host_type not in hostvars:
|
if host_type not in hostvars:
|
||||||
@ -350,24 +353,28 @@ def _append_to_host_groups(inventory, container_type, assignment, host_type,
|
|||||||
hdata['physical_host'] = host_type
|
hdata['physical_host'] = host_type
|
||||||
|
|
||||||
if container.startswith('%s-' % type_and_name):
|
if container.startswith('%s-' % type_and_name):
|
||||||
logger.debug("Added host %s to %s hosts",
|
appended = append_if(array=iah, item=container)
|
||||||
container, assignment)
|
if appended:
|
||||||
append_if(array=iah, item=container)
|
logger.debug("Added host %s to %s hosts",
|
||||||
|
container, assignment)
|
||||||
elif is_metal is True:
|
elif is_metal is True:
|
||||||
if component == assignment:
|
if component == assignment:
|
||||||
logger.debug("Added is_metal host %s to %s hosts",
|
appended = append_if(array=iah, item=container)
|
||||||
container, assignment)
|
if appended:
|
||||||
append_if(array=iah, item=container)
|
logger.debug("Added is_metal host %s to %s hosts",
|
||||||
|
container, assignment)
|
||||||
if container.startswith('%s-' % type_and_name):
|
if container.startswith('%s-' % type_and_name):
|
||||||
logger.debug("Added host %s to %s hosts",
|
appended = append_if(array=iph, item=container)
|
||||||
container, physical_group_type)
|
if appended:
|
||||||
append_if(array=iph, item=container)
|
logger.debug("Added host %s to %s hosts",
|
||||||
|
container, physical_group_type)
|
||||||
|
|
||||||
elif is_metal is True:
|
elif is_metal is True:
|
||||||
if container.startswith(host_type):
|
if container.startswith(host_type):
|
||||||
logger.debug("Added is_metal host %s to %s hosts",
|
appended = append_if(array=iph, item=container)
|
||||||
container, physical_group_type)
|
if appended:
|
||||||
append_if(array=iph, item=container)
|
logger.debug("Added is_metal host %s to %s hosts",
|
||||||
|
container, physical_group_type)
|
||||||
|
|
||||||
# Append any options in config to the host_vars of a container
|
# Append any options in config to the host_vars of a container
|
||||||
container_vars = host_options.get('container_vars')
|
container_vars = host_options.get('container_vars')
|
||||||
@ -415,8 +422,10 @@ def _add_container_hosts(assignment, config, container_name, container_type,
|
|||||||
# If host_type is not in config do not append containers to it
|
# If host_type is not in config do not append containers to it
|
||||||
if host_type not in config[physical_host_type]:
|
if host_type not in config[physical_host_type]:
|
||||||
continue
|
continue
|
||||||
append_if(array=inventory['lxc_hosts']['hosts'],
|
appended = append_if(array=inventory['lxc_hosts']['hosts'],
|
||||||
item=host_type)
|
item=host_type)
|
||||||
|
if appended:
|
||||||
|
logger.debug("%s added to lxc_hosts group", host_type)
|
||||||
|
|
||||||
# Get any set host options
|
# Get any set host options
|
||||||
host_options = config[physical_host_type][host_type]
|
host_options = config[physical_host_type][host_type]
|
||||||
@ -517,9 +526,10 @@ def user_defined_setup(config, inventory):
|
|||||||
hvs[_key][_k] = _v
|
hvs[_key][_k] = _v
|
||||||
|
|
||||||
USED_IPS.add(_value['ip'])
|
USED_IPS.add(_value['ip'])
|
||||||
logger.debug("Attempting to add host %s to group %s",
|
appended = append_if(array=inventory[key]['hosts'], item=_key)
|
||||||
_key, key)
|
if appended:
|
||||||
append_if(array=inventory[key]['hosts'], item=_key)
|
logger.debug("Added host %s to group %s",
|
||||||
|
_key, key)
|
||||||
|
|
||||||
|
|
||||||
def skel_setup(environment, inventory):
|
def skel_setup(environment, inventory):
|
||||||
@ -943,13 +953,13 @@ def append_if(array, item):
|
|||||||
|
|
||||||
:param array: ``list`` List object to append to
|
:param array: ``list`` List object to append to
|
||||||
:param item: ``object`` Object to append to the list
|
:param item: ``object`` Object to append to the list
|
||||||
:returns array: returns the amended list.
|
:returns bool: Flag indicating whether the append happend (True)
|
||||||
|
or not (False)
|
||||||
"""
|
"""
|
||||||
if item not in array:
|
if item not in array:
|
||||||
array.append(item)
|
array.append(item)
|
||||||
# TODO(nrb): Would be nice to change this to return true/false
|
return True
|
||||||
# for logging purposes.
|
return False
|
||||||
return array
|
|
||||||
|
|
||||||
|
|
||||||
def _merge_dict(base_items, new_items):
|
def _merge_dict(base_items, new_items):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user