Skip to content

Commit

Permalink
Add "Add TPM" VM action
Browse files Browse the repository at this point in the history
  • Loading branch information
Shotaro-Kawaguchi authored and martinpitt committed Oct 29, 2024
1 parent 7000928 commit 2ad5d22
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/components/common/needsShutdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ export function needsShutdownWatchdog(vm) {
return vm.persistent && vm.state === "running" && vm.inactiveXML.watchdog.action !== vm.watchdog.action;
}

export function needsShutdownTpm(vm) {
return vm.persistent && vm.state === "running" && vm.inactiveXML.tpm !== vm.tpm;
}

export function needsShutdownSpice(vm) {
return vm.hasSpice !== vm.inactiveXML.hasSpice;
}
Expand Down Expand Up @@ -121,6 +125,10 @@ export function getDevicesRequiringShutdown(vm) {
if (needsShutdownSpice(vm))
devices.push(_("SPICE"));

// TPM
if (needsShutdownTpm(vm))
devices.push(_("TPM"));

return devices;
}

Expand Down
14 changes: 14 additions & 0 deletions src/components/vm/vmActions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
domainSendNMI,
domainShutdown,
domainStart,
domainAddTPM,
} from '../../libvirtApi/domain.js';
import store from "../../store.js";

Expand Down Expand Up @@ -181,6 +182,8 @@ const onSendNMI = (vm) => domainSendNMI({ name: vm.name, id: vm.id, connectionNa
);
});

const onAddTPM = (vm) => domainAddTPM({ connectionName: vm.connectionName, vmName: vm.name });

const VmActions = ({ vm, vms, onAddErrorNotification, isDetailsPage }) => {
const Dialogs = useDialogs();
const [operationInProgress, setOperationInProgress] = useState(false);
Expand Down Expand Up @@ -467,6 +470,17 @@ const VmActions = ({ vm, vms, onAddErrorNotification, isDetailsPage }) => {
if (domainCanRename(state) || isDetailsPage)
dropdownItems.push(<Divider key="separator-rename" />);

if (!vm.tpm) {
dropdownItems.push(
<DropdownItem key={`${id}-add-tpm`}
id={`${id}-add-tpm`}
onClick={() => onAddTPM(vm)}>
{_("Add TPM")}
</DropdownItem>
);
dropdownItems.push(<Divider key="separator-add-tpm" />);
}

if (state !== undefined && domainCanDelete(state, vm.id)) {
if (!vm.persistent) {
dropdownItems.push(
Expand Down
24 changes: 22 additions & 2 deletions src/libvirt-xml-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ export function parseDomainDumpxml(connectionName, domXml, objPath) {
const watchdog = parseDumpxmlForWatchdog(devicesElem);
const vsock = parseDumpxmlForVsock(devicesElem);
const hasSpice = parseDumpxmlForSpice(devicesElem);
const hasTPM = parseDumpxmlForTPM(devicesElem);
const hasTPM = !!parseDumpxmlForTPM(devicesElem);
const tpm = parseDumpxmlForTPM(devicesElem);

const hasInstallPhase = parseDumpxmlMachinesMetadataElement(metadataElem, 'has_install_phase') === 'true';
const installSourceType = parseDumpxmlMachinesMetadataElement(metadataElem, 'install_source_type');
Expand Down Expand Up @@ -321,6 +322,7 @@ export function parseDomainDumpxml(connectionName, domXml, objPath) {
vsock,
metadata,
hasSpice,
tpm,
hasTPM,
};
}
Expand Down Expand Up @@ -566,7 +568,25 @@ function parseDumpxmlForSpice(devicesElem) {
}

function parseDumpxmlForTPM(devicesElem) {
return devicesElem.getElementsByTagName('tpm').length > 0;
const tpmElems = devicesElem.getElementsByTagName('tpm');
if (tpmElems.length > 0) {
const tpmElem = tpmElems[0];
const model = tpmElem.getAttribute('model');
const backendElem = tpmElem.getElementsByTagName('backend')[0];
const type = backendElem.getAttribute('type');
const version = backendElem.getAttribute('version');
const devicePathElem = backendElem.getElementsByTagName('device')[0];
const devicePath = devicePathElem ? devicePathElem.getAttribute('path') : null;

const tpm = {
model,
type,
version,
devicePath,
};
return tpm;
}
return null;
}

export function parseDumpxmlForFilesystems(devicesElem) {
Expand Down

0 comments on commit 2ad5d22

Please sign in to comment.