Use the image name from the controller when creating a new template from an appliance.

This commit is contained in:
grossmj 2024-05-18 16:27:22 +07:00
parent a9bca2e265
commit 8f268e374c
No known key found for this signature in database
GPG Key ID: 0A2D76AC45EA25CD
2 changed files with 57 additions and 43 deletions

View File

@ -141,7 +141,7 @@
> >
<mat-icon aria-label="Refresh list of images">refresh</mat-icon></button <mat-icon aria-label="Refresh list of images">refresh</mat-icon></button
><br /> ><br />
<div> <div>
<div *ngFor="let version of applianceToInstall.versions"> <div *ngFor="let version of applianceToInstall.versions">
<div class="list-item"> <div class="list-item">
<span>{{ applianceToInstall.name }} version {{ version.name }}</span> <span>{{ applianceToInstall.name }} version {{ version.name }}</span>
@ -212,7 +212,7 @@
[uploader]="uploaderImage" [uploader]="uploaderImage"
/> />
<button class="button" mat-raised-button (click)="file2.click()">Import</button> <button class="button" mat-raised-button (click)="file2.click()">Import</button>
<button <button
class="button" class="button"
mat-raised-button mat-raised-button
@ -356,7 +356,7 @@
</div> </div>
<div *ngIf="applianceToInstall.docker"> <div *ngIf="applianceToInstall.docker">
<button mat-raised-button color="primary" (click)="createDockerTemplate()" class="create-button"> <button mat-raised-button color="primary" (click)="createDockerTemplate()" class="create-button">
Create docker template Create docker template
</button> </button>
@ -364,7 +364,7 @@
<div *ngIf="applianceToInstall.dynamips"> <div *ngIf="applianceToInstall.dynamips">
<div> <div>
Install required files Install the required images
<button <button
mat-icon-button mat-icon-button
matTooltip="Refresh list of images" matTooltip="Refresh list of images"
@ -376,10 +376,16 @@
<mat-list> <mat-list>
<mat-list-item *ngFor="let image of applianceToInstall.images"> <mat-list-item *ngFor="let image of applianceToInstall.images">
<div class="list-item"> <div class="list-item">
<div> <span>
{{ image.filename }} {{ image.filename }}
</div> </span>
<div> <div>
<span *ngIf="checkImageFromVersion(image.filename)"
><mat-icon matTooltip="Ready to install" matTooltipClass="custom-tooltip">check</mat-icon>
</span>
<span *ngIf="!checkImageFromVersion(image.filename)"
><mat-icon matTooltip="Missing" matTooltipClass="custom-tooltip">close</mat-icon>
</span>
<input <input
type="file" type="file"
class="non-visible" class="non-visible"
@ -401,7 +407,7 @@
<div *ngIf="applianceToInstall.iou"> <div *ngIf="applianceToInstall.iou">
<div> <div>
Install required files Install required images
<button <button
mat-icon-button mat-icon-button
matTooltip="Refresh list of images" matTooltip="Refresh list of images"
@ -417,6 +423,12 @@
{{ image.filename }} {{ image.filename }}
</div> </div>
<div> <div>
<span *ngIf="checkImageFromVersion(image.filename)"
><mat-icon matTooltip="Ready to install" matTooltipClass="custom-tooltip">check</mat-icon>
</span>
<span *ngIf="!checkImageFromVersion(image.filename)"
><mat-icon matTooltip="Missing" matTooltipClass="custom-tooltip">close</mat-icon>
</span>
<input <input
type="file" type="file"
class="non-visible" class="non-visible"

View File

