def update_facts_by_namespace(operation, host_id_list, namespace, fact_dict): hosts_to_update = find_non_culled_hosts( Host.query.filter( (Host.account == current_identity.account_number) & Host.id.in_(host_id_list) & Host.facts.has_key(namespace) # noqa: W601 JSONB query filter, not a dict ) ).all() logger.debug("hosts_to_update:%s", hosts_to_update) if len(hosts_to_update) != len(host_id_list): error_msg = ( "ERROR: The number of hosts requested does not match the number of hosts found in the host database. " "This could happen if the namespace does not exist or the account number associated with the call does " "not match the account number associated with one or more the hosts. Rejecting the fact change request." ) logger.debug(error_msg) return error_msg, 400 for host in hosts_to_update: if operation is FactOperations.replace: host.replace_facts_in_namespace(namespace, fact_dict) else: host.merge_facts_in_namespace(namespace, fact_dict) db.session.commit() logger.debug("hosts_to_update:%s", hosts_to_update) return 200
def _get_host_list_by_id_list(account_number, host_id_list): return find_non_culled_hosts(Host.query.filter((Host.account == account_number) & Host.id.in_(host_id_list)))
def _get_host_list_by_id_list(host_id_list): current_identity = get_current_identity() query = Host.query.filter((Host.account == current_identity.account_number) & Host.id.in_(host_id_list)) return find_non_culled_hosts( update_query_for_owner_id(current_identity, query))