Skip to content

Commit

Permalink
Add a plan details item to edit boot disk
Browse files Browse the repository at this point in the history
Signed-off-by: yaacov <[email protected]>
  • Loading branch information
yaacov committed Jun 7, 2024
1 parent aec1776 commit b484d2d
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
"Assessment": "Assessment",
"Authentication type": "Authentication type",
"Bandwidth": "Bandwidth",
"Boot from the fifth disk": "Boot from the fifth disk",
"Boot from the first disk": "Boot from the first disk",
"Boot from the fourth disk": "Boot from the fourth disk",
"Boot from the second disk": "Boot from the second disk",
"Boot from the third disk": "Boot from the third disk",
"CA certificate": "CA certificate",
"CA certificate - disabled when 'Skip certificate validation' is selected": "CA certificate - disabled when 'Skip certificate validation' is selected",
"CA certificate - leave empty to use system CA certificates": "CA certificate - leave empty to use system CA certificates",
Expand Down Expand Up @@ -112,6 +117,7 @@
"Description": "Description",
"Details": "Details",
"Determines the frequency with which the system checks the status of snapshot creation or removal during oVirt warm migration. The default value is 10 seconds.": "Determines the frequency with which the system checks the status of snapshot creation or removal during oVirt warm migration. The default value is 10 seconds.",
"Disk {{diskNumber}}": "Disk {{diskNumber}}",
"Disk counter": "Disk counter",
"Disk transfer": "Disk transfer",
"Do not try to preserve the static IPs of VMs with Windows guest operating system from vSphere.": "Do not try to preserve the static IPs of VMs with Windows guest operating system from vSphere.",
Expand All @@ -138,6 +144,7 @@
"Edit Provider Credentials": "Edit Provider Credentials",
"Edit provider credentials.\n Use this link to edit the providers credentials instead of editing the secret directly.": "Edit provider credentials.\n Use this link to edit the providers credentials instead of editing the secret directly.",
"Edit provider web UI link": "Edit provider web UI link",
"Edit root disk": "Edit root disk",
"Edit Snapshot polling interval (seconds)": "Edit Snapshot polling interval (seconds)",
"Edit StorageMap": "Edit StorageMap",
"Edit target namespace": "Edit target namespace",
Expand Down Expand Up @@ -175,6 +182,7 @@
"Filter by template": "Filter by template",
"Filter by tenant": "Filter by tenant",
"Filter provider": "Filter provider",
"First disk": "First disk",
"Flavor": "Flavor",
"Folder": "Folder",
"GPUs/Host Devices": "GPUs/Host Devices",
Expand Down Expand Up @@ -375,10 +383,12 @@
"Restore default columns": "Restore default columns",
"Return to the providers list page": "Return to the providers list page",
"Reveal values": "Reveal values",
"Root disk": "Root disk",
"Run the migration plan.": "Run the migration plan.",
"Running": "Running",
"Running virtual machines": "Running virtual machines",
"Save": "Save",
"Second disk": "Second disk",
"Secret": "Secret",
"Secret failed to load, check if the secret exist.": "Secret failed to load, check if the secret exist.",
"Secret is loading, please wait.": "Secret is loading, please wait.",
Expand Down Expand Up @@ -412,6 +422,7 @@
"Source Only": "Source Only",
"Source provider": "Source provider",
"Specifies the duration for retaining 'must gather' reports before they are automatically deleted. The default value is -1, which implies automatic cleanup is disabled.": "Specifies the duration for retaining 'must gather' reports before they are automatically deleted. The default value is -1, which implies automatic cleanup is disabled.",
"Specify the root disk for Openshift Virtualization configuration and guest agent setup.": "Specify the root disk for Openshift Virtualization configuration and guest agent setup.",
"Specify the type of source provider. Allowed values are ova, ovirt, vsphere,\n openshift, and openstack. This label is needed to verify the credentials are correct when the remote system is accessible and, for RHV, to retrieve the Manager CA certificate when\n a third-party certificate is specified.": "Specify the type of source provider. Allowed values are ova, ovirt, vsphere,\n openshift, and openstack. This label is needed to verify the credentials are correct when the remote system is accessible and, for RHV, to retrieve the Manager CA certificate when\n a third-party certificate is specified.",
"Staging": "Staging",
"Start": "Start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DescriptionList } from '@patternfly/react-core';
import {
PreserveClusterCpuModelDetailsItem,
PreserveStaticIPsDetailsItem,
RootDiskDetailsItem,
TargetNamespaceDetailsItem,
TransferNetworkDetailsItem,
WarmDetailsItem,
Expand Down Expand Up @@ -70,6 +71,10 @@ export const SettingsSectionInternal: React.FC<SettingsSectionProps> = ({ obj, p
{['vsphere'].includes(sourceProvider?.spec?.type) && (
<PreserveStaticIPsDetailsItem resource={obj} canPatch={permissions.canPatch} />
)}

{['vsphere'].includes(sourceProvider?.spec?.type) && (
<RootDiskDetailsItem resource={obj} canPatch={permissions.canPatch} />
)}
</DescriptionList>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import { useModal } from 'src/modules/Providers/modals';
import { DetailsItem } from 'src/modules/Providers/utils';
import { useForkliftTranslation } from 'src/utils/i18n';

import { Label } from '@patternfly/react-core';

import { PlanDetailsItemProps } from '../../DetailsSection';
import { EditRootDisk } from '../modals/EditRootDisk/EditRootDisk';

export const RootDiskDetailsItem: React.FC<PlanDetailsItemProps> = ({
resource,
canPatch,
helpContent,
}) => {
const { t } = useForkliftTranslation();
const { showModal } = useModal();

const defaultHelpContent = t(
`Specify the root disk for Openshift Virtualization configuration and guest agent setup.`,
);

const rootDisk = resource?.spec?.vms?.[0].rootDisk || '1';

const labelMap = {
'1': (
<Label isCompact color={'blue'}>
{t('First disk')}
</Label>
),
'2': (
<Label isCompact color={'orange'}>
{t('Second disk')}
</Label>
),
};

const getDiskLabel = (diskNumber: string) => {
if (diskNumber in labelMap) {
return labelMap[diskNumber];
}

return (
<Label isCompact color={'red'}>
{t('Disk {{diskNumber}}', { diskNumber })}
</Label>
);
};

return (
<DetailsItem
title={t('Root disk')}
content={getDiskLabel(rootDisk)}
helpContent={helpContent ?? defaultHelpContent}
crumbs={['spec', 'vms', 'rootDisk']}
onEdit={canPatch && (() => showModal(<EditRootDisk resource={resource} />))}
/>
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './PreserveClusterCpuModelDetailsItem';
export * from './PreserveStaticIPsDetailsItem';
export * from './RootDiskDetailsItem';
export * from './TargetNamespaceDetailsItem';
export * from './TransferNetworkDetailsItem';
export * from './WarmDetailsItem';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import React from 'react';
import { useToggle } from 'src/modules/Providers/hooks';
import {
AlertMessageForModals,
EditModal,
EditModalProps,
ModalInputComponentType,
OnConfirmHookType,
} from 'src/modules/Providers/modals';
import { useForkliftTranslation } from 'src/utils/i18n';

import { Modify, PlanModel, V1beta1Plan } from '@kubev2v/types';
import { K8sModel, k8sPatch } from '@openshift-console/dynamic-plugin-sdk';
import { Dropdown, DropdownItem, DropdownToggle } from '@patternfly/react-core';

const onConfirm: OnConfirmHookType = async ({ resource, model, newValue }) => {
const plan = resource as V1beta1Plan;

const resourceValue = plan?.spec?.vms;
const op = resourceValue ? 'replace' : 'add';
const newVMs = resourceValue.map((vm) => ({
...vm,
rootDisk: newValue || undefined,
}));

const obj = await k8sPatch({
model: model,
resource: resource,
data: [
{
op,
path: '/spec/vms',
value: newVMs || undefined,
},
],
});

return obj;
};

interface DropdownRendererProps {
value: string | number;
onChange: (V1beta1PlanSpecTransferNetwork) => void;
}

const RootDiskInputFactory: () => ModalInputComponentType = () => {
const DropdownRenderer: React.FC<DropdownRendererProps> = ({ value, onChange }) => {
const { t } = useForkliftTranslation();
const [isOpen, onToggle] = useToggle(false);

const diskOptions = [
{ key: '', description: t('Boot from the first disk'), content: 'First disk' },
{ key: '2', description: t('Boot from the second disk'), content: 'Second disk' },
{ key: '3', description: t('Boot from the third disk'), content: 'Third disk' },
{ key: '4', description: t('Boot from the fourth disk'), content: 'Fourth disk' },
{ key: '5', description: t('Boot from the fifth disk'), content: 'Fifth disk' },
];

const dropdownItems = diskOptions.map((option) => (
<DropdownItem
key={option.key}
description={option.description}
onClick={() => onChange(option.key)}
>
{option.content}
</DropdownItem>
));

return (
<Dropdown
onSelect={onToggle}
toggle={
<DropdownToggle id="select network" onToggle={onToggle}>
{diskOptions.find((o) => o.key === value)?.content || 'First disk'}
</DropdownToggle>
}
isOpen={isOpen}
dropdownItems={dropdownItems}
menuAppendTo="parent"
/>
);
};

return DropdownRenderer;
};

export const EditRootDisk: React.FC<EditRootDiskProps> = (props) => {
const { t } = useForkliftTranslation();

const plan = props.resource;
const rootDisk = plan.spec.vms?.[0]?.rootDisk;
const allVMsHasMatchingRootDisk = plan.spec.vms.every((vm) => vm?.rootDisk === rootDisk);

return (
<EditModal
{...props}
jsonPath={(obj: V1beta1Plan) => obj?.spec?.vms?.[0]?.rootDisk}
title={props?.title || t('Edit root disk')}
label={props?.label || t('Root disk')}
model={PlanModel}
onConfirmHook={onConfirm}
body={
<>
{t(
`Specify the root disk for Openshift Virtualization configuration and guest agent setup.`,
)}
{!allVMsHasMatchingRootDisk && (
<AlertMessageForModals
variant="warning"
title={'The plan rootDisk keys was manually configured'}
message={
<>
<p>
Warning: not all virtual machines are configures using the same root disk
number,
</p>
<p>updating the root disk number will override the current configuration.</p>
</>
}
/>
)}
</>
}
InputComponent={RootDiskInputFactory()}
/>
);
};

export type EditRootDiskProps = Modify<
EditModalProps,
{
resource: V1beta1Plan;
title?: string;
label?: string;
model?: K8sModel;
jsonPath?: string | string[];
}
>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @index(['./*', /style/g], f => `export * from '${f.path}';`)
export * from './EditRootDisk';
// @endindex

0 comments on commit b484d2d

Please sign in to comment.