@ -15,7 +15,7 @@ import { InformationDialogComponent } from '../../../components/dialogs/informat
import { Appliance, Image, Version } from '../../../models/appliance'; import { Appliance, Image, Version } from '../../../models/appliance';
import { Project } from '../../../models/project'; import { Project } from '../../../models/project';
import { QemuBinary } from '../../../models/qemu/qemu-binary'; import { QemuBinary } from '../../../models/qemu/qemu-binary';
import{ Controller } from '../../../models/controller'; import { Controller } from '../../../models/controller';
import { Template } from '../../../models/template'; import { Template } from '../../../models/template';
import { DockerTemplate } from '../../../models/templates/docker-template'; import { DockerTemplate } from '../../../models/templates/docker-template';
import { IosTemplate } from '../../../models/templates/ios-template'; import { IosTemplate } from '../../../models/templates/ios-template';
@ -179,7 +179,7 @@ export class NewTemplateDialogComponent implements OnInit {
status: number, status: number,
headers: ParsedResponseHeaders headers: ParsedResponseHeaders
) => { ) => {
this.toasterService.error('An error has occured because image already exists'); this.toasterService.error('An error has occurred because image already exists');
this.progressService.deactivate(); this.progressService.deactivate();
this.uploaderImage.clearQueue(); this.uploaderImage.clearQueue();
}; };
@ -190,7 +190,7 @@ export class NewTemplateDialogComponent implements OnInit {
status: number, status: number,
headers: ParsedResponseHeaders headers: ParsedResponseHeaders
) => { ) => {
this.toasterService.success('Image imported succesfully'); this.toasterService.success('Image successfully imported');
this.refreshImages(); this.refreshImages();
this.progressService.deactivate(); this.progressService.deactivate();
this.uploaderImage.clearQueue(); this.uploaderImage.clearQueue();
@ -418,23 +418,6 @@ export class NewTemplateDialogComponent implements OnInit {
return false; return false;
} }
checkImages(version: Version): boolean {
if (version.images.hdb_disk_image) {
if (
this.checkImageFromVersion(version.images.hda_disk_image) &&
this.checkImageFromVersion(version.images.hdb_disk_image)
)
return true;
return false;
}
if (this.checkImageFromVersion(version.images.hda_disk_image)) {
return true;
} else {
return false;
}
}
openConfirmationDialog(message: string, link: string) { openConfirmationDialog(message: string, link: string) {
const dialogRef = this.dialog.open(InformationDialogComponent, { const dialogRef = this.dialog.open(InformationDialogComponent, {
width: '400px', width: '400px',
@ -481,19 +464,26 @@ export class NewTemplateDialogComponent implements OnInit {
} }
createIouTemplate(image: Image) { createIouTemplate(image: Image) {
let iou_image = image.filename;
let imageToInstall = this.applianceToInstall.images.filter((n) => n.filename === iou_image)[0];
let imageToUse = this.iouImages.filter((n) => n.checksum === imageToInstall.md5sum);
if (imageToUse.length > 0) {
iou_image = imageToUse[0].filename; // use the image name from the controller
}
let iouTemplate: IouTemplate = new IouTemplate(); let iouTemplate: IouTemplate = new IouTemplate();
iouTemplate.nvram = this.applianceToInstall.iou.nvram; iouTemplate.nvram = this.applianceToInstall.iou.nvram;
iouTemplate.ram = this.applianceToInstall.iou.ram; iouTemplate.ram = this.applianceToInstall.iou.ram;
iouTemplate.ethernet_adapters = this.applianceToInstall.iou.ethernet_adapters; iouTemplate.ethernet_adapters = this.applianceToInstall.iou.ethernet_adapters;
iouTemplate.serial_adapters = this.applianceToInstall.iou.serial_adapters; iouTemplate.serial_adapters = this.applianceToInstall.iou.serial_adapters;
iouTemplate.startup_config = this.applianceToInstall.iou.startup_config; iouTemplate.startup_config = this.applianceToInstall.iou.startup_config;
iouTemplate.builtin = this.applianceToInstall.builtin;
iouTemplate.category = this.getCategory(); iouTemplate.category = this.getCategory();
iouTemplate.default_name_format = this.applianceToInstall.default_name_format; iouTemplate.default_name_format = this.applianceToInstall.default_name_format;
iouTemplate.symbol = this.applianceToInstall.symbol; iouTemplate.symbol = this.applianceToInstall.symbol;
iouTemplate.compute_id = 'local'; iouTemplate.compute_id = 'local';
iouTemplate.template_id = uuid(); iouTemplate.template_id = uuid();
iouTemplate.path = image.filename; iouTemplate.path = iou_image;
iouTemplate.template_type = 'iou'; iouTemplate.template_type = 'iou';
const dialogRef = this.dialog.open(TemplateNameDialogComponent, { const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
@ -521,6 +511,14 @@ export class NewTemplateDialogComponent implements OnInit {
} }
createIosTemplate(image: Image) { createIosTemplate(image: Image) {
let ios_image = image.filename;
let imageToInstall = this.applianceToInstall.images.filter((n) => n.filename === ios_image)[0];
let imageToUse = this.iosImages.filter((n) => n.checksum === imageToInstall.md5sum);
if (imageToUse.length > 0) {
ios_image = imageToUse[0].filename; // use the image name from the controller
}
let iosTemplate: IosTemplate = new IosTemplate(); let iosTemplate: IosTemplate = new IosTemplate();
iosTemplate.chassis = this.applianceToInstall.dynamips.chassis; iosTemplate.chassis = this.applianceToInstall.dynamips.chassis;
iosTemplate.nvram = this.applianceToInstall.dynamips.nvram; iosTemplate.nvram = this.applianceToInstall.dynamips.nvram;
@ -535,13 +533,12 @@ export class NewTemplateDialogComponent implements OnInit {
iosTemplate.slot5 = this.applianceToInstall.dynamips.slot5; iosTemplate.slot5 = this.applianceToInstall.dynamips.slot5;
iosTemplate.slot6 = this.applianceToInstall.dynamips.slot6; iosTemplate.slot6 = this.applianceToInstall.dynamips.slot6;
iosTemplate.slot7 = this.applianceToInstall.dynamips.slot7; iosTemplate.slot7 = this.applianceToInstall.dynamips.slot7;
iosTemplate.builtin = this.applianceToInstall.builtin;
iosTemplate.category = this.getCategory(); iosTemplate.category = this.getCategory();
iosTemplate.default_name_format = this.applianceToInstall.default_name_format; iosTemplate.default_name_format = this.applianceToInstall.default_name_format;
iosTemplate.symbol = this.applianceToInstall.symbol; iosTemplate.symbol = this.applianceToInstall.symbol;
iosTemplate.compute_id = 'local'; iosTemplate.compute_id = 'local';
iosTemplate.template_id = uuid(); iosTemplate.template_id = uuid();
iosTemplate.image = image.filename; iosTemplate.image = ios_image;
iosTemplate.template_type = 'dynamips'; iosTemplate.template_type = 'dynamips';
const dialogRef = this.dialog.open(TemplateNameDialogComponent, { const dialogRef = this.dialog.open(TemplateNameDialogComponent, {
@ -573,7 +570,6 @@ export class NewTemplateDialogComponent implements OnInit {
let dockerTemplate: DockerTemplate = new DockerTemplate(); let dockerTemplate: DockerTemplate = new DockerTemplate();
dockerTemplate.adapters = this.applianceToInstall.docker.adapters; dockerTemplate.adapters = this.applianceToInstall.docker.adapters;
dockerTemplate.console_type = this.applianceToInstall.docker.console_type; dockerTemplate.console_type = this.applianceToInstall.docker.console_type;
dockerTemplate.builtin = this.applianceToInstall.builtin;
dockerTemplate.category = this.getCategory(); dockerTemplate.category = this.getCategory();
dockerTemplate.default_name_format = this.applianceToInstall.default_name_format; dockerTemplate.default_name_format = this.applianceToInstall.default_name_format;
dockerTemplate.symbol = this.applianceToInstall.symbol; dockerTemplate.symbol = this.applianceToInstall.symbol;
@ -607,12 +603,19 @@ export class NewTemplateDialogComponent implements OnInit {
}); });
} }
createQemuTemplateFromVersion(version: Version) { findControllerImageName(image_name) {
if (!this.checkImages(version)) {
this.toasterService.error('Please install required images first');
return;
}
if (image_name) {
let imageToInstall = this.applianceToInstall.images.filter((n) => n.filename === image_name)[0];
let imageToUse = this.qemuImages.filter((n) => n.checksum === imageToInstall.md5sum);
if (imageToUse.length > 0) {
image_name = imageToUse[0].filename; // use the image name from the controller
}
}
return image_name;
}
createQemuTemplateFromVersion(version: Version) {
let qemuTemplate: QemuTemplate = new QemuTemplate(); let qemuTemplate: QemuTemplate = new QemuTemplate();
qemuTemplate.ram = this.applianceToInstall.qemu.ram; qemuTemplate.ram = this.applianceToInstall.qemu.ram;
qemuTemplate.adapters = this.applianceToInstall.qemu.adapters; qemuTemplate.adapters = this.applianceToInstall.qemu.adapters;
@ -623,7 +626,6 @@ export class NewTemplateDialogComponent implements OnInit {
qemuTemplate.hdb_disk_interface = this.applianceToInstall.qemu.hdb_disk_interface; qemuTemplate.hdb_disk_interface = this.applianceToInstall.qemu.hdb_disk_interface;
qemuTemplate.hdc_disk_interface = this.applianceToInstall.qemu.hdc_disk_interface; qemuTemplate.hdc_disk_interface = this.applianceToInstall.qemu.hdc_disk_interface;
qemuTemplate.hdd_disk_interface = this.applianceToInstall.qemu.hdd_disk_interface; qemuTemplate.hdd_disk_interface = this.applianceToInstall.qemu.hdd_disk_interface;
qemuTemplate.builtin = this.applianceToInstall.builtin;
qemuTemplate.category = this.getCategory(); qemuTemplate.category = this.getCategory();
qemuTemplate.first_port_name = this.applianceToInstall.first_port_name; qemuTemplate.first_port_name = this.applianceToInstall.first_port_name;
qemuTemplate.port_name_format = this.applianceToInstall.port_name_format; qemuTemplate.port_name_format = this.applianceToInstall.port_name_format;
@ -632,11 +634,11 @@ export class NewTemplateDialogComponent implements OnInit {
qemuTemplate.symbol = this.applianceToInstall.symbol; qemuTemplate.symbol = this.applianceToInstall.symbol;
qemuTemplate.compute_id = 'local'; qemuTemplate.compute_id = 'local';
qemuTemplate.template_id = uuid(); qemuTemplate.template_id = uuid();
qemuTemplate.hda_disk_image = version.images.hda_disk_image; qemuTemplate.hda_disk_image = this.findControllerImageName(version.images.hda_disk_image);
qemuTemplate.hdb_disk_image = version.images.hdb_disk_image; qemuTemplate.hdb_disk_image = this.findControllerImageName(version.images.hdb_disk_image);
qemuTemplate.hdc_disk_image = version.images.hdc_disk_image; qemuTemplate.hdc_disk_image = this.findControllerImageName(version.images.hdc_disk_image);
qemuTemplate.hdd_disk_image = version.images.hdd_disk_image; qemuTemplate.hdd_disk_image = this.findControllerImageName(version.images.hdd_disk_image);
qemuTemplate.cdrom_image = version.images.cdrom_image; qemuTemplate.cdrom_image = this.findControllerImageName(version.images.cdrom_image);
qemuTemplate.template_type = 'qemu'; qemuTemplate.template_type = 'qemu';
qemuTemplate.usage = this.applianceToInstall.usage; qemuTemplate.usage = this.applianceToInstall.usage;
qemuTemplate.platform = this.applianceToInstall.qemu.arch; qemuTemplate.platform = this.applianceToInstall.qemu.arch;