Add logic to allow bifrost_inventory to run without shade

The dynamic inventory script only requires shade when querying
ironic for a list of hardware resources.  As we may not have
completed the installation sequence, shade may not be present.

Added a check to attempt to load shade and then error if a user
attempts to use the script to query ironic with shade missing.

Change-Id: I300e043bd76d4872781b42e05a5eb76a30a74f5e
This commit is contained in:
Julia Kreger 2015-06-26 14:06:47 -04:00
parent 761e345a66
commit 95d28e0eee

View File

@ -119,7 +119,12 @@ import yaml
from oslo_config import cfg
from oslo_log import log
import shade
try:
import shade
SHADE_LOADED = True
except ImportError:
SHADE_LOADED = False
LOG = log.getLogger(__name__)
@ -354,7 +359,13 @@ def main():
"Tried JSON, YAML, and CSV formats")
exit(1)
elif "ironic" in data_source:
(groups, hostvars) = _process_shade(groups, hostvars)
if SHADE_LOADED:
(groups, hostvars) = _process_shade(groups, hostvars)
else:
print("ERROR: BIFROST_INVENTORY_SOURCE is set to ironic "
"however the shade library failed to load, and may "
"not be present.")
exit(1)
else:
print('ERROR: BIFROST_INVENTORY_SOURCE does not define a file')
exit(1)