fix(vm): block VM creation with invalid CloudInit YAML content

This commit is contained in:
copilot-swe-agent[bot]
2026-08-05 15:56:22 +08:00
committed by Andy Lee
parent fbd4a1108f
commit 1df5af32b8
3 changed files with 54 additions and 0 deletions
@@ -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;