1 ##############################################################################
2 # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, 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 ##############################################################################
11 from django.template.loader import render_to_string
13 from resource_inventory.models import Host, InterfaceProfile
18 Utility class to create a full PDF yaml file
22 def makePDF(cls, booking):
24 fills the pod descriptor file template with info about the resource
26 template = "dashboard/pdf.yaml"
28 info['details'] = cls.get_pdf_details(booking.resource)
29 info['jumphost'] = cls.get_pdf_jumphost(booking)
30 info['nodes'] = cls.get_pdf_nodes(booking)
32 return render_to_string(template, context=info)
35 def get_pdf_details(cls, resource):
37 Info for the "details" section
41 email = "email@mail.com"
42 resource_lab = resource.template.lab
43 lab = resource_lab.name
44 location = resource_lab.location
45 pod_type = "development"
46 link = "https://wiki.opnfv.org/display/INF/Pharos+Laas"
49 # try to get more specific info that may fail, we dont care if it does
50 booking_owner = booking.models.Booking.objects.get(resource=resource).owner
51 owner = booking_owner.username
52 email = booking_owner.userprofile.email_addr
56 details['contact'] = email
58 details['link'] = link
59 details['owner'] = owner
60 details['location'] = location
61 details['type'] = pod_type
66 def get_jumphost(cls, booking):
68 if booking.opnfv_config:
69 jumphost_opnfv_config = booking.opnfv_config.host_opnfv_config.get(
70 role__name__iexact="jumphost"
72 jumphost = booking.resource.hosts.get(config=jumphost_opnfv_config.host_config)
73 else: # if there is no opnfv config, use headnode
74 jumphost = Host.objects.filter(
75 bundle=booking.resource,
76 config__is_head_node=True
82 def get_pdf_jumphost(cls, booking):
84 returns a dict of all the info for the "jumphost" section
86 jumphost = cls.get_jumphost(booking)
87 jumphost_info = cls.get_pdf_host(jumphost)
88 jumphost_info['os'] = jumphost.config.image.os.name
92 def get_pdf_nodes(cls, booking):
94 returns a list of all the "nodes" (every host except jumphost)
97 nodes = set(Host.objects.filter(bundle=booking.resource))
98 nodes.discard(cls.get_jumphost(booking))
101 pdf_nodes.append(cls.get_pdf_host(node))
106 def get_pdf_host(cls, host):
108 method to gather all needed info about a host
112 host_info['name'] = host.template.resource.name
113 host_info['node'] = cls.get_pdf_host_node(host)
114 host_info['disks'] = []
115 for disk in host.profile.storageprofile.all():
116 host_info['disks'].append(cls.get_pdf_host_disk(disk))
118 host_info['interfaces'] = []
119 for interface in host.interfaces.all():
120 host_info['interfaces'].append(cls.get_pdf_host_iface(interface))
122 host_info['remote'] = cls.get_pdf_host_remote_management(host)
127 def get_pdf_host_node(cls, host):
129 returns "node" info for a given host
132 d['type'] = "baremetal"
133 d['vendor'] = host.vendor
134 d['model'] = host.model
135 d['memory'] = str(host.profile.ramprofile.first().amount) + "G"
137 cpu = host.profile.cpuprofile.first()
138 d['arch'] = cpu.architecture
140 d['cores'] = cpu.cores
142 if cflags and cflags.strip():
143 d['cpu_cflags'] = cflags
145 d['cpu_cflags'] = "none"
150 def get_pdf_host_disk(cls, disk):
152 returns a dict describing the given disk
155 disk_info['name'] = disk.name
156 disk_info['capacity'] = str(disk.size) + "G"
157 disk_info['type'] = disk.media_type
158 disk_info['interface'] = disk.interface
159 disk_info['rotation'] = disk.rotation
163 def get_pdf_host_iface(cls, interface):
165 returns a dict describing given interface
168 iface_info['features'] = "none"
169 iface_info['mac_address'] = interface.mac_address
170 iface_info['name'] = interface.name
173 profile = InterfaceProfile.objects.get(host=interface.host.profile, name=interface.name)
174 speed = str(int(profile.speed / 1000)) + "gb"
177 iface_info['speed'] = speed
181 def get_pdf_host_remote_management(cls, host):
183 gives the remote params of the host
185 man = host.remote_management
187 mgmt['address'] = man.address
188 mgmt['mac_address'] = man.mac_address
189 mgmt['pass'] = man.password
190 mgmt['type'] = man.management_type
191 mgmt['user'] = man.user
192 mgmt['versions'] = [man.versions]