mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2025-12-13 13:11:43 +00:00
fix: allow to edit as yaml if has empty CPU or memory (#547)
* fix: allow edit as yaml in create VM page if empty CPU or memory Signed-off-by: Andy Lee <andy.lee@suse.com> * refactor: remove getCPUMemoryValidation Signed-off-by: Andy Lee <andy.lee@suse.com> --------- Signed-off-by: Andy Lee <andy.lee@suse.com>
This commit is contained in:
parent
7af8a82838
commit
5c2a23924d
@ -338,6 +338,15 @@ export default {
|
|||||||
saveVM(buttonCb) {
|
saveVM(buttonCb) {
|
||||||
clear(this.errors);
|
clear(this.errors);
|
||||||
|
|
||||||
|
this.validateCPUMemory();
|
||||||
|
|
||||||
|
// block create VM flow if has validation errors
|
||||||
|
if (this.errors.length) {
|
||||||
|
buttonCb(false);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.isSingle) {
|
if (this.isSingle) {
|
||||||
this.saveSingle(buttonCb);
|
this.saveSingle(buttonCb);
|
||||||
} else {
|
} else {
|
||||||
@ -345,6 +354,18 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
validateCPUMemory() {
|
||||||
|
const { cpu, memory } = this;
|
||||||
|
|
||||||
|
if ((!cpu)) {
|
||||||
|
this.errors.push(this.t('validation.required', { key: this.t('harvester.virtualMachine.input.cpu') }, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((!memory)) {
|
||||||
|
this.errors.push(this.t('validation.required', { key: this.t('harvester.virtualMachine.input.memory') }, true));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async saveSingle(buttonCb) {
|
async saveSingle(buttonCb) {
|
||||||
this.parseVM();
|
this.parseVM();
|
||||||
this.value.spec.template.spec.hostname = this.hostname ? this.hostname : this.value.metadata.name;
|
this.value.spec.template.spec.hostname = this.hostname ? this.hostname : this.value.metadata.name;
|
||||||
@ -466,9 +487,7 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cpuMemoryErrors = this.getCPUMemoryValidation();
|
const errors = this.getAccessCredentialsValidation();
|
||||||
const accessCredentialsErrors = this.getAccessCredentialsValidation();
|
|
||||||
const errors = [...cpuMemoryErrors, ...accessCredentialsErrors];
|
|
||||||
|
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return Promise.reject(errors);
|
return Promise.reject(errors);
|
||||||
|
|||||||
@ -1369,21 +1369,6 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getCPUMemoryValidation() {
|
|
||||||
const errors = [];
|
|
||||||
const { cpu, memory } = this;
|
|
||||||
|
|
||||||
if ((!cpu)) {
|
|
||||||
errors.push(this.t('validation.required', { key: this.t('harvester.virtualMachine.input.cpu') }, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((!memory)) {
|
|
||||||
errors.push(this.t('validation.required', { key: this.t('harvester.virtualMachine.input.memory') }, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
return errors;
|
|
||||||
},
|
|
||||||
|
|
||||||
getAccessCredentialsValidation() {
|
getAccessCredentialsValidation() {
|
||||||
const errors = [];
|
const errors = [];
|
||||||
|
|
||||||
|
|||||||
@ -3,15 +3,15 @@ import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations
|
|||||||
export function getVmCPUMemoryValues(vm) {
|
export function getVmCPUMemoryValues(vm) {
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
return {
|
return {
|
||||||
cpu: 0,
|
cpu: null,
|
||||||
memory: null,
|
memory: null,
|
||||||
isHotplugEnabled: false
|
isHotplugEnabled: false
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const isHotplugEnabled = isCPUMemoryHotPlugEnabled(vm);
|
const isHotplugEnabled = isCPUMemoryHotPlugEnabled(vm);
|
||||||
const { sockets = 1, threads = 1, cores = 1 } = vm.spec.template.spec.domain.cpu || {};
|
const { sockets = 1, threads = 1, cores = null } = vm.spec.template.spec.domain.cpu || {};
|
||||||
const cpu = sockets * threads * cores;
|
const cpu = cores === null ? null : sockets * threads * cores;
|
||||||
|
|
||||||
if (isHotplugEnabled) {
|
if (isHotplugEnabled) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user