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

Render VMs power state as icon with tooltip #723

Merged
merged 3 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, React.FC<VMCellProps>> = {
name: VMNameCellRenderer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
rszwajko marked this conversation as resolved.
Show resolved Hide resolved
label: t('Power state'),
isVisible: true,
isIdentity: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
rszwajko marked this conversation as resolved.
Show resolved Hide resolved
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';
Loading