diff --git a/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json b/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json index 9497848fb..3c94c8e42 100644 --- a/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json +++ b/packages/forklift-console-plugin/locales/en/plugin__forklift-console-plugin.json @@ -128,6 +128,7 @@ "Filter by namespace": "Filter by namespace", "Filter by network": "Filter by network", "Filter by path": "Filter by path", + "Filter by power state": "Filter by power state", "Filter by status": "Filter by status", "Filter by tenant": "Filter by tenant", "Flavor": "Flavor", @@ -233,6 +234,8 @@ "Number of storage volumes in cluster": "Number of storage volumes in cluster", "Number of virtual machines in cluster": "Number of virtual machines in cluster", "Number of virtual machines in OVA files": "Number of virtual machines in OVA files", + "Off": "Off", + "On": "On", "OpenShift cluster API endpoint. Empty may be used for the host provider.": "OpenShift cluster API endpoint. Empty may be used for the host provider.", "OpenStack domain for application credential credentials.": "OpenStack domain for application credential credentials.", "OpenStack domain for password credentials.": "OpenStack domain for password credentials.", @@ -271,6 +274,9 @@ "Please enter URL for the kubernetes API server, if empty URL default to this cluster.": "Please enter URL for the kubernetes API server, if empty URL default to this cluster.", "Please enter URL for vSphere REST APIs server.": "Please enter URL for vSphere REST APIs server.", "Pod network": "Pod network", + "Power state": "Power state", + "Powered off": "Powered off", + "Powered on": "Powered on", "Precopy interval (minutes)": "Precopy interval (minutes)", "Product": "Product", "Project": "Project", @@ -376,6 +382,8 @@ "Unable to retrieve data": "Unable to retrieve data", "Undefined": "Undefined", "Unique Kubernetes resource name identifier": "Unique Kubernetes resource name identifier", + "Unknown": "Unknown", + "Unknown power state": "Unknown power state", "Unsupported provider type": "Unsupported provider type", "Update credentials": "Update credentials", "Updated": "Updated", diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx index 13c579521..a3c48759c 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesList.tsx @@ -2,9 +2,10 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList'; +import { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList'; import { OVirtVirtualMachinesRow } from './OVirtVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; +import { getVmPowerState } from './utils'; export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ { @@ -70,13 +71,14 @@ export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'status', - jsonPath: '$.vm.status', + jsonPath: (data: VmData) => getVmPowerState(data?.vm), label: t('Status'), isVisible: true, isIdentity: false, filter: { - type: 'freetext', + type: 'enum', placeholderLabel: t('Filter by status'), + values: EnumToTuple({ off: 'Off', on: 'On', unknown: 'Unknown' }), }, sortable: true, }, diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesRow.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesRow.tsx index 3a3099754..084862cde 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesRow.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OVirtVirtualMachinesRow.tsx @@ -5,6 +5,7 @@ import { ResourceField, RowProps } from '@kubev2v/common'; import { OVirtVM } from '@kubev2v/types'; import { Td, Tr } from '@patternfly/react-table'; +import { PowerStateCellRenderer } from './components/PowerStateCellRenderer'; import { VMCellProps, VMConcernsCellRenderer, VMNameCellRenderer } from './components'; export interface VmData { @@ -36,7 +37,7 @@ const cellRenderers: Record> = { host: ({ data }) => {(data?.vm as OVirtVM)?.host}, cluster: ({ data }) => {(data?.vm as OVirtVM)?.cluster}, path: ({ data }) => {(data?.vm as OVirtVM)?.path}, - status: ({ data }) => {(data?.vm as OVirtVM)?.status}, + status: PowerStateCellRenderer, description: ({ data }) => {(data?.vm as OVirtVM)?.description}, }; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx index bf902801c..09acba996 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesList.tsx @@ -3,8 +3,10 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList'; +import { VmData } from './components'; import { OpenShiftVirtualMachinesRow } from './OpenShiftVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; +import { getVmPowerState } from './utils'; const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ { @@ -32,6 +34,19 @@ const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ values: EnumToTuple({ Critical: 'Critical', Warning: 'Warning', Information: 'Information' }), }, }, + { + resourceFieldId: 'status', + jsonPath: (data: VmData) => getVmPowerState(data?.vm), + label: t('Status'), + isVisible: true, + isIdentity: false, + filter: { + type: 'enum', + placeholderLabel: t('Filter by status'), + values: EnumToTuple({ off: 'Off', on: 'On', unknown: 'Unknown' }), + }, + sortable: true, + }, ]; export const OpenShiftVirtualMachinesList: React.FC = ({ diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx index 8b11970fb..71ae071ec 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenShiftVirtualMachinesRow.tsx @@ -3,11 +3,13 @@ import React from 'react'; import { ResourceField, RowProps } from '@kubev2v/common'; import { Td, Tr } from '@patternfly/react-table'; +import { PowerStateCellRenderer } from './components/PowerStateCellRenderer'; import { VMCellProps, VMConcernsCellRenderer, VmData, VMNameCellRenderer } from './components'; const cellRenderers: Record> = { name: VMNameCellRenderer, concerns: VMConcernsCellRenderer, + status: PowerStateCellRenderer, }; const renderTd = ({ resourceData, resourceFieldId, resourceFields }: RenderTdProps) => { diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx index 6fe4271a6..28d5eeb9b 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/OpenStackVirtualMachinesList.tsx @@ -2,7 +2,8 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList'; +import { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList'; +import { getVmPowerState } from './utils/helpers/getVmPowerState'; import { OpenStackVirtualMachinesRow } from './OpenStackVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; @@ -58,13 +59,14 @@ export const openStackVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'status', - jsonPath: '$.vm.status', + jsonPath: (data: VmData) => getVmPowerState(data?.vm), label: t('Status'), isVisible: true, isIdentity: false, filter: { - type: 'freetext', + type: 'enum', placeholderLabel: t('Filter by status'), + values: EnumToTuple({ off: 'Off', on: 'On', unknown: 'Unknown' }), }, sortable: true, }, diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx index 2413a605c..433944b2d 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesList.tsx @@ -2,8 +2,9 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList'; +import { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; +import { getVmPowerState } from './utils'; import { VSphereVirtualMachinesRow } from './VSphereVirtualMachinesRow'; export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ @@ -65,14 +66,15 @@ export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ sortable: true, }, { - resourceFieldId: 'status', - jsonPath: '$.vm.powerState', - label: t('Status'), + resourceFieldId: 'powerState', + jsonPath: (data: VmData) => getVmPowerState(data?.vm), + label: t('Power state'), isVisible: true, isIdentity: false, filter: { - type: 'freetext', - placeholderLabel: t('Filter by status'), + type: 'enum', + placeholderLabel: t('Filter by power state'), + values: EnumToTuple({ off: 'Off', on: 'On', unknown: 'Unknown' }), }, sortable: true, }, diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesRow.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesRow.tsx index 3f1c571a4..936dcbd40 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesRow.tsx +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/VSphereVirtualMachinesRow.tsx @@ -5,7 +5,12 @@ import { ResourceField, RowProps } from '@kubev2v/common'; import { VSphereVM } from '@kubev2v/types'; import { Td, Tr } from '@patternfly/react-table'; -import { VMCellProps, VMConcernsCellRenderer, VMNameCellRenderer } from './components'; +import { + PowerStateCellRenderer, + VMCellProps, + VMConcernsCellRenderer, + VMNameCellRenderer, +} from './components'; export interface VmData { vm: VSphereVM; @@ -38,7 +43,7 @@ const cellRenderers: Record> = { {Boolean((data?.vm as VSphereVM)?.isTemplate).toString()} ), path: ({ data }) => {(data?.vm as VSphereVM)?.path}, - status: ({ data }) => {(data?.vm as VSphereVM)?.powerState}, + powerState: PowerStateCellRenderer, }; export const VSphereVirtualMachinesRow: React.FC> = ({ diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/PowerStateCellRenderer.tsx b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/PowerStateCellRenderer.tsx new file mode 100644 index 000000000..6bff7bcf8 --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/PowerStateCellRenderer.tsx @@ -0,0 +1,28 @@ +import React from 'react'; +import { TableIconCell } from 'src/modules/Providers/utils'; +import { useForkliftTranslation } from 'src/utils/i18n'; + +import { Tooltip } from '@patternfly/react-core'; +import { OffIcon, PowerOffIcon, UnknownIcon } from '@patternfly/react-icons'; + +import { getVmPowerState } from '../utils'; +import { PowerState } from '../utils/helpers/getVmPowerState'; + +import { VMCellProps } from './VMCellProps'; + +export const PowerStateCellRenderer: React.FC = ({ data }) => { + const { t } = useForkliftTranslation(); + const powerState = getVmPowerState(data?.vm); + const states: { [key in PowerState]: [JSX.Element, string, string] } = { + on: [, t('Powered on'), t('On')], + off: [, t('Powered off'), t('Off')], + unknown: [, t('Unknown power state'), t('Unknown')], + }; + const [icon, tooltipText, shortText] = states[powerState] || states.unknown; + + return ( + {icon}}> + {shortText} + + ); +}; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts index bfa04fb19..f374d52b9 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts @@ -1,4 +1,5 @@ // @index(['./*', /style/g], f => `export * from '${f.path}';`) +export * from './PowerStateCellRenderer'; export * from './VMCellProps'; export * from './VMConcernsCellRenderer'; export * from './VMNameCellRenderer'; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getVmPowerState.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getVmPowerState.ts new file mode 100644 index 000000000..e86fdcd3d --- /dev/null +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getVmPowerState.ts @@ -0,0 +1,64 @@ +import { + OpenshiftVM, + OpenstackVM, + OVirtVM, + ProviderVirtualMachine, + VSphereVM, +} from '@kubev2v/types'; + +export type PowerState = 'on' | 'off' | 'unknown'; + +export const getVmPowerState = (vm?: ProviderVirtualMachine): PowerState => { + if (!vm) return 'unknown'; + + switch (vm?.providerType) { + case 'ovirt': + return getOVirtVmPowerState(vm); + case 'vsphere': + return getVSphereVmPowerState(vm); + case 'openstack': + return getOpenStackVmPowerState(vm); + case 'openshift': + return getOpenShiftVmPowerState(vm); + case 'ova': + return 'off'; + default: + return 'unknown'; + } +}; + +const getOVirtVmPowerState = (vm: OVirtVM): PowerState => { + switch (vm?.status) { + case 'up': + return 'on'; + case 'down': + return 'off'; + default: + return 'unknown'; + } +}; + +const getVSphereVmPowerState = (vm: VSphereVM): PowerState => { + switch (vm?.powerState) { + case 'poweredOn': + return 'on'; + case 'poweredOff': + return 'off'; + default: + return 'unknown'; + } +}; + +const getOpenStackVmPowerState = (vm: OpenstackVM): PowerState => { + switch (vm?.status) { + case 'ACTIVE': + return 'on'; + case 'SHUTOFF': + return 'off'; + default: + return 'unknown'; + } +}; + +const getOpenShiftVmPowerState = (vm: OpenshiftVM): PowerState => + vm?.object?.status?.printableStatus === 'Running' ? 'on' : 'off'; diff --git a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts index 07e829de1..266cbc91d 100644 --- a/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts +++ b/packages/forklift-console-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts @@ -1,3 +1,4 @@ // @index(['./*', /style/g], f => `export * from '${f.path}';`) export * from './getHighestPriorityConcern'; +export * from './getVmPowerState'; // @endindex