diff --git a/src/pages/container-service/containers/Containers/actions/Delete.jsx b/src/pages/container-service/containers/Containers/actions/Delete.jsx index 4b1adaee..0e8d80b4 100644 --- a/src/pages/container-service/containers/Containers/actions/Delete.jsx +++ b/src/pages/container-service/containers/Containers/actions/Delete.jsx @@ -14,6 +14,7 @@ import { ConfirmAction } from 'containers/Action'; import globalContainersStore from 'src/stores/zun/containers'; +import { checkItemAction } from 'resources/zun/container'; export default class DeleteContainer extends ConfirmAction { get id() { @@ -38,7 +39,7 @@ export default class DeleteContainer extends ConfirmAction { policy = 'container:container:delete'; - allowedCheckFunc = () => true; + allowedCheckFunc = (item) => checkItemAction(item, 'delete'); onSubmit = (data) => globalContainersStore.delete({ id: data.uuid }); } diff --git a/src/pages/container-service/containers/Containers/actions/Pause.jsx b/src/pages/container-service/containers/Containers/actions/Pause.jsx index 606a7e8c..d96e74d5 100644 --- a/src/pages/container-service/containers/Containers/actions/Pause.jsx +++ b/src/pages/container-service/containers/Containers/actions/Pause.jsx @@ -12,6 +12,7 @@ import { ConfirmAction } from 'containers/Action'; import globalContainersStore from 'src/stores/zun/containers'; +import { checkItemAction } from 'resources/zun/container'; export default class PauseContainer extends ConfirmAction { get id() { @@ -32,7 +33,7 @@ export default class PauseContainer extends ConfirmAction { policy = 'container:container:pause'; - allowedCheckFunc = () => true; + allowedCheckFunc = (item) => checkItemAction(item, 'pause'); onSubmit = (data) => globalContainersStore.pause({ id: data.uuid }); } diff --git a/src/pages/container-service/containers/Containers/actions/Reboot.jsx b/src/pages/container-service/containers/Containers/actions/Reboot.jsx index 9861590c..fa2af641 100644 --- a/src/pages/container-service/containers/Containers/actions/Reboot.jsx +++ b/src/pages/container-service/containers/Containers/actions/Reboot.jsx @@ -12,6 +12,7 @@ import { ConfirmAction } from 'containers/Action'; import globalContainersStore from 'src/stores/zun/containers'; +import { checkItemAction } from 'resources/zun/container'; export default class RebootContainer extends ConfirmAction { get id() { @@ -32,7 +33,7 @@ export default class RebootContainer extends ConfirmAction { policy = 'container:container:reboot'; - allowedCheckFunc = () => true; + allowedCheckFunc = (item) => checkItemAction(item, 'reboot'); onSubmit = (data) => globalContainersStore.reboot({ id: data.uuid }); } diff --git a/src/pages/container-service/containers/Containers/actions/Start.jsx b/src/pages/container-service/containers/Containers/actions/Start.jsx index f59dcf08..d6c605cd 100644 --- a/src/pages/container-service/containers/Containers/actions/Start.jsx +++ b/src/pages/container-service/containers/Containers/actions/Start.jsx @@ -12,6 +12,7 @@ import { ConfirmAction } from 'containers/Action'; import globalContainersStore from 'src/stores/zun/containers'; +import { checkItemAction } from 'resources/zun/container'; export default class StartContainer extends ConfirmAction { get id() { @@ -32,7 +33,7 @@ export default class StartContainer extends ConfirmAction { policy = 'container:container:start'; - allowedCheckFunc = () => true; + allowedCheckFunc = (item) => checkItemAction(item, 'start'); onSubmit = (data) => globalContainersStore.start({ id: data.uuid }); } diff --git a/src/pages/container-service/containers/Containers/actions/Stop.jsx b/src/pages/container-service/containers/Containers/actions/Stop.jsx index a682ad78..a851e515 100644 --- a/src/pages/container-service/containers/Containers/actions/Stop.jsx +++ b/src/pages/container-service/containers/Containers/actions/Stop.jsx @@ -14,6 +14,7 @@ import { ConfirmAction } from 'containers/Action'; import globalContainersStore from 'src/stores/zun/containers'; +import { checkItemAction } from 'resources/zun/container'; export default class StopContainer extends ConfirmAction { get id() { @@ -34,7 +35,7 @@ export default class StopContainer extends ConfirmAction { policy = 'container:container:stop'; - allowedCheckFunc = () => true; + allowedCheckFunc = (item) => checkItemAction(item, 'stop'); onSubmit = (data) => globalContainersStore.stop({ id: data.uuid }); } diff --git a/src/pages/container-service/containers/Containers/actions/Unpause.jsx b/src/pages/container-service/containers/Containers/actions/Unpause.jsx index 54ef08be..07eba740 100644 --- a/src/pages/container-service/containers/Containers/actions/Unpause.jsx +++ b/src/pages/container-service/containers/Containers/actions/Unpause.jsx @@ -14,6 +14,7 @@ import { ConfirmAction } from 'containers/Action'; import globalContainersStore from 'src/stores/zun/containers'; +import { checkItemAction } from 'resources/zun/container'; export default class UnpauseContainer extends ConfirmAction { get id() { @@ -34,7 +35,7 @@ export default class UnpauseContainer extends ConfirmAction { policy = 'container:container:unpause'; - allowedCheckFunc = () => true; + allowedCheckFunc = (item) => checkItemAction(item, 'unpause'); onSubmit = (data) => globalContainersStore.unpause({ id: data.uuid }); } diff --git a/src/resources/zun/container.js b/src/resources/zun/container.js index 53e69612..5c9b662f 100644 --- a/src/resources/zun/container.js +++ b/src/resources/zun/container.js @@ -6,6 +6,9 @@ export const containerStatus = { Paused: t('Paused'), Restarting: t('Restarting'), Deleting: t('Deleting'), + Error: t('Error'), + Unknown: t('Unknown'), + Rebuilding: t('Rebuilding'), }; export const containerTaskStatus = { @@ -16,3 +19,70 @@ export const containerTaskStatus = { container_rebooting: t('Container Rebooting'), container_deleting: t('Container Deleting'), }; + +const states = { + ERROR: 'Error', + RUNNING: 'Running', + STOPPED: 'Stopped', + PAUSED: 'Paused', + UNKNOWN: 'Unknown', + CREATING: 'Creating', + CREATED: 'Created', + DELETED: 'Deleted', + DELETING: 'Deleting', + REBUILDING: 'Rebuilding', + DEAD: 'Dead', + RESTARTING: 'Restarting', +}; + +const validStates = { + update: [states.CREATED, states.RUNNING, states.STOPPED, states.PAUSED], + start: [states.CREATED, states.STOPPED, states.ERROR], + stop: [states.RUNNING], + reboot: [states.CREATED, states.RUNNING, states.STOPPED, states.ERROR], + rebuild: [states.CREATED, states.RUNNING, states.STOPPED, states.ERROR], + pause: [states.RUNNING], + unpause: [states.PAUSED], + execute: [states.RUNNING], + kill: [states.RUNNING], + delete: [ + states.CREATED, + states.ERROR, + states.STOPPED, + states.DELETED, + states.DEAD, + ], + delete_force: [ + states.CREATED, + states.CREATING, + states.ERROR, + states.RUNNING, + states.STOPPED, + states.UNKNOWN, + states.DELETED, + states.DEAD, + states.RESTARTING, + states.REBUILDING, + states.DELETING, + ], + delete_stop: [ + states.RUNNING, + states.CREATED, + states.ERROR, + states.STOPPED, + states.DELETED, + states.DEAD, + ], + manage_security_groups: [ + states.CREATED, + states.RUNNING, + states.STOPPED, + states.PAUSED, + ], +}; + +export const checkItemAction = (item, actionName) => { + if (!item) return false; + const { status } = item; + return validStates[actionName].includes(status); +};