Created
October 16, 2018 17:21
-
-
Save goneri/8bbccb88fafbc8fa55ac816a540a2c7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import subprocess | |
def print_result(oc_hosts_by_nova_id, groups): | |
print("undercloud ansible_user=stack\n") | |
for i in oc_hosts_by_nova_id.values(): | |
str_fmt = ( | |
"%(Name)s ansible_host=%(IpAddress)s " | |
"ansible_user=heat-admin ansible_ssh_common_args='" | |
" -o ProxyJump=stack@undercloud'") | |
print(str_fmt % i) | |
print("\n[overcloud_nodes]") | |
for i in oc_hosts_by_nova_id.values(): | |
print(i['Name']) | |
print("\n[openstack_nodes]") | |
for i in oc_hosts_by_nova_id.values(): | |
print(i['Name']) | |
for name, nodes in groups.items(): | |
print("\n[%s]" % name) | |
for i in nodes: | |
print(i['Name']) | |
print("[tester]\n" | |
"undercloud\n\n" | |
"[shade]\n" | |
"localhost\n\n" | |
"[undercloud]\n" | |
"undercloud\n\n" | |
"[local]\n" | |
"localhost ansible_connection=local ansible_python_interpreter=python\n") | |
stdout = subprocess.check_output('source /home/stack/stackrc && openstack server list --format=json', shell=True) | |
oc_hosts_by_nova_id = {} | |
oc_hosts_by_ironic_id = {} | |
for i in json.loads(stdout): | |
oc_hosts_by_nova_id[i['ID']] = i | |
for i in oc_hosts_by_nova_id.values(): | |
i['IpAddress'] = i['Networks'].split('=')[1] | |
stdout = subprocess.check_output('source /home/stack/stackrc && openstack baremetal node list --format=json', shell=True) | |
for i in json.loads(stdout): | |
oc_host = oc_hosts_by_nova_id[i['Instance UUID']] | |
oc_hosts_by_ironic_id[i['UUID']] = oc_host | |
groups = {} | |
stdout = subprocess.check_output('source /home/stack/stackrc && openstack overcloud profiles list --format=json', shell=True) | |
for i in json.loads(stdout): | |
oc_host = oc_hosts_by_ironic_id[i['Node UUID']] | |
if i['Current Profile'] not in groups: | |
groups[i['Current Profile']] = [] | |
groups[i['Current Profile']].append(oc_host) | |
print_result(oc_hosts_by_nova_id, groups) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment