I resolved "Cannot add Qemu template manually bug

#1287"
This commit is contained in:
Sakshi Goel 2022-04-13 13:47:03 +05:30
parent 97d1bc7596
commit 5e65aff228
5 changed files with 39 additions and 21 deletions

View File

@ -29,16 +29,16 @@
</form>
</mat-step>
<mat-step label="QEMU binary and memory" [completed]="memoryForm.get('ramMemory').value && selectedBinary">
<mat-step label="Platform and memory" [completed]="memoryForm.get('ramMemory').value && selectedPlatform">
<form [formGroup]="memoryForm">
<mat-form-field class="form-field">
<mat-select
placeholder="Qemu binary"
[(ngModel)]="selectedBinary"
placeholder="Platform"
[(ngModel)]="selectedPlatform"
[ngModelOptions]="{ standalone: true }"
>
<mat-option *ngFor="let binary of qemuBinaries" [value]="binary">
{{ binary.path }}
<mat-option *ngFor="let platform of selectPlatform " [value]="platform">
{{ platform }}
</mat-option>
</mat-select> </mat-form-field
><br />

View File

@ -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 {

View File

@ -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() {

View File

@ -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'];
}

View File

@ -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<QemuBinary[]> {
@ -28,11 +28,11 @@ export class QemuService {
}
getImages(server: Server): Observable<any> {
return this.httpServer.get<QemuImage[]>(server, '/compute/qemu/images') as Observable<QemuImage[]>;
return this.httpServer.get<QemuImage[]>(server, '/images') as Observable<QemuImage[]>;
}
addImage(server: Server, qemuImg: QemuImg): Observable<QemuImg> {
return this.httpServer.post<QemuImg>(server, '/compute/qemu/img', qemuImg) as Observable<QemuImg>;
return this.httpServer.post<QemuImg>(server, '/images/upload', qemuImg) as Observable<QemuImg>;
}
addTemplate(server: Server, qemuTemplate: QemuTemplate): Observable<QemuTemplate> {