1 ##############################################################################
2 # Copyright (c) 2016 Dan Radez (dradez@redhat.com) and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
14 class Inventory(dict):
16 This class parses an APEX inventory yaml file into an object. It
17 generates or detects all missing fields for deployment.
19 It then collapses one level of identifcation from the object to
20 convert it to a structure that can be dumped into a json file formatted
21 such that Triple-O can read the resulting json as an instackenv.json file.
23 def __init__(self, source, ha=True, virtual=False):
25 if type(source) is str:
26 with open(source, 'r') as network_settings_file:
27 yaml_dict = yaml.load(network_settings_file)
28 # collapse node identifiers from the structure
29 init_dict['nodes'] = list(map(lambda n: n[1],
30 yaml_dict['nodes'].items()))
32 # assume input is a dict to build from
37 def munge_nodes(node):
38 node['pm_addr'] = node['ipmi_ip']
39 node['pm_password'] = node['ipmi_pass']
40 node['pm_user'] = node['ipmi_user']
41 node['mac'] = [node['mac_address']]
43 for i in ('ipmi_ip', 'ipmi_pass', 'ipmi_user', 'mac_address'):
48 super().__init__({'nodes': list(map(munge_nodes, init_dict['nodes']))})
50 # verify number of nodes
51 if ha and len(self['nodes']) < 5:
52 raise InventoryException('You must provide at least 5 '
53 'nodes for HA baremetal deployment')
54 elif len(self['nodes']) < 2:
55 raise InventoryException('You must provide at least 2 nodes '
56 'for non-HA baremetal deployment${reset}')
59 self['arch'] = 'x86_64'
60 self['host-ip'] = '192.168.122.1'
61 self['power_manager'] = \
62 'nova.virt.baremetal.virtual_power_driver.VirtualPowerManager'
64 self['ssh-key'] = 'INSERT_STACK_USER_PRIV_KEY'
65 self['ssh-user'] = 'root'
67 def dump_instackenv_json(self):
68 print(json.dumps(dict(self), sort_keys=True, indent=4))
71 class InventoryException(Exception):
72 def __init__(self, value):