Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "view, edit, and add TPM devices" to overview #1796

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 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) {
martinpitt marked this conversation as resolved.
Show resolved Hide resolved
return vm.persistent && vm.state === "running" && vm.inactiveXML.tpm !== vm.tpm;
}

export function needsShutdownSpice(vm) {
return vm.hasSpice !== vm.inactiveXML.hasSpice;
}
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 @@ -57,6 +57,7 @@ import {
domainSendNMI,
domainShutdown,
domainStart,
domainAddTPM,
} from '../../libvirtApi/domain.js';
import store from "../../store.js";

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

const onAddTPM = (vm) => domainAddTPM({ connectionName: vm.connectionName, vmName: vm.name });
martinpitt marked this conversation as resolved.
Show resolved Hide resolved

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

if (!Object.keys(vm.tpm).length) {
martinpitt marked this conversation as resolved.
Show resolved Hide resolved
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
23 changes: 21 additions & 2 deletions src/libvirt-xml-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ export function parseDomainDumpxml(connectionName, domXml, objPath) {
const watchdog = parseDumpxmlForWatchdog(devicesElem);
const vsock = parseDumpxmlForVsock(devicesElem);
const hasSpice = parseDumpxmlForSpice(devicesElem);
const hasTPM = parseDumpxmlForTPM(devicesElem);
const { tpm, hasTPM } = parseDumpxmlForTPM(devicesElem);
martinpitt marked this conversation as resolved.
Show resolved Hide resolved

const hasInstallPhase = parseDumpxmlMachinesMetadataElement(metadataElem, 'has_install_phase') === 'true';
const installSourceType = parseDumpxmlMachinesMetadataElement(metadataElem, 'install_source_type');
Expand Down Expand Up @@ -315,6 +315,7 @@ export function parseDomainDumpxml(connectionName, domXml, objPath) {
vsock,
metadata,
hasSpice,
tpm,
hasTPM,
};
}
Expand Down Expand Up @@ -560,7 +561,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, hasTPM: true };
}
return { tpm: {}, hasTPM: false };
martinpitt marked this conversation as resolved.
Show resolved Hide resolved
}

export function parseDumpxmlForFilesystems(devicesElem) {
Expand Down