mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-06 06:06:05 +08:00
fix(vm): block VM creation with invalid CloudInit YAML content
This commit is contained in:
committed by
Andy Lee
parent
fbd4a1108f
commit
1df5af32b8
@@ -1,4 +1,5 @@
|
||||
<script>
|
||||
import jsyaml from 'js-yaml';
|
||||
import { mapGetters } from 'vuex';
|
||||
import Tabbed from '@shell/components/Tabbed';
|
||||
import Tab from '@shell/components/Tabbed/Tab';
|
||||
@@ -177,8 +178,17 @@ export default {
|
||||
},
|
||||
|
||||
async saveVMT(buttonCb) {
|
||||
this.errors = [];
|
||||
this.parseVM();
|
||||
|
||||
this.validateCloudInit();
|
||||
|
||||
if (this.errors.length) {
|
||||
buttonCb(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const templates = await this.$store.dispatch('harvester/findAll', { type: HCI.VM_TEMPLATE });
|
||||
const template = templates.find( (O) => O.metadata.name === this.templateValue.metadata.name);
|
||||
|
||||
@@ -237,6 +247,24 @@ export default {
|
||||
this.$refs.yamlEditor?.refresh();
|
||||
}
|
||||
},
|
||||
|
||||
validateCloudInit() {
|
||||
if (this.userScript) {
|
||||
try {
|
||||
jsyaml.load(this.userScript);
|
||||
} catch (e) {
|
||||
this.errors.push(this.t('harvester.virtualMachine.cloudConfig.user.invalidYaml'));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.networkScript) {
|
||||
try {
|
||||
jsyaml.load(this.networkScript);
|
||||
} catch (e) {
|
||||
this.errors.push(this.t('harvester.virtualMachine.cloudConfig.network.invalidYaml'));
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script>
|
||||
import jsyaml from 'js-yaml';
|
||||
import { isEqual } from 'lodash';
|
||||
import { mapGetters } from 'vuex';
|
||||
import Tabbed from '@shell/components/Tabbed';
|
||||
@@ -379,6 +380,7 @@ export default {
|
||||
|
||||
this.validateCPUMemory();
|
||||
this.validateWindowsSysprep();
|
||||
this.validateCloudInit();
|
||||
|
||||
// block create VM flow if has validation errors
|
||||
if (this.errors.length) {
|
||||
@@ -424,6 +426,28 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
validateCloudInit() {
|
||||
if (this.isWindows) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.userScript) {
|
||||
try {
|
||||
jsyaml.load(this.userScript);
|
||||
} catch (e) {
|
||||
this.errors.push(this.t('harvester.virtualMachine.cloudConfig.user.invalidYaml'));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.networkScript) {
|
||||
try {
|
||||
jsyaml.load(this.networkScript);
|
||||
} catch (e) {
|
||||
this.errors.push(this.t('harvester.virtualMachine.cloudConfig.network.invalidYaml'));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async saveSingle(buttonCb) {
|
||||
this.parseVM();
|
||||
this.value.spec.template.spec.hostname = this.hostname ? this.hostname : this.value.metadata.name;
|
||||
|
||||
Reference in New Issue
Block a user