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 788f25166..7974b5431 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 @@ -71,7 +71,7 @@ export const oVirtVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'status', - jsonPath: (data) => getVmPowerState('ovirt', (data as VmData)?.vm), + jsonPath: (data) => getVmPowerState((data as VmData)?.vm), label: t('Status'), isVisible: true, isIdentity: false, 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 3680138f3..bf902801c 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 @@ -2,8 +2,7 @@ import React from 'react'; import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common'; -import { ProviderVirtualMachinesList, VmData } from './components/ProviderVirtualMachinesList'; -import { getVmPowerState } from './utils/helpers/getVmPowerState'; +import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList'; import { OpenShiftVirtualMachinesRow } from './OpenShiftVirtualMachinesRow'; import { ProviderVirtualMachinesProps } from './ProviderVirtualMachines'; 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 6e5c304a1..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,8 +3,8 @@ import React from 'react'; import { ResourceField, RowProps } from '@kubev2v/common'; import { Td, Tr } from '@patternfly/react-table'; -import { VMCellProps, VMConcernsCellRenderer, VmData, VMNameCellRenderer } from './components'; import { PowerStateCellRenderer } from './components/PowerStateCellRenderer'; +import { VMCellProps, VMConcernsCellRenderer, VmData, VMNameCellRenderer } from './components'; const cellRenderers: Record> = { name: VMNameCellRenderer, 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 2991401bb..3072f31a4 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 @@ -59,7 +59,7 @@ export const openStackVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'status', - jsonPath: (data) => getVmPowerState('openstack', (data as VmData)?.vm), + jsonPath: (data) => getVmPowerState((data as VmData)?.vm), label: t('Status'), isVisible: true, isIdentity: false, 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 d5fb42788..6797458ef 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 @@ -67,7 +67,7 @@ export const vSphereVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [ }, { resourceFieldId: 'powerState', - jsonPath: (data) => getVmPowerState('vsphere', (data as VmData)?.vm), + jsonPath: (data) => getVmPowerState((data as VmData)?.vm), label: t('Power state'), isVisible: true, isIdentity: false, 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 index 57cd6ece5..4682eab7b 100644 --- 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 @@ -8,47 +8,57 @@ import { export type PowerState = 'on' | 'off' | 'unknown'; -// moved from packages/legacy/src/common/components/VMNameWithPowerState.tsx export const getVmPowerState = (vm?: ProviderVirtualMachine): PowerState => { - let powerStatus: PowerState = 'unknown'; - if (!vm) return powerStatus; + if (!vm) return 'unknown'; + switch (vm?.providerType) { - case 'ovirt': { - if ((vm as OVirtVM).status === 'up') powerStatus = 'on'; - if ((vm as OVirtVM).status === 'down') powerStatus = 'off'; - break; - } - case 'vsphere': { - if ((vm as VSphereVM).powerState === 'poweredOn') powerStatus = 'on'; - if ((vm as VSphereVM).powerState === 'poweredOff') powerStatus = 'off'; - break; - } - case 'openstack': { - const status = (vm as OpenstackVM).status; - if (status === 'ACTIVE') { - powerStatus = 'on'; - } - if (status === 'SHUTOFF') { - powerStatus = 'off'; - } - break; - } - case 'openshift': { - const status = (vm as OpenshiftVM)?.object?.status?.printableStatus; - if (status === 'Running') { - powerStatus = 'on'; - } else { - powerStatus = 'off'; - } - break; - } - case 'ova': { - powerStatus = 'off'; - break; - } - default: { - powerStatus = 'unknown'; - } + case 'ovirt': + return getOVirtVmPowerState(vm as OVirtVM); + case 'vsphere': + return getVSphereVmPowerState(vm as VSphereVM); + case 'openstack': + return getOpenStackVmPowerState(vm as OpenstackVM); + case 'openshift': + return getOpenShiftVmPowerState(vm as OpenshiftVM); + 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'; } - return powerStatus; }; + +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';