Merge "Improve bifrost inventory module"
This commit is contained in:
commit
e490f27ada
@ -171,31 +171,26 @@ def _process_baremetal_data(data_source, groups, hostvars):
|
|||||||
"""Process data through as pre-formatted data"""
|
"""Process data through as pre-formatted data"""
|
||||||
with open(data_source, 'rb') as file_object:
|
with open(data_source, 'rb') as file_object:
|
||||||
try:
|
try:
|
||||||
file_data = json.load(file_object)
|
file_data = yaml.safe_load(file_object)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.debug("Attempting to parse JSON: %s" % e)
|
LOG.debug("Failed to parse JSON or YAML: %s" % e)
|
||||||
try:
|
raise Exception("Failed to parse JSON or YAML")
|
||||||
file_object.seek(0)
|
|
||||||
file_data = yaml.load(file_object)
|
|
||||||
except Exception as e:
|
|
||||||
LOG.debug("Attempting to parse YAML: %s" % e)
|
|
||||||
raise Exception("Failed to parse JSON and YAML")
|
|
||||||
|
|
||||||
for name in file_data:
|
for name in file_data:
|
||||||
host = file_data[name]
|
host = file_data[name]
|
||||||
# Perform basic validation
|
# Perform basic validation
|
||||||
if ('ipv4_address' not in host or
|
if ('ipv4_address' not in host or
|
||||||
not host['ipv4_address']):
|
not host['ipv4_address']):
|
||||||
host['addressing_mode'] = "dhcp"
|
host['addressing_mode'] = "dhcp"
|
||||||
else:
|
else:
|
||||||
host['ansible_ssh_host'] = host['ipv4_address']
|
host['ansible_ssh_host'] = host['ipv4_address']
|
||||||
|
|
||||||
if ('provisioning_ipv4_address' not in host and
|
if ('provisioning_ipv4_address' not in host and
|
||||||
'addressing_mode' not in host):
|
'addressing_mode' not in host):
|
||||||
host['provisioning_ipv4_address'] = host['ipv4_address']
|
host['provisioning_ipv4_address'] = host['ipv4_address']
|
||||||
# Add each host to the values to be returned.
|
# Add each host to the values to be returned.
|
||||||
groups['baremetal']['hosts'].append(host['name'])
|
groups['baremetal']['hosts'].append(host['name'])
|
||||||
hostvars.update({host['name']: host})
|
hostvars.update({host['name']: host})
|
||||||
return (groups, hostvars)
|
return (groups, hostvars)
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ unused,,00000000-0000-0000-0000-000000000002,hostname1,
|
|||||||
[{"mac": "00:01:02:03:04:05"}], "properties": {"ram": "8192",
|
[{"mac": "00:01:02:03:04:05"}], "properties": {"ram": "8192",
|
||||||
"cpu_arch": "x86_64", "disk_size": "512", "cpus": "1"}}}""".replace('\n', '')
|
"cpu_arch": "x86_64", "disk_size": "512", "cpus": "1"}}}""".replace('\n', '')
|
||||||
(groups, hostvars) = utils.bifrost_data_conversion(
|
(groups, hostvars) = utils.bifrost_data_conversion(
|
||||||
yaml.dump(json.loads(str(expected_hostvars))))
|
yaml.safe_dump(json.loads(str(expected_hostvars))))
|
||||||
self.assertDictEqual(json.loads(str(expected_hostvars)), hostvars)
|
self.assertDictEqual(json.loads(str(expected_hostvars)), hostvars)
|
||||||
|
|
||||||
def test_minimal_json(self):
|
def test_minimal_json(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user