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, resource):
24 fills the pod descriptor file template with info about the resource
26 template = "dashboard/pdf.yaml"
28 info['details'] = cls.get_pdf_details(resource)
29 info['jumphost'] = cls.get_pdf_jumphost(resource)
30 info['nodes'] = cls.get_pdf_nodes(resource)
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_pdf_jumphost(cls, resource):
68 returns a dict of all the info for the "jumphost" section
70 jumphost = Host.objects.get(bundle=resource, config__opnfvRole__name__iexact="jumphost")
71 jumphost_info = cls.get_pdf_host(jumphost)
72 remote_params = jumphost_info['remote_management'] # jumphost has extra block not in normal hosts
73 remote_params.pop("address")
74 remote_params.pop("mac_address")
75 jumphost_info['remote_params'] = remote_params
76 jumphost_info['os'] = jumphost.config.image.os.name
80 def get_pdf_nodes(cls, resource):
82 returns a list of all the "nodes" (every host except jumphost)
85 nodes = Host.objects.filter(bundle=resource).exclude(config__opnfvRole__name__iexact="jumphost")
87 pdf_nodes.append(cls.get_pdf_host(node))
92 def get_pdf_host(cls, host):
94 method to gather all needed info about a host
98 host_info['name'] = host.template.resource.name
99 host_info['node'] = cls.get_pdf_host_node(host)
100 host_info['disks'] = []
101 for disk in host.profile.storageprofile.all():
102 host_info['disks'].append(cls.get_pdf_host_disk(disk))
104 host_info['interfaces'] = []
105 for interface in host.interfaces.all():
106 host_info['interfaces'].append(cls.get_pdf_host_iface(interface))
108 host_info['remote_management'] = cls.get_pdf_host_remote_management(host)
113 def get_pdf_host_node(cls, host):
115 returns "node" info for a given host
118 d['type'] = "baremetal"
119 d['vendor'] = host.vendor
120 d['model'] = host.model
121 d['memory'] = str(host.profile.ramprofile.first().amount) + "G"
123 cpu = host.profile.cpuprofile.first()
124 d['arch'] = cpu.architecture
126 d['cores'] = cpu.cores
128 if cflags and cflags.strip():
129 d['cpu_cflags'] = cflags
131 d['cpu_cflags'] = "none"
136 def get_pdf_host_disk(cls, disk):
138 returns a dict describing the given disk
141 disk_info['name'] = disk.name
142 disk_info['capacity'] = str(disk.size) + "G"
143 disk_info['type'] = disk.media_type
144 disk_info['interface'] = disk.interface
145 disk_info['rotation'] = disk.rotation
149 def get_pdf_host_iface(cls, interface):
151 returns a dict describing given interface
154 iface_info['features'] = "none"
155 iface_info['mac_address'] = interface.mac_address
156 iface_info['name'] = interface.name
159 profile = InterfaceProfile.objects.get(host=interface.host.profile, name=interface.name)
160 speed = str(int(profile.speed / 1000)) + "gb"
163 iface_info['speed'] = speed
167 def get_pdf_host_remote_management(cls, host):
169 gives the remote params of the host
172 mgmt['address'] = "I dunno"
173 mgmt['mac_address'] = "I dunno"
174 mgmt['pass'] = "I dunno"
175 mgmt['type'] = "I dunno"
176 mgmt['user'] = "I dunno"
177 mgmt['versions'] = ["I dunno"]