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

View File

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

View File

@ -137,7 +137,11 @@ export default {
}, },
isTpmEnabled(spec) { 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) { isSecureBoot(spec) {

View File

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