From 5e65aff2285b748ab37cfc40fed7b209ac268b3a Mon Sep 17 00:00:00 2001 From: Sakshi Goel Date: Wed, 13 Apr 2022 13:47:03 +0530 Subject: [PATCH] I resolved "Cannot add Qemu template manually bug #1287" --- .../add-qemu-vm-template.component.html | 10 +++--- .../add-qemu-vm-template.component.ts | 31 +++++++++++++------ .../new-template-dialog.component.ts | 9 ++++-- .../services/qemu-configuration.service.ts | 4 +++ src/app/services/qemu.service.ts | 6 ++-- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/app/components/preferences/qemu/add-qemu-vm-template/add-qemu-vm-template.component.html b/src/app/components/preferences/qemu/add-qemu-vm-template/add-qemu-vm-template.component.html index 0aa2d7fe..e6df8fb1 100644 --- a/src/app/components/preferences/qemu/add-qemu-vm-template/add-qemu-vm-template.component.html +++ b/src/app/components/preferences/qemu/add-qemu-vm-template/add-qemu-vm-template.component.html @@ -29,16 +29,16 @@ - +
- - {{ binary.path }} + + {{ platform }}
diff --git a/src/app/components/preferences/qemu/add-qemu-vm-template/add-qemu-vm-template.component.ts b/src/app/components/preferences/qemu/add-qemu-vm-template/add-qemu-vm-template.component.ts index 7787a0b4..661866ba 100644 --- a/src/app/components/preferences/qemu/add-qemu-vm-template/add-qemu-vm-template.component.ts +++ b/src/app/components/preferences/qemu/add-qemu-vm-template/add-qemu-vm-template.component.ts @@ -1,7 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; -import { FileItem, FileUploader, ParsedResponseHeaders } from 'ng2-file-upload'; +import { FileItem, FileUploader, FileUploaderOptions, ParsedResponseHeaders } from 'ng2-file-upload'; import { v4 as uuid } from 'uuid'; import { Compute } from '../../../../models/compute'; import { QemuBinary } from '../../../../models/qemu/qemu-binary'; @@ -23,6 +23,8 @@ import { ToasterService } from '../../../../services/toaster.service'; export class AddQemuVmTemplateComponent implements OnInit { server: Server; qemuBinaries: QemuBinary[] = []; + selectPlatform: string[] = []; + selectedPlatform: string; selectedBinary: QemuBinary; ramMemory: number; consoleTypes: string[] = []; @@ -68,6 +70,7 @@ export class AddQemuVmTemplateComponent implements OnInit { ngOnInit() { this.uploader = new FileUploader({}); + this.uploader.onAfterAddingFile = (file) => { file.withCredentials = false; }; @@ -85,6 +88,7 @@ export class AddQemuVmTemplateComponent implements OnInit { }); this.toasterService.success('Image uploaded'); }; + this.uploader.onProgressItem = (progress: any) => { this.uploadProgress = progress['progress']; }; @@ -97,16 +101,18 @@ export class AddQemuVmTemplateComponent implements OnInit { this.qemuTemplate = qemuTemplate; }); - this.qemuService.getBinaries(server).subscribe((qemuBinaries: QemuBinary[]) => { + + this.qemuService.getBinaries(this.server).subscribe((qemuBinaries: QemuBinary[]) => { this.qemuBinaries = qemuBinaries; if (this.qemuBinaries[0]) this.selectedBinary = this.qemuBinaries[0]; }); - if (!this.server.authToken) { - this.qemuService.getImages(server).subscribe((qemuImages: QemuImage[]) => { - this.qemuImages = qemuImages; - }); - } + this.qemuService.getImages(this.server).subscribe((qemuImages: QemuImage[]) => { + this.qemuImages = qemuImages; + }); + + this.selectPlatform = this.configurationService.getPlatform(); + this.selectedPlatform = this.selectPlatform[0]; this.consoleTypes = this.configurationService.getConsoleTypes(); }); @@ -124,17 +130,19 @@ export class AddQemuVmTemplateComponent implements OnInit { } uploadImageFile(event) { + this.uploadedFile = true; let name = event.target.files[0].name; this.diskForm.controls['fileName'].setValue(name); const url = this.qemuService.getImagePath(this.server, name); this.uploader.queue.forEach((elem) => (elem.url = url)); - + const itemToUpload = this.uploader.queue[0]; - if ((itemToUpload as any).options) (itemToUpload as any).options.disableMultipart = true; - + + if ((itemToUpload as any).options) (itemToUpload as any).options.disableMultipart = true; ((itemToUpload as any).options.headers =[{name:'Authorization',value:'Bearer ' + this.server.authToken}]) this.uploader.uploadItem(itemToUpload); + } goBack() { @@ -142,9 +150,12 @@ export class AddQemuVmTemplateComponent implements OnInit { } addTemplate() { + debugger if (!this.nameForm.invalid && !this.memoryForm.invalid && (this.selectedImage || this.chosenImage)) { this.qemuTemplate.ram = +this.memoryForm.get('ramMemory').value; this.qemuTemplate.qemu_path = this.selectedBinary.path; + this.qemuTemplate.platform = this.selectedPlatform; + if (this.newImageSelected) { this.qemuTemplate.hda_disk_image = this.diskForm.get('fileName').value; } else { diff --git a/src/app/components/project-map/new-template-dialog/new-template-dialog.component.ts b/src/app/components/project-map/new-template-dialog/new-template-dialog.component.ts index 8cea2cf5..c80ea682 100644 --- a/src/app/components/project-map/new-template-dialog/new-template-dialog.component.ts +++ b/src/app/components/project-map/new-template-dialog/new-template-dialog.component.ts @@ -106,6 +106,11 @@ export class NewTemplateDialogComponent implements OnInit { if (compute.capabilities.platform === 'linux') this.isLinuxPlatform = true; }); }); + + this.qemuService.getBinaries(this.server).subscribe((binaries) => { + this.qemuBinaries = binaries; + }); + this.qemuService.getImages(this.server).subscribe((qemuImages) => { this.qemuImages = qemuImages; }); @@ -178,9 +183,7 @@ export class NewTemplateDialogComponent implements OnInit { this.uploaderImage.clearQueue(); }; } - this.qemuService.getBinaries(this.server).subscribe((binaries) => { - this.qemuBinaries = binaries; - }); + } updateAppliances() { diff --git a/src/app/services/qemu-configuration.service.ts b/src/app/services/qemu-configuration.service.ts index c4e8c675..94180db6 100644 --- a/src/app/services/qemu-configuration.service.ts +++ b/src/app/services/qemu-configuration.service.ts @@ -2,6 +2,10 @@ import { Injectable } from '@angular/core'; @Injectable() export class QemuConfigurationService { + getPlatform() { + return ['x86_64', 'aarch64', 'alpha', 'arm', 'cris', 'i386', 'lm32', 'm68k', 'microblaze', 'microblazeel', 'mips', 'mips64', 'mips64el', 'mipsel', 'moxie', 'or32', 'ppc', 'ppc64', 'ppcemb', 's390x', 'sh4', 'sh4eb', 'sparc', 'sparc64', 'tricore', 'unicore32', 'xtensa', 'xtensaeb']; + } + getConsoleTypes() { return ['telnet', 'vnc', 'spice', 'spice+agent', 'none']; } diff --git a/src/app/services/qemu.service.ts b/src/app/services/qemu.service.ts index 064efb9a..18e743df 100644 --- a/src/app/services/qemu.service.ts +++ b/src/app/services/qemu.service.ts @@ -20,7 +20,7 @@ export class QemuService { } getImagePath(server: Server, filename: string): string { - return `${server.protocol}//${server.host}:${server.port}/v3/compute/qemu/images/${filename}`; + return `${server.protocol}//${server.host}:${server.port}/v3/images/upload/${filename}`; } getBinaries(server: Server): Observable { @@ -28,11 +28,11 @@ export class QemuService { } getImages(server: Server): Observable { - return this.httpServer.get(server, '/compute/qemu/images') as Observable; + return this.httpServer.get(server, '/images') as Observable; } addImage(server: Server, qemuImg: QemuImg): Observable { - return this.httpServer.post(server, '/compute/qemu/img', qemuImg) as Observable; + return this.httpServer.post(server, '/images/upload', qemuImg) as Observable; } addTemplate(server: Server, qemuTemplate: QemuTemplate): Observable {