refactor: rewrite render logic

Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
This commit is contained in:
Yi-Ya Chen 2025-02-07 16:54:41 +08:00
parent 84bacfaff5
commit 68ba934b5a
No known key found for this signature in database
GPG Key ID: 9A2E6FBD33F68EDE
4 changed files with 55 additions and 43 deletions

View File

@ -465,6 +465,15 @@ export default {
:mode="mode"
/>
<Checkbox
v-if="tpmEnabled"
v-model:value="persistentStateEnabled"
class="check"
type="checkbox"
:label="t('harvester.virtualMachine.advancedOptions.persistentState')"
:mode="mode"
/>
<Checkbox
v-model:value="efiEnabled"
class="check"
@ -481,16 +490,6 @@ export default {
:label="t('harvester.virtualMachine.secureBoot')"
:mode="mode"
/>
<Checkbox
v-if="tpmEnabled || efiEnabled"
class="check"
type="checkbox"
:label="t('harvester.virtualMachine.advancedOptions.persistentState')"
:mode="mode"
:value="true"
:disabled="true"
/>
</Tab>
</Tabbed>
</CruResource>

View File

@ -873,6 +873,15 @@ export default {
:mode="mode"
/>
<Checkbox
v-if="tpmEnabled"
v-model:value="persistentStateEnabled"
class="check"
type="checkbox"
:label="t('harvester.virtualMachine.advancedOptions.persistentState')"
:mode="mode"
/>
<Checkbox
v-model:value="efiEnabled"
class="check"
@ -890,16 +899,6 @@ export default {
:mode="mode"
/>
<Checkbox
v-if="tpmEnabled || efiEnabled"
class="check"
type="checkbox"
:label="t('harvester.virtualMachine.advancedOptions.persistentState')"
:mode="mode"
:value="true"
:disabled="true"
/>
<Banner
v-if="showCpuPinningBanner"
color="warning"

View File

@ -137,7 +137,11 @@ export default {
},
isTpmEnabled(spec) {
return !!spec?.template?.spec?.domain?.devices?.tpm ;
return !!spec?.template?.spec?.domain?.devices?.tpm;
},
isPersistentStateEnabled(spec) {
return !!spec?.template?.spec?.domain?.devices?.tpm?.persistent;
},
isSecureBoot(spec) {

View File

@ -164,6 +164,7 @@ export default {
accessCredentials: [],
efiEnabled: false,
tpmEnabled: false,
persistentStateEnabled: false,
secureBoot: false,
userDataTemplateId: '',
saveUserDataAsClearText: false,
@ -367,6 +368,7 @@ export default {
const installAgent = this.hasInstallAgent(userData, osType, true);
const efiEnabled = this.isEfiEnabled(spec);
const tpmEnabled = this.isTpmEnabled(spec);
const persistentStateEnabled = this.isPersistentStateEnabled(spec);
const secureBoot = this.isSecureBoot(spec);
const cpuPinning = this.isCpuPinning(spec);
@ -399,6 +401,7 @@ export default {
this['installUSBTablet'] = installUSBTablet;
this['efiEnabled'] = efiEnabled;
this['tpmEnabled'] = tpmEnabled;
this['persistentStateEnabled'] = persistentStateEnabled;
this['secureBoot'] = secureBoot;
this['cpuPinning'] = cpuPinning;
@ -1384,30 +1387,25 @@ export default {
},
setBootMethod(boot = { efi: false, secureBoot: false }) {
if (!boot.efi) {
if (boot.efi && boot.secureBoot) {
set(this.spec.template.spec.domain, 'features.smm.enabled', true);
set(this.spec.template.spec.domain, 'firmware.bootloader.efi.secureBoot', true);
} else if (boot.efi && !boot.secureBoot) {
// set(this.spec.template.spec.domain, 'features.smm.enabled', false);
try {
delete this.spec.template.spec.domain.features.smm['enabled'];
const noKeys = Object.keys(this.spec.template.spec.domain.features.smm).length === 0;
if (noKeys) {
delete this.spec.template.spec.domain.features['smm'];
}
} catch (e) {}
set(this.spec.template.spec.domain, 'firmware.bootloader.efi.secureBoot', false);
} else {
delete this.spec.template.spec.domain['firmware'];
delete this.spec.template.spec.domain.features['smm'];
return;
}
set(this.spec.template.spec.domain, 'firmware.bootloader.efi.persistent', true);
set(this.spec.template.spec.domain, 'firmware.bootloader.efi.secureBoot', !!boot.secureBoot);
if (boot.secureBoot) {
set(this.spec.template.spec.domain, 'features.smm.enabled', true);
return;
}
try {
const smm = this.spec.template.spec.domain.features.smm;
delete smm['enabled'];
if (Object.keys(smm).length === 0) {
delete this.spec.template.spec.domain.features['smm'];
}
} catch (e) {}
},
setCpuPinning(value) {
@ -1420,12 +1418,20 @@ export default {
setTPM(tpmEnabled) {
if (tpmEnabled) {
set(this.spec.template.spec.domain.devices, 'tpm.persistent', true);
set(this.spec.template.spec.domain.devices, 'tpm', {});
} else {
delete this.spec.template.spec.domain.devices['tpm'];
}
},
setPersistentStateEnabled(persistentStateEnabled) {
if (persistentStateEnabled) {
set(this.spec.template.spec.domain.devices, 'tpm', { persistent: true });
} else {
set(this.spec.template.spec.domain.devices, 'tpm', {});
}
},
deleteSSHFromUserData(ssh = []) {
const sshAuthorizedKeys = this.getSSHFromUserData(this.userScript);
@ -1549,6 +1555,10 @@ export default {
this.setTPM(val);
},
persistentStateEnabled(val) {
this.setPersistentStateEnabled(val);
},
installAgent: {
/**
* rules