mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-08-16 12:49:14 +00:00
fix(vm): block VM creation with invalid CloudInit YAML content
This commit is contained in:
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;
|
||||
|
||||
@ -830,10 +830,12 @@ harvester:
|
||||
label: User Data Template
|
||||
title: "User Data:"
|
||||
tip: "You can specify user data to configure an instance or run a configuration script during launch. If you launch more than one instance at a time, the user data is available to all the instances in that reservation. <a href='https://cloudinit.readthedocs.io/en/latest/topics/examples.html' target='_blank'>Learn more</a>"
|
||||
invalidYaml: 'Invalid User Data YAML syntax'
|
||||
network:
|
||||
label: Network Data Template
|
||||
title: "Network Data:"
|
||||
tip: "The network-data configuration allows you to customize the instance's networking interfaces by assigning subnet configuration, virtual device creation (bonds, bridges, VLANs) routes and DNS configuration. <a href='https://cloudinit.readthedocs.io/en/latest/reference/network-config-format-v1.html' target='_blank'>Learn more</a>"
|
||||
invalidYaml: 'Invalid Network Data YAML syntax'
|
||||
sysprep:
|
||||
title: Windows Sysprep Configuration
|
||||
description: "Configure Windows automated installation using autounattend.xml. The configuration will be stored in a Kubernetes Secret and mounted as a CD-ROM during installation. <a href='https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/automate-windows-setup' target='_blank'>Learn more</a>"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user