diff options
Diffstat (limited to 'src/resource_inventory/pdf_templater.py')
-rw-r--r-- | src/resource_inventory/pdf_templater.py | 53 |
1 files changed, 34 insertions, 19 deletions
diff --git a/src/resource_inventory/pdf_templater.py b/src/resource_inventory/pdf_templater.py index a50f04c..2302530 100644 --- a/src/resource_inventory/pdf_templater.py +++ b/src/resource_inventory/pdf_templater.py @@ -19,15 +19,15 @@ class PDFTemplater: """ @classmethod - def makePDF(cls, resource): + def makePDF(cls, booking): """ fills the pod descriptor file template with info about the resource """ template = "dashboard/pdf.yaml" info = {} - info['details'] = cls.get_pdf_details(resource) - info['jumphost'] = cls.get_pdf_jumphost(resource) - info['nodes'] = cls.get_pdf_nodes(resource) + info['details'] = cls.get_pdf_details(booking.resource) + info['jumphost'] = cls.get_pdf_jumphost(booking) + info['nodes'] = cls.get_pdf_nodes(booking) return render_to_string(template, context=info) @@ -63,26 +63,40 @@ class PDFTemplater: return details @classmethod - def get_pdf_jumphost(cls, resource): + def get_jumphost(cls, booking): + jumphost = None + if booking.opnfv_config: + jumphost_opnfv_config = booking.opnfv_config.host_opnfv_config.get( + role__name__iexact="jumphost" + ) + jumphost = booking.resource.hosts.get(config=jumphost_opnfv_config.host_config) + else: # if there is no opnfv config, use headnode + jumphost = Host.objects.filter( + bundle=booking.resource, + config__is_head_node=True + ).first() + + return jumphost + + @classmethod + def get_pdf_jumphost(cls, booking): """ returns a dict of all the info for the "jumphost" section """ - jumphost = Host.objects.get(bundle=resource, config__opnfvRole__name__iexact="jumphost") + jumphost = cls.get_jumphost(booking) 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 @classmethod - def get_pdf_nodes(cls, resource): + def get_pdf_nodes(cls, booking): """ returns a list of all the "nodes" (every host except jumphost) """ pdf_nodes = [] - nodes = Host.objects.filter(bundle=resource).exclude(config__opnfvRole__name__iexact="jumphost") + nodes = set(Host.objects.filter(bundle=booking.resource)) + nodes.discard(cls.get_jumphost(booking)) + for node in nodes: pdf_nodes.append(cls.get_pdf_host(node)) @@ -105,7 +119,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 @@ -168,11 +182,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 |