summaryrefslogtreecommitdiffstats
path: root/xci/playbooks/dynamic_inventory.py
diff options
context:
space:
mode:
Diffstat (limited to 'xci/playbooks/dynamic_inventory.py')
-rwxr-xr-xxci/playbooks/dynamic_inventory.py75
1 files changed, 62 insertions, 13 deletions
diff --git a/xci/playbooks/dynamic_inventory.py b/xci/playbooks/dynamic_inventory.py
index bf9483da..ed63141c 100755
--- a/xci/playbooks/dynamic_inventory.py
+++ b/xci/playbooks/dynamic_inventory.py
@@ -21,6 +21,12 @@ import json
class XCIInventory(object):
+ """
+
+ Generates the ansible inventory based on the idf and pdf files provided
+ when executing the deployment script
+
+ """
def __init__(self):
super(XCIInventory, self).__init__()
self.inventory = {}
@@ -42,12 +48,12 @@ class XCIInventory(object):
self.opnfv_networks = {}
self.opnfv_networks['opnfv'] = {}
- self.opnfv_networks['opnfv']['admin'] = {}
- self.opnfv_networks['opnfv']['admin']['address'] = '172.29.236.10/22'
+ self.opnfv_networks['opnfv']['mgmt'] = {}
+ self.opnfv_networks['opnfv']['mgmt']['address'] = '172.29.236.10/22'
self.opnfv_networks['opnfv']['public'] = {}
self.opnfv_networks['opnfv']['public']['address'] = '192.168.122.2/24'
self.opnfv_networks['opnfv']['public']['gateway'] = '192.168.122.1'
- self.opnfv_networks['opnfv']['public']['dns'] = '192.168.122.1'
+ self.opnfv_networks['opnfv']['public']['dns'] = ['192.168.122.1']
self.opnfv_networks['opnfv']['private'] = {}
self.opnfv_networks['opnfv']['private']['address'] = '172.29.240.10/22'
self.opnfv_networks['opnfv']['storage'] = {}
@@ -74,8 +80,10 @@ class XCIInventory(object):
self.args = parser.parse_args()
def read_pdf_idf(self):
- pdf_file = os.path.dirname(os.path.realpath(__file__)) + "/../var/pdf.yml"
- idf_file = os.path.dirname(os.path.realpath(__file__)) + "/../var/idf.yml"
+ pdf_file = os.environ['PDF']
+ idf_file = os.environ['IDF']
+ opnfv_file = os.path.dirname(os.path.realpath(__file__)) + "/../var/opnfv_vm_pdf.yml"
+ opnfv_idf_file = os.path.dirname(os.path.realpath(__file__)) + "/../var/opnfv_vm_idf.yml"
nodes = []
host_networks = {}
@@ -93,19 +101,34 @@ class XCIInventory(object):
print(e)
sys.exit(1)
- valid_host = (host for host in idf['xci'][self.installer]['nodes_roles'] \
+ with open(opnfv_file) as f:
+ try:
+ opnfv_pdf = yaml.safe_load(f)
+ except yaml.YAMLError as e:
+ print(e)
+ sys.exit(1)
+
+ with open(opnfv_idf_file) as f:
+ try:
+ opnfv_idf = yaml.safe_load(f)
+ except yaml.YAMLError as e:
+ print(e)
+ sys.exit(1)
+
+
+ valid_host = (host for host in idf['xci']['installers'][self.installer]['nodes_roles'] \
if host in idf['xci']['flavors'][self.flavor] \
and host != 'opnfv')
for host in valid_host:
nodes.append(host)
- hostname = idf['xci'][self.installer]['hostnames'][host]
+ hostname = idf['xci']['installers'][self.installer]['hostnames'][host]
self.add_host(hostname)
- for role in idf['xci'][self.installer]['nodes_roles'][host]:
+ for role in idf['xci']['installers'][self.installer]['nodes_roles'][host]:
self.add_to_group(role, hostname)
- pdf_host_info = filter(lambda x: x['name'] == host, pdf['nodes'])[0]
- native_vlan_if = filter(lambda x: x['vlan'] == 'native', pdf_host_info['interfaces'])
+ pdf_host_info = list(filter(lambda x: x['name'] == host, pdf['nodes']))[0]
+ native_vlan_if = list(filter(lambda x: x['vlan'] == 'native', pdf_host_info['interfaces']))
self.add_hostvar(hostname, 'ansible_host', native_vlan_if[0]['address'])
self.add_hostvar(hostname, 'ip', native_vlan_if[0]['address'])
host_networks[hostname] = {}
@@ -117,15 +140,41 @@ class XCIInventory(object):
if 'gateway' in ndata.keys():
host_networks[hostname][network]['gateway'] = str(ndata['gateway']) + "/" + str(ndata['mask'])
if 'dns' in ndata.keys():
- host_networks[hostname][network]['dns'] = str(ndata['dns'])
+ host_networks[hostname][network]['dns'] = []
+ for d in ndata['dns']:
+ host_networks[hostname][network]['dns'].append(str(d))
+
+ # Get also vlan and mac_address from pdf
+ host_networks[hostname][network]['mac_address'] = str(pdf_host_info['interfaces'][int(network_interface_num)]['mac_address'])
+ host_networks[hostname][network]['vlan'] = str(pdf_host_info['interfaces'][int(network_interface_num)]['vlan'])
+
+ # Get also vlan and mac_address from opnfv_pdf
+ mgmt_idf_index = int(opnfv_idf['opnfv_vm_idf']['net_config']['mgmt']['interface'])
+ opnfv_mgmt = opnfv_pdf['opnfv_vm_pdf']['interfaces'][mgmt_idf_index]
+ admin_idf_index = int(opnfv_idf['opnfv_vm_idf']['net_config']['admin']['interface'])
+ opnfv_public = opnfv_pdf['opnfv_vm_pdf']['interfaces'][admin_idf_index]
+ self.opnfv_networks['opnfv']['mgmt']['mac_address'] = str(opnfv_mgmt['mac_address'])
+ self.opnfv_networks['opnfv']['mgmt']['vlan'] = str(opnfv_mgmt['vlan'])
+ self.opnfv_networks['opnfv']['public']['mac_address'] = str(opnfv_public['mac_address'])
+ self.opnfv_networks['opnfv']['public']['vlan'] = str(opnfv_public['vlan'])
+
+ # Add the interfaces from idf
+
host_networks.update(self.opnfv_networks)
self.add_groupvar('all', 'host_info', host_networks)
+ if 'deployment_host_interfaces' in idf['xci']['installers'][self.installer]['network']:
+ mgmt_idf_index = int(opnfv_idf['opnfv_vm_idf']['net_config']['mgmt']['interface'])
+ admin_idf_index = int(opnfv_idf['opnfv_vm_idf']['net_config']['admin']['interface'])
+ self.add_hostvar('deployment_host', 'network_interface_admin', idf['xci']['installers'][self.installer]['network']['deployment_host_interfaces'][admin_idf_index])
+ self.add_hostvar('deployment_host', 'network_interface_mgmt', idf['xci']['installers'][self.installer]['network']['deployment_host_interfaces'][mgmt_idf_index])
+
# Now add the additional groups
- for parent in idf['xci'][self.installer]['groups'].keys():
- map(lambda x: self.add_group(x, parent), idf['xci'][self.installer]['groups'][parent])
+ for parent in idf['xci']['installers'][self.installer]['groups'].keys():
+ for host in idf['xci']['installers'][self.installer]['groups'][parent]:
+ self.add_group(host, parent)
# Read additional group variables
self.read_additional_group_vars()