diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2019-04-12 12:24:34 -0400 |
---|---|---|
committer | Parker Berberian <pberberian@iol.unh.edu> | 2019-04-17 10:18:45 -0400 |
commit | 9693b9e4185f5dfc658655aef0156f36453133ee (patch) | |
tree | baabbd8820ea2e62b3d667cbe238f64d31fcbe82 /src/resource_inventory | |
parent | d8e9f0e33648426a95ae50bf27fa089036f6a1fd (diff) |
Fixes the idf and pdf templates so that we can deploy opnfv
Change-Id: I0091629f8f0af423210b2e81210d65239e9662b4
Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory')
-rw-r--r-- | src/resource_inventory/admin.py | 5 | ||||
-rw-r--r-- | src/resource_inventory/idf_templater.py | 148 | ||||
-rw-r--r-- | src/resource_inventory/pdf_templater.py | 19 |
3 files changed, 159 insertions, 13 deletions
diff --git a/src/resource_inventory/admin.py b/src/resource_inventory/admin.py index e063cc0..7ff510b 100644 --- a/src/resource_inventory/admin.py +++ b/src/resource_inventory/admin.py @@ -32,7 +32,8 @@ from resource_inventory.models import ( OPNFVConfig, OPNFVRole, Image, - HostConfiguration + HostConfiguration, + RemoteInfo ) profiles = [HostProfile, InterfaceProfile, DiskProfile, CpuProfile, RamProfile] @@ -47,6 +48,6 @@ physical = [Host, Interface, Network, Vlan, ResourceBundle] admin.site.register(physical) -config = [Scenario, Installer, Opsys, ConfigBundle, OPNFVConfig, OPNFVRole, Image, HostConfiguration] +config = [Scenario, Installer, Opsys, ConfigBundle, OPNFVConfig, OPNFVRole, Image, HostConfiguration, RemoteInfo] admin.site.register(config) diff --git a/src/resource_inventory/idf_templater.py b/src/resource_inventory/idf_templater.py new file mode 100644 index 0000000..7cd13bb --- /dev/null +++ b/src/resource_inventory/idf_templater.py @@ -0,0 +1,148 @@ +############################################################################## +# Copyright (c) 2019 Parker Berberian, Sawyer Bergeron, and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + + +from django.template.loader import render_to_string + +from account.models import PublicNetwork + +from resource_inventory.models import ( + OPNFVConfig, + Vlan +) + + +class IDFTemplater: + """ + Utility class to create a full IDF yaml file + """ + def __init__(self): + self.net_names = ["admin", "mgmt", "private", "public"] + self.networks = {} + for i, name in enumerate(self.net_names): + self.networks[name] = { + "name": name, + "vlan": -1, + "interface": i, + "ip": "10.250." + str(i) + ".0", + "netmask": 24 + } + + def makeIDF(self, booking): + """ + fills the installer descriptor file template with info about the resource + """ + template = "dashboard/idf.yaml" + info = {} + info['version'] = "0.1" + info['net_config'] = self.get_net_config(booking) + info['fuel'] = self.get_fuel_config(booking) + + return render_to_string(template, context=info) + + def get_net_config(self, booking): + net_config = {} + try: + net_config['oob'] = self.get_oob_net(booking) + except Exception: + net_config['oob'] = {} + try: + net_config['public'] = self.get_public_net(booking) + except Exception: + net_config['public'] = {} + + for net in [net for net in self.net_names if net != "public"]: + try: + net_config[net] = self.get_single_net_config(booking, net) + except Exception: + net_config[net] = {} + + return net_config + + def get_public_net(self, booking): + public = {} + config = OPNFVConfig.objects.get(bundle=booking.config_bundle) + public_role = config.networks.get(name="public") + public_vlan = Vlan.objects.filter(network=public_role.network).first() + public_network = PublicNetwork.objects.get(vlan=public_vlan.vlan_id, lab=booking.lab) + self.networks['public']['vlan'] = public_vlan.vlan_id + public['interface'] = self.networks['public']['interface'] + public['vlan'] = public_network.vlan # untagged?? + public['network'] = public_network.cidr.split("/")[0] + public['mask'] = public_network.cidr.split("/")[1] + # public['ip_range'] = 4 # necesary? + public['gateway'] = public_network.gateway + public['dns'] = ["1.1.1.1", "8.8.8.8"] + + return public + + def get_oob_net(self, booking): + net = {} + hosts = booking.resource.hosts.all() + addrs = [host.remote_management.address for host in hosts] + net['ip_range'] = ",".join(addrs) + net['vlan'] = "native" + return net + + def get_single_net_config(self, booking, net_name): + config = OPNFVConfig.objects.get(bundle=booking.config_bundle) + role = config.networks.get(name=net_name) + vlan = Vlan.objects.filter(network=role.network).first() + self.networks[net_name]['vlan'] = vlan.vlan_id + net = {} + net['interface'] = self.networks[net_name]['interface'] + net['vlan'] = vlan.vlan_id + net['network'] = self.networks[net_name]['ip'] + net['mask'] = self.networks[net_name]['netmask'] + + return net + + def get_fuel_config(self, booking): + fuel = {} + fuel['jumphost'] = {} + try: + fuel['jumphost']['bridges'] = self.get_fuel_bridges() + except Exception: + fuel['jumphost']['bridges'] = {} + + fuel['network'] = {} + try: + fuel['network']['nodes'] = self.get_fuel_nodes(booking) + except Exception: + fuel['network']['nodes'] = {} + + return fuel + + def get_fuel_bridges(self): + bridges = {} + for net in self.net_names: + bridges[net] = "br-" + net + + return bridges + + def get_fuel_nodes(self, booking): + hosts = booking.resource.hosts.exclude(config__opnfvRole__name="jumphost") + nodes = [] + for host in hosts: + node = {} + ordered_interfaces = self.get_node_interfaces(host) + node['interfaces'] = [iface['name'] for iface in ordered_interfaces] + node['bus_addrs'] = [iface['bus'] for iface in ordered_interfaces] + nodes.append(node) + + return nodes + + def get_node_interfaces(self, node): + # TODO: this should sync with pdf ordering + interfaces = [] + + for iface in node.interfaces.all(): + interfaces.append({"name": iface.name, "bus": iface.bus_address}) + + return interfaces diff --git a/src/resource_inventory/pdf_templater.py b/src/resource_inventory/pdf_templater.py index 9f7e7f1..2db2129 100644 --- a/src/resource_inventory/pdf_templater.py +++ b/src/resource_inventory/pdf_templater.py @@ -69,10 +69,6 @@ class PDFTemplater: """ jumphost = Host.objects.get(bundle=resource, config__opnfvRole__name__iexact="jumphost") jumphost_info = cls.get_pdf_host(jumphost) - remote_params = jumphost_info['remote_management'] # jumphost has extra block not in normal hosts - remote_params.pop("address") - remote_params.pop("mac_address") - jumphost_info['remote_params'] = remote_params jumphost_info['os'] = jumphost.config.image.os.name return jumphost_info @@ -105,7 +101,7 @@ class PDFTemplater: for interface in host.interfaces.all(): host_info['interfaces'].append(cls.get_pdf_host_iface(interface)) - host_info['remote_management'] = cls.get_pdf_host_remote_management(host) + host_info['remote'] = cls.get_pdf_host_remote_management(host) return host_info @@ -163,11 +159,12 @@ class PDFTemplater: """ gives the remote params of the host """ + man = host.remote_management mgmt = {} - mgmt['address'] = "I dunno" - mgmt['mac_address'] = "I dunno" - mgmt['pass'] = "I dunno" - mgmt['type'] = "I dunno" - mgmt['user'] = "I dunno" - mgmt['versions'] = ["I dunno"] + mgmt['address'] = man.address + mgmt['mac_address'] = man.mac_address + mgmt['pass'] = man.password + mgmt['type'] = man.management_type + mgmt['user'] = man.user + mgmt['versions'] = [man.versions] return mgmt |