mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-06 22:26: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 { 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