This commit is contained in:
piotrpekala7 2020-08-05 12:24:51 +02:00
parent b78f3824fc
commit d0e6318198
4 changed files with 89 additions and 25 deletions

View File

@ -139,16 +139,26 @@
</mat-select>
</div>
<div>
Install required files
<mat-list>
<mat-list-item *ngFor="let image of applianceToInstall.images">
Install required files <br/>
<div>
<div *ngFor="let version of applianceToInstall.versions">
<div class="list-item">
<span>{{applianceToInstall.name}} version {{version.name}}</span>
<div>
{{image.filename}}
<button *ngIf="checkImages(version)" class="button" mat-raised-button color="primary" (click)="createQemuTemplateFromVersion(version)">Create</button>
</div>
</div>
<div class="list-item-inside" *ngIf="version.images.hda_disk_image">
<span>
{{version.images.hda_disk_image}}
</span>
<div>
<span *ngIf="checkImage(image)"><mat-icon matTooltip="Ready to install" matTooltipClass="custom-tooltip">check</mat-icon></span>
<span *ngIf="!checkImage(image)"><mat-icon matTooltip="Missing" matTooltipClass="custom-tooltip">close</mat-icon></span>
<span *ngIf="checkImageFromVersion(version.images.hda_disk_image)"><mat-icon matTooltip="Ready to install" matTooltipClass="custom-tooltip">check</mat-icon></span>
<span *ngIf="!checkImageFromVersion(version.images.hda_disk_image)"><mat-icon matTooltip="Missing" matTooltipClass="custom-tooltip">close</mat-icon></span>
<input
type="file"
class="non-visible"
@ -157,12 +167,32 @@
ng2FileSelect
[uploader]="uploaderImage"/>
<button class="button" mat-raised-button (click)="file2.click()">Import</button>
<button class="button" mat-raised-button (click)="downloadImage(image)">Download</button>
<button *ngIf="checkImage(image)" class="button" mat-raised-button color="primary" (click)="createQemuTemplate(image)">Create</button>
<button class="button" mat-raised-button (click)="downloadImageFromVersion(version.images.hda_disk_image)">Download</button>
</div>
</div>
<div class="list-item-inside" *ngIf="version.images.hdb_disk_image">
<span>
{{version.images.hdb_disk_image}}
</span>
<div>
<span *ngIf="checkImageFromVersion(version.images.hdb_disk_image)"><mat-icon matTooltip="Ready to install" matTooltipClass="custom-tooltip">check</mat-icon></span>
<span *ngIf="!checkImageFromVersion(version.images.hdb_disk_image)"><mat-icon matTooltip="Missing" matTooltipClass="custom-tooltip">close</mat-icon></span>
<input
type="file"
class="non-visible"
#file2
(change)="importImage($event)"
ng2FileSelect
[uploader]="uploaderImage"/>
<button class="button" mat-raised-button (click)="file2.click()">Import</button>
<button class="button" mat-raised-button (click)="downloadImageFromVersion(version.images.hdb_disk_image)">Download</button>
</div>
</div>
</div>
</div>
</mat-list-item>
</mat-list>
</div>
</div>

View File

@ -42,6 +42,15 @@
display: flex;
justify-content: space-between;
width: 100%;
margin-bottom: 15px;
}
.list-item-inside {
display: flex;
justify-content: space-between;
width: 100%;
padding-left: 30px;
margin-bottom: 15px;
}
.button {

View File

@ -9,7 +9,7 @@ import { Server } from '../../../models/server';
import { Node } from '../../../cartography/models/node';
import { Project } from '../../../models/project';
import { ApplianceService } from '../../../services/appliances.service';
import { Appliance, Image } from '../../../models/appliance';
import { Appliance, Image, Version } from '../../../models/appliance';
import { animate, state, style, transition, trigger } from '@angular/animations';
import { FileUploader, FileItem, ParsedResponseHeaders } from 'ng2-file-upload';
import { ToasterService } from '../../../services/toaster.service';
@ -304,10 +304,33 @@ export class NewTemplateDialogComponent implements OnInit {
return false;
}
checkImageFromVersion(image: string): boolean {
if (this.applianceToInstall.qemu) {
if (this.qemuImages.filter(n => n.filename === image).length > 0) return true;
} else if (this.applianceToInstall.dynamips) {
if (this.iosImages.filter(n => n.filename === image).length > 0) return true;
} else if (this.applianceToInstall.iou) {
if (this.iouImages.filter(n => n.filename === image).length > 0) return true;
}
return false;
}
checkImages(version: Version): boolean {
if (this.checkImageFromVersion(version.images.hda_disk_image) && this.checkImageFromVersion(version.images.hdb_disk_image)) return true;
return false;
}
downloadImage(image: Image) {
window.open(image.download_url);
}
downloadImageFromVersion(image: string) {
this.applianceToInstall.images.forEach(n => {
if (n.filename === image) this.downloadImage(n);
});
}
createIouTemplate (image: Image) {
let iouTemplate: IouTemplate = new IouTemplate();
iouTemplate.name = this.applianceToInstall.name;
@ -385,7 +408,7 @@ export class NewTemplateDialogComponent implements OnInit {
});
}
createQemuTemplate(image: Image) {
createQemuTemplateFromVersion(version: Version) {
if (!this.selectedBinary) {
this.toasterService.error('Please select QEMU binary first');
return;
@ -406,7 +429,8 @@ export class NewTemplateDialogComponent implements OnInit {
qemuTemplate.qemu_path = this.selectedBinary.path;
qemuTemplate.compute_id = this.isGns3VmChosen ? 'vm' : 'local';
qemuTemplate.template_id = uuid();
qemuTemplate.hda_disk_image = image.filename;
qemuTemplate.hda_disk_image = version.images.hda_disk_image;
qemuTemplate.hdb_disk_image = version.images.hdb_disk_image;
qemuTemplate.template_type = 'qemu';
this.qemuService.addTemplate(this.server, qemuTemplate).subscribe((template) => {

View File

@ -49,6 +49,7 @@ export interface Iou {
export interface Images {
hda_disk_image: string;
hdb_disk_image: string;
}
export interface Version {