Skip to content

Commit

Permalink
add sr and vdi stores
Browse files Browse the repository at this point in the history
  • Loading branch information
J0ris-K committed Jan 8, 2025
1 parent a68d7f9 commit f1b000c
Show file tree
Hide file tree
Showing 7 changed files with 324 additions and 31 deletions.
4 changes: 3 additions & 1 deletion @xen-orchestra/lite/src/libs/xen-api/xen-api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import type {
VTPM_OPERATION,
VUSB_OPERATION,
} from '@/libs/xen-api/xen-api.enums'
import type { XEN_API_OBJECT_TYPES } from '@/libs/xen-api/xen-api.utils'
import type {XEN_API_OBJECT_TYPES} from '@/libs/xen-api/xen-api.utils'

type TypeMapping = typeof XEN_API_OBJECT_TYPES
export type ObjectType = keyof TypeMapping
Expand Down Expand Up @@ -118,9 +118,11 @@ export interface XenApiHost extends XenApiRecord<'host'> {
export interface XenApiSr extends XenApiRecord<'sr'> {
content_type: string
name_label: string
VDIs: XenApiVdi['$ref'][]
physical_size: number
physical_utilisation: number
shared: boolean
type: string
sm_config: {
type?: string
}
Expand Down
18 changes: 18 additions & 0 deletions @xen-orchestra/lite/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,27 @@
"new-vm.add": "Add new VM",
"new-vm.create": "Create VM",
"new-vm.template": "Template",
"new-vm.pick-template": "Pick a template from your list",
"new-vm.install-settings": "Install settings",
"new-vm.interfaces": "Interfaces",
"new-vm.mac-addresses": "Mac addresses",
"new-vm.storage-repositories": "Storage repositories (SR)",
"new-vm.disk-name": "Disk name",
"new-vm.size": "Size",
"new-vm.description": "Description",
"new-vm.network": "Network",
"new-vm.storage": "Storage",
"new-vm.settings": "Settings",
"new-vm.summary": "Summary",
"new-vm.iso-dvd": "ISO/DVD",
"new-vm.boot-vm": "Boot VM after creation",
"new-vm.auto-power": "Auto power-on",
"new-vm.fast-clone": "Fast clone",
"new-vm.pxe": "PXE",
"new-vm.ram": "Ram",
"new-vm.new": "New",
"new-vm.typology": "Typology",
"new-vm.vcpu": "Vcpu",
"new-vm.no-config": "No config",
"new-vm.user-config": "User configuration",
"new-vm.network-config": "Network configuration",
Expand Down
4 changes: 4 additions & 0 deletions @xen-orchestra/lite/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@

"new-vm": "Nouvelle VM",
"new-vm.add": "Ajouter une nouvelle VM",
"new-vm.pick-template": "Choisissez un modèle dans votre liste",
"new-vm.ram": "Ram",
"new-vm.typology": "Typologie",
"new-vm.vcpu": "Vcpu",
"new-vm.create": "Créer une VM",
"new-vm.template": "Modèle",
"new-vm.install-settings": "Paramètres d'installation",
Expand Down
42 changes: 40 additions & 2 deletions @xen-orchestra/lite/src/stores/xen-api/sr.store.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
import type { XenApiSr } from '@/libs/xen-api/xen-api.types'
import { createXapiStoreConfig } from '@/stores/xen-api/create-xapi-store-config'
import { useVdiStore } from '@/stores/xen-api/vdi.store'
import { createSubscribableStoreContext } from '@core/utils/create-subscribable-store-context.util'
import { defineStore } from 'pinia'
import { computed } from 'vue'

export const useSrStore = defineStore('xen-api-sr', () => {
const config = createXapiStoreConfig('sr')
const deps = {
vdiStore: useVdiStore(),
}

return createSubscribableStoreContext(config, {})
const vdiContext = deps.vdiStore.getContext()

const { context: baseContext, ...configRest } = createXapiStoreConfig('sr')

const srs = computed(() => baseContext.records.value)
const srsName = (ref: XenApiSr['$ref']) => baseContext.getByOpaqueRef(ref)?.name_label

const getSrWithISO = computed(() => srs.value.filter(sr => sr.type === 'iso'))

const concatVidsArray = computed(() => getSrWithISO.value.flatMap(sr => sr.VDIs || []))

const vdisGroupedBySrName = computed(() => {
const groupedVdis: Record<string, XenApiSr[]> = {}

concatVidsArray.value.forEach(vdiRef => {
const vdi = vdiContext.getByOpaqueRef(vdiRef)
if (vdi) {
const srName = srsName(vdi.SR) || 'Unknown SR'
if (!groupedVdis[srName]) {
groupedVdis[srName] = []
}
groupedVdis[srName].push(vdi)
}
})

return groupedVdis
})

const context = {
...baseContext,
vdisGroupedBySrName,
}

return createSubscribableStoreContext({ context, ...configRest }, deps)
})
9 changes: 9 additions & 0 deletions @xen-orchestra/lite/src/stores/xen-api/vdi.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createXapiStoreConfig } from '@/stores/xen-api/create-xapi-store-config'
import { createSubscribableStoreContext } from '@core/utils/create-subscribable-store-context.util'
import { defineStore } from 'pinia'

export const useVdiStore = defineStore('xen-api-vdi', () => {
const config = createXapiStoreConfig('vdi')

return createSubscribableStoreContext(config, {})
})
Loading

0 comments on commit f1b000c

Please sign in to comment.