def set_hosts_roles(client, cluster_id): hosts = [] libvirt_macs = utils.get_libvirt_nodes_mac_role_ip_and_name() inventory_hosts = client.get_cluster_hosts(cluster_id) assert len(libvirt_macs) == len(inventory_hosts) for host in inventory_hosts: hw = json.loads(host["hardware_info"]) role = [libvirt_macs[nic["mac"]]["role"] for nic in hw["nics"] if nic["mac"].lower() in libvirt_macs][0] hosts.append({"id": host["id"], "role": role}) if hosts: client.set_hosts_roles(cluster_id=cluster_id, hosts_with_roles=hosts)
def set_hosts_roles(client, cluster_id, network_name): added_hosts = [] libvirt_nodes = utils.get_libvirt_nodes_mac_role_ip_and_name(network_name) inventory_hosts = client.get_cluster_hosts(cluster_id) for libvirt_mac, libvirt_metadata in libvirt_nodes.items(): for host in inventory_hosts: hw = json.loads(host["hardware_info"]) if libvirt_mac.lower() in map(lambda nic: nic["mac"].lower(), hw["nics"]): added_hosts.append({"id": host["id"], "role": libvirt_metadata["role"]}) assert len(libvirt_nodes) == len(added_hosts), "All nodes should have matching inventory hosts" client.set_hosts_roles(cluster_id=cluster_id, hosts_with_roles=added_hosts)