-
Notifications
You must be signed in to change notification settings - Fork 615
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 #1774 from jtomasek/add-host-status-column
Add host status column
- Loading branch information
Showing
6 changed files
with
245 additions
and
45 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
frontend/packages/metal3-plugin/src/components/host-status.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,59 @@ | ||
import * as React from 'react'; | ||
import { Button } from 'patternfly-react'; | ||
|
||
import { K8sResourceKind } from '@console/internal/module/k8s'; | ||
import { StatusIconAndText } from '@console/internal/components/utils/status-icon'; | ||
import { RequireCreatePermission } from '@console/internal/components/utils'; | ||
import { getHostStatus } from '../utils/host-status'; | ||
|
||
import { | ||
HOST_STATUS_DISCOVERED, | ||
HOST_PROGRESS_STATES, | ||
HOST_ERROR_STATES, | ||
HOST_SUCCESS_STATES, | ||
} from '../constants'; | ||
import { BaremetalHostModel } from '../models'; | ||
|
||
// TODO(jtomasek): Update this with onClick handler once add discovered host functionality | ||
// is available | ||
export const AddDiscoveredHostButton: React.FC<{ host: K8sResourceKind }> = ( | ||
{ host }, // eslint-disable-line @typescript-eslint/no-unused-vars | ||
) => { | ||
const { | ||
metadata: { namespace }, | ||
} = host; | ||
|
||
return ( | ||
<RequireCreatePermission model={BaremetalHostModel} namespace={namespace}> | ||
<Button bsStyle="link"> | ||
<StatusIconAndText status="Add host" iconName="add-circle-o" /> | ||
</Button> | ||
</RequireCreatePermission> | ||
); | ||
}; | ||
|
||
type BaremetalHostStatusProps = { | ||
host: K8sResourceKind; | ||
machine?: K8sResourceKind; | ||
node?: K8sResourceKind; | ||
}; | ||
|
||
const BaremetalHostStatus = ({ host }: BaremetalHostStatusProps) => { | ||
const hostStatus = getHostStatus(host); | ||
const { status, title } = hostStatus; | ||
|
||
switch (true) { | ||
case status === HOST_STATUS_DISCOVERED: | ||
return <AddDiscoveredHostButton host={host} />; | ||
case HOST_PROGRESS_STATES.includes(status): | ||
return <StatusIconAndText status={title} iconName="refresh" />; | ||
case HOST_SUCCESS_STATES.includes(status): | ||
return <StatusIconAndText status={title} iconName="ok" />; | ||
case HOST_ERROR_STATES.includes(status): | ||
return <StatusIconAndText status={title} iconName="error-circle-o" />; | ||
default: | ||
return <StatusIconAndText status={title} iconName="unknown" />; | ||
} | ||
}; | ||
|
||
export default BaremetalHostStatus; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
export const HOST_STATUS_READY = 'ready'; | ||
export const HOST_STATUS_DISCOVERED = 'discovered'; | ||
export const HOST_STATUS_OK = 'OK'; | ||
export const HOST_STATUS_EXTERNALLY_PROVISIONED = 'externally provisioned'; | ||
export const HOST_STATUS_PROVISIONED = 'provisioned'; | ||
export const HOST_STATUS_DEPROVISIONED = 'deprovisioned'; | ||
export const HOST_STATUS_REGISTERING = 'registering'; | ||
export const HOST_STATUS_INSPECTING = 'inspecting'; | ||
export const HOST_STATUS_PREPARING_TO_PROVISION = 'preparing to provision'; | ||
export const HOST_STATUS_PROVISIONING = 'provisioning'; | ||
export const HOST_STATUS_DEPROVISIONING = 'deprovisioning'; | ||
export const HOST_STATUS_MAKING_HOST_AVAILABLE = 'making host available'; | ||
export const HOST_STATUS_MATCH_PROFILE = 'match profile'; | ||
export const HOST_STATUS_STARTING_MAINTENANCE = 'starting maintenance'; | ||
export const HOST_STATUS_STOPPING_MAINTENANCE = 'stopping maintenance'; | ||
export const HOST_STATUS_MAINTENANCE = 'maintenance'; | ||
export const HOST_STATUS_VALIDATION_ERROR = 'validation error'; | ||
export const HOST_STATUS_REGISTRATION_ERROR = 'registration error'; | ||
export const HOST_STATUS_PROVISIONING_ERROR = 'provisioning error'; | ||
export const HOST_STATUS_POWER_MANAGEMENT_ERROR = 'power management error'; | ||
|
||
export const HOST_STATUS_TITLES = { | ||
[HOST_STATUS_READY]: 'Ready', | ||
[HOST_STATUS_DISCOVERED]: 'Discovered', | ||
[HOST_STATUS_OK]: 'OK', | ||
[HOST_STATUS_PROVISIONED]: 'Provisioned', | ||
[HOST_STATUS_EXTERNALLY_PROVISIONED]: 'Externally provisioned', | ||
[HOST_STATUS_DEPROVISIONED]: 'Deprovisioned', | ||
[HOST_STATUS_REGISTERING]: 'Registering', | ||
[HOST_STATUS_INSPECTING]: 'Inspecting', | ||
[HOST_STATUS_PREPARING_TO_PROVISION]: 'Preparing to provision', | ||
[HOST_STATUS_PROVISIONING]: 'Provisioning', | ||
[HOST_STATUS_DEPROVISIONING]: 'Deprovisioning', | ||
[HOST_STATUS_MAKING_HOST_AVAILABLE]: 'Making host available', | ||
[HOST_STATUS_VALIDATION_ERROR]: 'Validation Error(s)', | ||
[HOST_STATUS_REGISTRATION_ERROR]: 'Registration Error', | ||
[HOST_STATUS_PROVISIONING_ERROR]: 'Provisioning Error', | ||
[HOST_STATUS_POWER_MANAGEMENT_ERROR]: 'Power Management Error', | ||
[HOST_STATUS_STARTING_MAINTENANCE]: 'Starting maintenance', | ||
[HOST_STATUS_STOPPING_MAINTENANCE]: 'Stopping maintenance', | ||
[HOST_STATUS_MAINTENANCE]: 'Maintenance', | ||
[HOST_STATUS_MATCH_PROFILE]: 'Matching profile', | ||
}; | ||
|
||
export const HOST_ERROR_STATES = [ | ||
HOST_STATUS_REGISTRATION_ERROR, | ||
HOST_STATUS_PROVISIONING_ERROR, | ||
HOST_STATUS_VALIDATION_ERROR, | ||
HOST_STATUS_POWER_MANAGEMENT_ERROR, | ||
]; | ||
|
||
export const HOST_WARN_STATES = []; | ||
|
||
export const HOST_PROGRESS_STATES = [ | ||
HOST_STATUS_INSPECTING, | ||
HOST_STATUS_PREPARING_TO_PROVISION, | ||
HOST_STATUS_PREPARING_TO_PROVISION, | ||
HOST_STATUS_PROVISIONING, | ||
HOST_STATUS_DEPROVISIONING, | ||
HOST_STATUS_MAKING_HOST_AVAILABLE, | ||
HOST_STATUS_REGISTERING, | ||
HOST_STATUS_STARTING_MAINTENANCE, | ||
HOST_STATUS_STOPPING_MAINTENANCE, | ||
HOST_STATUS_MATCH_PROFILE, | ||
]; | ||
|
||
export const HOST_SUCCESS_STATES = [ | ||
HOST_STATUS_READY, | ||
HOST_STATUS_DISCOVERED, | ||
HOST_STATUS_OK, | ||
HOST_STATUS_PROVISIONED, | ||
HOST_STATUS_EXTERNALLY_PROVISIONED, | ||
HOST_STATUS_DEPROVISIONED, | ||
]; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { K8sResourceKind } from '@console/internal/module/k8s'; | ||
|
||
import { | ||
getHostOperationalStatus, | ||
getHostProvisioningState, | ||
getHostErrorMessage, | ||
// isNodeUnschedulable, | ||
} from '../selectors'; | ||
|
||
import { | ||
HOST_STATUS_TITLES, | ||
HOST_STATUS_READY, | ||
// HOST_STATUS_STARTING_MAINTENANCE, | ||
} from '../constants'; | ||
|
||
// import { NOT_HANDLED } from '../common'; | ||
|
||
// const isStartingMaintenance = (node) => { | ||
// if (isNodeUnschedulable(node)) { | ||
// return { | ||
// status: HOST_STATUS_STARTING_MAINTENANCE, | ||
// text: HOST_STATUS_TITLES[HOST_STATUS_STARTING_MAINTENANCE], | ||
// }; | ||
// } | ||
// return NOT_HANDLED; | ||
// }; | ||
|
||
const getBaremetalHostStatus = (host: K8sResourceKind) => { | ||
const operationalStatus = getHostOperationalStatus(host); | ||
const provisioningState = getHostProvisioningState(host); | ||
|
||
const hostStatus = provisioningState || operationalStatus || undefined; | ||
return { | ||
status: hostStatus, | ||
title: HOST_STATUS_TITLES[hostStatus] || hostStatus, | ||
errorMessage: getHostErrorMessage(host), | ||
}; | ||
}; | ||
|
||
export const getHostStatus = ( | ||
host: K8sResourceKind, | ||
// machine?: MachineKind, | ||
// node?: NodeKind, | ||
) => { | ||
// TODO(jtomasek): make this more robust by including node/machine status | ||
// return isStartingMaintenance(node) || getBaremetalHostStatus(host); | ||
return getBaremetalHostStatus(host); | ||
}; | ||
|
||
export const getSimpleHostStatus = ( | ||
host: K8sResourceKind, | ||
// machine?: MachineKind, | ||
// node?: NodeKind, | ||
): string => getHostStatus(host).status; | ||
|
||
export const canHostAddMachine = (host: K8sResourceKind): boolean => | ||
[HOST_STATUS_READY].includes(getSimpleHostStatus(host)); | ||
// export const canHostStartMaintenance = (hostNode: NodeKind) => hostNode && !isNodeUnschedulable(hostNode); | ||
// export const canHostStopMaintenance = (hostNode: NodeKind) => isNodeUnschedulable(hostNode); |