fix: preserve YAML device parameters on config editing (#487)

Signed-off-by: Caio Torres <caio.torres@suse.com>
This commit is contained in:
Caio Torres 2025-09-01 03:20:12 -03:00 committed by GitHub
parent 775330d829
commit 22c99211f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -767,6 +767,9 @@ export default {
}
}
const specDisks = this.spec?.template?.spec?.domain?.devices?.disks;
const mergedDisks = this.mergeDeviceList(specDisks, disks);
let spec = {
...this.spec,
runStrategy: this.runStrategy,
@ -789,7 +792,7 @@ export default {
...this.spec.template?.spec?.domain,
devices: {
...this.spec.template?.spec?.domain?.devices,
disks,
disks: mergedDisks,
},
},
volumes,
@ -888,13 +891,16 @@ export default {
interfaces.push(_interface);
});
const specInterfaces = this.spec?.template?.spec?.domain?.devices?.interfaces;
const mergedInterfaces = this.mergeDeviceList(specInterfaces, interfaces);
const spec = {
...this.spec.template.spec,
domain: {
...this.spec.template.spec.domain,
devices: {
...this.spec.template.spec.domain.devices,
interfaces,
interfaces: mergedInterfaces,
},
},
networks
@ -1543,6 +1549,23 @@ export default {
this.refreshYamlEditor();
},
mergeDeviceList(specDeviceList, deviceList) {
if (!specDeviceList || specDeviceList.length === 0) {
return deviceList;
}
const specDeviceMap = new Map(specDeviceList.map((device) => [device.name, device]));
return deviceList.map((device) => {
const specDevice = specDeviceMap.get(device.name);
if (specDevice) {
return { ...specDevice, ...device };
}
return device;
});
},
refreshYamlEditor() {
this.$nextTick(() => {
this.$refs.yamlEditor?.updateValue();