forked from kubev2v/forklift-console-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubev2v#723 from rszwajko/vmPowerState
Render VMs power state as icon with tooltip
- Loading branch information
Showing
12 changed files
with
146 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...odules/Providers/views/details/tabs/VirtualMachines/components/PowerStateCellRenderer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<VMCellProps> = ({ data }) => { | ||
const { t } = useForkliftTranslation(); | ||
const powerState = getVmPowerState(data?.vm); | ||
const states: { [key in PowerState]: [JSX.Element, string, string] } = { | ||
on: [<PowerOffIcon color="green" key="on" />, t('Powered on'), t('On')], | ||
off: [<OffIcon color="red" key="off" />, t('Powered off'), t('Off')], | ||
unknown: [<UnknownIcon key="unknown" />, t('Unknown power state'), t('Unknown')], | ||
}; | ||
const [icon, tooltipText, shortText] = states[powerState] || states.unknown; | ||
|
||
return ( | ||
<TableIconCell icon={<Tooltip content={tooltipText}>{icon}</Tooltip>}> | ||
{shortText} | ||
</TableIconCell> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...nsole-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/getVmPowerState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
1 change: 1 addition & 0 deletions
1
...le-plugin/src/modules/Providers/views/details/tabs/VirtualMachines/utils/helpers/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @index(['./*', /style/g], f => `export * from '${f.path}';`) | ||
export * from './getHighestPriorityConcern'; | ||
export * from './getVmPowerState'; | ||
// @endindex |