Use metalsmith for getting OC servers in inventory when available

The tripleo-inventory role gets a list of server ips
from which to collect logs.
This review allows that list to be gathered from metalsmith
rather than nova when that package is available and
baremetal_provision is defined and set to true.

Change-Id: I40dd4870327408c6151ceb7eb7fdd316c0018b14
This commit is contained in:
Ronelle Landy 2020-01-30 11:03:07 -05:00 committed by Sagi Shnaidman
parent f81189367e
commit d113a69f86
1 changed files with 11 additions and 0 deletions

View File

@ -19,6 +19,9 @@ import os
from distutils.version import LooseVersion
from keystoneauth1.identity import v3
from keystoneauth1 import session
{% if baremetal_provision|default(false)|bool %}
from metalsmith import Provisioner
{% endif %}
from novaclient import __version__ as nc_version
from novaclient import client
try:
@ -55,7 +58,15 @@ else:
session = session.Session(auth=auth, verify=False)
nova = client.Client(2, session=session)
{% if baremetal_provision|default(false)|bool %}
provisioner = Provisioner(session=session)
servers_list = provisioner.list_instances()
oc_servers = {server.hostname: server.ip_addresses()['ctlplane'][0]
for server in servers_list
if server.ip_addresses().get('ctlplane')}
{% else %}
oc_servers = {server.name: server.networks['ctlplane'][0]
for server in nova.servers.list()
if server.networks.get('ctlplane')}
{% endif %}
print(json.dumps(oc_servers, indent=4))