feat(lite): introduce POWER_STATE and VM_OPERATION enums (#6846)
This commit is contained in:
committed by
GitHub
parent
6864775b8a
commit
e1145f35ee
@@ -4,7 +4,7 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import UiIcon from "@/components/ui/icon/UiIcon.vue";
|
||||
import type { PowerState } from "@/libs/xen-api";
|
||||
import { POWER_STATE } from "@/libs/xen-api";
|
||||
import {
|
||||
faMoon,
|
||||
faPause,
|
||||
@@ -15,14 +15,14 @@ import {
|
||||
import { computed } from "vue";
|
||||
|
||||
const props = defineProps<{
|
||||
state: PowerState;
|
||||
state: POWER_STATE;
|
||||
}>();
|
||||
|
||||
const icons = {
|
||||
Running: faPlay,
|
||||
Paused: faPause,
|
||||
Suspended: faMoon,
|
||||
Halted: faStop,
|
||||
[POWER_STATE.RUNNING]: faPlay,
|
||||
[POWER_STATE.PAUSED]: faPause,
|
||||
[POWER_STATE.SUSPENDED]: faMoon,
|
||||
[POWER_STATE.HALTED]: faStop,
|
||||
};
|
||||
|
||||
const icon = computed(() => icons[props.state] ?? faQuestion);
|
||||
|
||||
@@ -38,6 +38,7 @@ import UiCardFooter from "@/components/ui/UiCardFooter.vue";
|
||||
import UiCardSpinner from "@/components/ui/UiCardSpinner.vue";
|
||||
import UiCardTitle from "@/components/ui/UiCardTitle.vue";
|
||||
import { percent } from "@/libs/utils";
|
||||
import { POWER_STATE } from "@/libs/xen-api";
|
||||
import { useHostMetricsStore } from "@/stores/host-metrics.store";
|
||||
import { useHostStore } from "@/stores/host.store";
|
||||
import { useVmMetricsStore } from "@/stores/vm-metrics.store";
|
||||
@@ -45,7 +46,7 @@ import { useVmStore } from "@/stores/vm.store";
|
||||
import { logicAnd } from "@vueuse/math";
|
||||
import { computed } from "vue";
|
||||
|
||||
const ACTIVE_STATES = new Set(["Running", "Paused"]);
|
||||
const ACTIVE_STATES = new Set([POWER_STATE.RUNNING, POWER_STATE.PAUSED]);
|
||||
|
||||
const {
|
||||
hasError: hostStoreHasError,
|
||||
|
||||
@@ -97,6 +97,7 @@ import PowerStateIcon from "@/components/PowerStateIcon.vue";
|
||||
import UiIcon from "@/components/ui/icon/UiIcon.vue";
|
||||
import { isHostRunning, isOperationsPending } from "@/libs/utils";
|
||||
import type { XenApiHost, XenApiVm } from "@/libs/xen-api";
|
||||
import { POWER_STATE, VM_OPERATION } from "@/libs/xen-api";
|
||||
import { useHostMetricsStore } from "@/stores/host-metrics.store";
|
||||
import { useHostStore } from "@/stores/host.store";
|
||||
import { usePoolStore } from "@/stores/pool.store";
|
||||
@@ -136,42 +137,52 @@ const vmRefsWithPowerState = computed(() =>
|
||||
const xenApi = useXenApiStore().getXapi();
|
||||
|
||||
const areVmsRunning = computed(() =>
|
||||
vms.value.every((vm) => vm.power_state === "Running")
|
||||
vms.value.every((vm) => vm.power_state === POWER_STATE.RUNNING)
|
||||
);
|
||||
const areVmsHalted = computed(() =>
|
||||
vms.value.every((vm) => vm.power_state === "Halted")
|
||||
vms.value.every((vm) => vm.power_state === POWER_STATE.HALTED)
|
||||
);
|
||||
const areVmsSuspended = computed(() =>
|
||||
vms.value.every((vm) => vm.power_state === "Suspended")
|
||||
vms.value.every((vm) => vm.power_state === POWER_STATE.SUSPENDED)
|
||||
);
|
||||
const areVmsPaused = computed(() =>
|
||||
vms.value.every((vm) => vm.power_state === "Paused")
|
||||
vms.value.every((vm) => vm.power_state === POWER_STATE.PAUSED)
|
||||
);
|
||||
|
||||
const areOperationsPending = (operation: string | string[]) =>
|
||||
const areOperationsPending = (operation: VM_OPERATION | VM_OPERATION[]) =>
|
||||
vms.value.some((vm) => isOperationsPending(vm, operation));
|
||||
|
||||
const areVmsBusyToStart = computed(() => areOperationsPending("start"));
|
||||
const areVmsBusyToStart = computed(() =>
|
||||
areOperationsPending(VM_OPERATION.START)
|
||||
);
|
||||
const areVmsBusyToStartOnHost = computed(() =>
|
||||
areOperationsPending("start_on")
|
||||
areOperationsPending(VM_OPERATION.START_ON)
|
||||
);
|
||||
const areVmsBusyToPause = computed(() =>
|
||||
areOperationsPending(VM_OPERATION.PAUSE)
|
||||
);
|
||||
const areVmsBusyToSuspend = computed(() =>
|
||||
areOperationsPending(VM_OPERATION.SUSPEND)
|
||||
);
|
||||
const areVmsBusyToPause = computed(() => areOperationsPending("pause"));
|
||||
const areVmsBusyToSuspend = computed(() => areOperationsPending("suspend"));
|
||||
const areVmsBusyToResume = computed(() =>
|
||||
areOperationsPending(["unpause", "resume"])
|
||||
areOperationsPending([VM_OPERATION.UNPAUSE, VM_OPERATION.RESUME])
|
||||
);
|
||||
const areVmsBusyToReboot = computed(() =>
|
||||
areOperationsPending(VM_OPERATION.CLEAN_REBOOT)
|
||||
);
|
||||
const areVmsBusyToReboot = computed(() => areOperationsPending("clean_reboot"));
|
||||
const areVmsBusyToForceReboot = computed(() =>
|
||||
areOperationsPending("hard_reboot")
|
||||
areOperationsPending(VM_OPERATION.HARD_REBOOT)
|
||||
);
|
||||
const areVmsBusyToShutdown = computed(() =>
|
||||
areOperationsPending("clean_shutdown")
|
||||
areOperationsPending(VM_OPERATION.CLEAN_SHUTDOWN)
|
||||
);
|
||||
const areVmsBusyToForceShutdown = computed(() =>
|
||||
areOperationsPending("hard_shutdown")
|
||||
areOperationsPending(VM_OPERATION.HARD_SHUTDOWN)
|
||||
);
|
||||
const getHostState = (host: XenApiHost) =>
|
||||
isHostRunning(host, hostMetricsSubscription) ? "Running" : "Halted";
|
||||
isHostRunning(host, hostMetricsSubscription)
|
||||
? POWER_STATE.RUNNING
|
||||
: POWER_STATE.HALTED;
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped>
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
XenApiHostMetrics,
|
||||
XenApiRecord,
|
||||
XenApiVm,
|
||||
VM_OPERATION,
|
||||
} from "@/libs/xen-api";
|
||||
import type { CollectionSubscription } from "@/stores/xapi-collection.store";
|
||||
import type { Filter } from "@/types/filter";
|
||||
@@ -194,7 +195,7 @@ export function requireSubscription<T>(
|
||||
|
||||
export const isOperationsPending = (
|
||||
obj: XenApiVm,
|
||||
operations: string[] | string
|
||||
operations: VM_OPERATION[] | VM_OPERATION
|
||||
) => {
|
||||
const currentOperations = Object.values(obj.current_operations);
|
||||
return castArray(operations).some((operation) =>
|
||||
|
||||
@@ -65,7 +65,27 @@ export const getRawObjectType = (type: ObjectType): RawObjectType => {
|
||||
return OBJECT_TYPES[type];
|
||||
};
|
||||
|
||||
export type PowerState = "Running" | "Paused" | "Halted" | "Suspended";
|
||||
export enum POWER_STATE {
|
||||
RUNNING = "Running",
|
||||
PAUSED = "Paused",
|
||||
HALTED = "Halted",
|
||||
SUSPENDED = "Suspended",
|
||||
}
|
||||
|
||||
export enum VM_OPERATION {
|
||||
START = "start",
|
||||
START_ON = "start_on",
|
||||
RESUME = "resume",
|
||||
UNPAUSE = "unpause",
|
||||
CLONE = "clone",
|
||||
SHUTDOWN = "shutdown",
|
||||
CLEAN_SHUTDOWN = "clean_shutdown",
|
||||
HARD_SHUTDOWN = "hard_shutdown",
|
||||
CLEAN_REBOOT = "clean_reboot",
|
||||
HARD_REBOOT = "hard_reboot",
|
||||
PAUSE = "pause",
|
||||
SUSPEND = "suspend",
|
||||
}
|
||||
|
||||
export interface XenApiRecord {
|
||||
$ref: string;
|
||||
@@ -98,12 +118,12 @@ export interface XenApiSr extends XenApiRecord {
|
||||
}
|
||||
|
||||
export interface XenApiVm extends XenApiRecord {
|
||||
current_operations: Record<string, string>;
|
||||
current_operations: Record<string, VM_OPERATION>;
|
||||
guest_metrics: string;
|
||||
metrics: string;
|
||||
name_label: string;
|
||||
name_description: string;
|
||||
power_state: PowerState;
|
||||
power_state: POWER_STATE;
|
||||
resident_on: string;
|
||||
consoles: string[];
|
||||
is_control_domain: boolean;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { requireSubscription, sortRecordsByNameLabel } from "@/libs/utils";
|
||||
import type { GRANULARITY } from "@/libs/xapi-stats";
|
||||
import { POWER_STATE } from "@/libs/xen-api";
|
||||
import type { XenApiHost, XenApiVm } from "@/libs/xen-api";
|
||||
import {
|
||||
type CollectionSubscription,
|
||||
@@ -40,7 +41,9 @@ export const useVmStore = defineStore("vm", () => {
|
||||
});
|
||||
|
||||
const runningVms = computed(() =>
|
||||
vmSubscription.records.value.filter((vm) => vm.power_state === "Running")
|
||||
vmSubscription.records.value.filter(
|
||||
(vm) => vm.power_state === POWER_STATE.RUNNING
|
||||
)
|
||||
);
|
||||
|
||||
const getStats = (id: string, granularity: GRANULARITY) => {
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
<ComponentStory
|
||||
:params="[
|
||||
prop('state')
|
||||
.enum('Running', 'Suspended', 'Halted', 'Paused')
|
||||
.enum(...Object.values(POWER_STATE))
|
||||
.required()
|
||||
.preset('Running')
|
||||
.preset(POWER_STATE.RUNNING)
|
||||
.widget(),
|
||||
]"
|
||||
v-slot="{ properties }"
|
||||
@@ -17,6 +17,7 @@
|
||||
import PowerStateIcon from "@/components/PowerStateIcon.vue";
|
||||
import ComponentStory from "@/components/component-story/ComponentStory.vue";
|
||||
import { prop } from "@/libs/story/story-param";
|
||||
import { POWER_STATE } from "@/libs/xen-api";
|
||||
</script>
|
||||
|
||||
<style lang="postcss" scoped></style>
|
||||
|
||||
@@ -37,6 +37,7 @@ import PowerStateIcon from "@/components/PowerStateIcon.vue";
|
||||
import UiCard from "@/components/ui/UiCard.vue";
|
||||
import UiCardTitle from "@/components/ui/UiCardTitle.vue";
|
||||
import VmsActionsBar from "@/components/vm/VmsActionsBar.vue";
|
||||
import { POWER_STATE } from "@/libs/xen-api";
|
||||
import { useUiStore } from "@/stores/ui.store";
|
||||
import { useVmStore } from "@/stores/vm.store";
|
||||
import type { Filters } from "@/types/filter";
|
||||
@@ -56,7 +57,7 @@ const filters: Filters = {
|
||||
label: t("power-state"),
|
||||
icon: faPowerOff,
|
||||
type: "enum",
|
||||
choices: ["Running", "Halted", "Paused", "Suspended"],
|
||||
choices: Object.values(POWER_STATE),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { POWER_STATE, VM_OPERATION } from "@/libs/xen-api";
|
||||
import { computed } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import RemoteConsole from "@/components/RemoteConsole.vue";
|
||||
@@ -17,13 +18,13 @@ import { useVmStore } from "@/stores/vm.store";
|
||||
import { isOperationsPending } from "@/libs/utils";
|
||||
|
||||
const STOP_OPERATIONS = [
|
||||
"shutdown",
|
||||
"clean_shutdown",
|
||||
"hard_shutdown",
|
||||
"clean_reboot",
|
||||
"hard_reboot",
|
||||
"pause",
|
||||
"suspend",
|
||||
VM_OPERATION.SHUTDOWN,
|
||||
VM_OPERATION.CLEAN_SHUTDOWN,
|
||||
VM_OPERATION.HARD_SHUTDOWN,
|
||||
VM_OPERATION.CLEAN_REBOOT,
|
||||
VM_OPERATION.HARD_REBOOT,
|
||||
VM_OPERATION.PAUSE,
|
||||
VM_OPERATION.SUSPEND,
|
||||
];
|
||||
|
||||
const route = useRoute();
|
||||
@@ -37,7 +38,9 @@ const isReady = computed(() => isVmReady.value && isConsoleReady.value);
|
||||
|
||||
const vm = computed(() => getVmByUuid(route.params.uuid as string));
|
||||
|
||||
const isVmRunning = computed(() => vm.value?.power_state === "Running");
|
||||
const isVmRunning = computed(
|
||||
() => vm.value?.power_state === POWER_STATE.RUNNING
|
||||
);
|
||||
|
||||
const vmConsole = computed(() => {
|
||||
const consoleOpaqueRef = vm.value?.consoles[0];
|
||||
|
||||
Reference in New Issue
Block a user