From 7f3d25964f2482e96c9d0404c2d273833c6d7106 Mon Sep 17 00:00:00 2001 From: Mathieu <70369997+MathieuRA@users.noreply.github.com> Date: Mon, 3 Oct 2022 17:20:44 +0200 Subject: [PATCH] feat(lite): display storage usage (#6421) --- .../dashboard/PoolDashboardStorageUsage.vue | 103 ++++++++++++++++++ @xen-orchestra/lite/src/libs/utils.ts | 7 ++ @xen-orchestra/lite/src/libs/xen-api.ts | 6 + @xen-orchestra/lite/src/locales/en.json | 2 + @xen-orchestra/lite/src/locales/fr.json | 2 + .../lite/src/stores/storage.store.ts | 7 ++ .../lite/src/stores/xen-api.store.ts | 3 + .../lite/src/types/human-format.d.ts | 15 ++- .../lite/src/views/pool/PoolDashboardView.vue | 2 + 9 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 @xen-orchestra/lite/src/components/pool/dashboard/PoolDashboardStorageUsage.vue create mode 100644 @xen-orchestra/lite/src/stores/storage.store.ts diff --git a/@xen-orchestra/lite/src/components/pool/dashboard/PoolDashboardStorageUsage.vue b/@xen-orchestra/lite/src/components/pool/dashboard/PoolDashboardStorageUsage.vue new file mode 100644 index 000000000..c292fd8cf --- /dev/null +++ b/@xen-orchestra/lite/src/components/pool/dashboard/PoolDashboardStorageUsage.vue @@ -0,0 +1,103 @@ + + + + + diff --git a/@xen-orchestra/lite/src/libs/utils.ts b/@xen-orchestra/lite/src/libs/utils.ts index d2e2c3e3e..1c384aa94 100644 --- a/@xen-orchestra/lite/src/libs/utils.ts +++ b/@xen-orchestra/lite/src/libs/utils.ts @@ -1,4 +1,5 @@ import { utcParse } from "d3-time-format"; +import humanFormat from "human-format"; import { round } from "lodash-es"; import type { Filter } from "@/types/filter"; import { faSquareCheck } from "@fortawesome/free-regular-svg-icons"; @@ -32,6 +33,12 @@ const iconsByType = { enum: faList, }; +export function formatSize(bytes: number) { + return bytes != null + ? humanFormat(bytes, { scale: "binary", unit: "B" }) + : "N/D"; +} + export function getFilterIcon(filter: Filter | undefined) { if (!filter) { return; diff --git a/@xen-orchestra/lite/src/libs/xen-api.ts b/@xen-orchestra/lite/src/libs/xen-api.ts index 9cd2cb30d..bc5550b73 100644 --- a/@xen-orchestra/lite/src/libs/xen-api.ts +++ b/@xen-orchestra/lite/src/libs/xen-api.ts @@ -79,6 +79,12 @@ export interface XenApiHost extends XenApiRecord { resident_VMs: string[]; } +export interface XenApiSr extends XenApiRecord { + name_label: string; + physical_size: number; + physical_utilisation: number; +} + export interface XenApiVm extends XenApiRecord { name_label: string; name_description: string; diff --git a/@xen-orchestra/lite/src/locales/en.json b/@xen-orchestra/lite/src/locales/en.json index ff1d35b55..37c463fb2 100644 --- a/@xen-orchestra/lite/src/locales/en.json +++ b/@xen-orchestra/lite/src/locales/en.json @@ -33,9 +33,11 @@ "stats": "Stats", "status": "Status", "storage": "Storage", + "storage-usage": "Storage usage", "switch-theme": "Switch theme", "system": "System", "tasks": "Tasks", + "top-#": "Top {n}", "total-free": "Total free", "total-used": "Total used", "vms": "VMs" diff --git a/@xen-orchestra/lite/src/locales/fr.json b/@xen-orchestra/lite/src/locales/fr.json index 885e2b5d0..b7afc0009 100644 --- a/@xen-orchestra/lite/src/locales/fr.json +++ b/@xen-orchestra/lite/src/locales/fr.json @@ -33,9 +33,11 @@ "stats": "Stats", "status": "Statut", "storage": "Stockage", + "storage-usage": "Utilisation du stockage", "switch-theme": "Changer de thème", "system": "Système", "tasks": "Tâches", + "top-#": "Top {n}", "total-free": "Total libre", "total-used": "Total utilisé", "vms": "VMs" diff --git a/@xen-orchestra/lite/src/stores/storage.store.ts b/@xen-orchestra/lite/src/stores/storage.store.ts new file mode 100644 index 000000000..93090cc51 --- /dev/null +++ b/@xen-orchestra/lite/src/stores/storage.store.ts @@ -0,0 +1,7 @@ +import { defineStore } from "pinia"; +import type { XenApiSr } from "@/libs/xen-api"; +import { createRecordContext } from "@/stores/index"; + +export const useSrStore = defineStore("SR", () => + createRecordContext("SR") +); diff --git a/@xen-orchestra/lite/src/stores/xen-api.store.ts b/@xen-orchestra/lite/src/stores/xen-api.store.ts index bff7bfc85..f924948e2 100644 --- a/@xen-orchestra/lite/src/stores/xen-api.store.ts +++ b/@xen-orchestra/lite/src/stores/xen-api.store.ts @@ -9,6 +9,7 @@ import { useHostMetricsStore } from "@/stores/host-metrics.store"; import { useHostStore } from "@/stores/host.store"; import { usePoolStore } from "@/stores/pool.store"; import { useRecordsStore } from "@/stores/records.store"; +import { useSrStore } from "@/stores/storage.store"; import { useVmGuestMetricsStore } from "@/stores/vm-guest-metrics.store"; import { useVmMetricsStore } from "@/stores/vm-metrics.store"; import { useVmStore } from "@/stores/vm.store"; @@ -76,11 +77,13 @@ export const useXenApiStore = defineStore("xen-api", () => { const hostMetricsStore = useHostMetricsStore(); const vmMetricsStore = useVmMetricsStore(); const vmGuestMetricsStore = useVmGuestMetricsStore(); + const srStore = useSrStore(); await Promise.all([ hostMetricsStore.init(), vmMetricsStore.init(), vmGuestMetricsStore.init(), + srStore.init(), ]); const consoleStore = useConsoleStore(); diff --git a/@xen-orchestra/lite/src/types/human-format.d.ts b/@xen-orchestra/lite/src/types/human-format.d.ts index c31014d4d..aee2c7466 100644 --- a/@xen-orchestra/lite/src/types/human-format.d.ts +++ b/@xen-orchestra/lite/src/types/human-format.d.ts @@ -1,3 +1,16 @@ declare module "human-format" { - function bytes(value: number): string; + type Options = { + decimals?: number; + maxDecimals?: number; + prefix?: string; + scale?: string; + separator?: string; + unit?: string; + }; + + function humanFormat(value: number, opts?: Options): number; + function bytes(value: number): number; + + humanFormat.bytes = bytes; + export default humanFormat; } diff --git a/@xen-orchestra/lite/src/views/pool/PoolDashboardView.vue b/@xen-orchestra/lite/src/views/pool/PoolDashboardView.vue index d9f58bd4e..98c8ca08a 100644 --- a/@xen-orchestra/lite/src/views/pool/PoolDashboardView.vue +++ b/@xen-orchestra/lite/src/views/pool/PoolDashboardView.vue @@ -1,11 +1,13 @@