Skip to content

Commit

Permalink
feat(xo-lite): add more info in side panel, persistent selected on ta…
Browse files Browse the repository at this point in the history
…ble row and improve store
  • Loading branch information
J0ris-K committed Nov 26, 2024
1 parent b24aac6 commit 763101a
Show file tree
Hide file tree
Showing 5 changed files with 283 additions and 133 deletions.
1 change: 1 addition & 0 deletions @xen-orchestra/lite/src/libs/xen-api/xen-api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type ObjectTypeToRecordMapping = {
host_metrics: XenApiHostMetrics
message: XenApiMessage<any>
network: XenApiNetwork
pif: XenApiPif
pool: XenApiPool
sr: XenApiSr
vm: XenApiVm
Expand Down
3 changes: 3 additions & 0 deletions @xen-orchestra/lite/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"gzip": "gzip",
"here": "Here",

"host": "Host",

Check failure on line 111 in @xen-orchestra/lite/src/locales/en.json

View workflow job for this annotation

GitHub Actions / CI

duplicate key 'host' in 'en'. "./@xen-orchestra/web/src/locales/en.json" has the same key
"host.active": "Active",
"host.inactive": "Inactive",

Expand Down Expand Up @@ -147,6 +148,8 @@
"no-tasks": "No tasks",
"not-found": "Not found",
"object": "Object",
"off": "Off",
"on": "On",
"ok": "OK",
"on-object": "on {object}",
"or": "Or",
Expand Down
3 changes: 3 additions & 0 deletions @xen-orchestra/lite/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"gzip": "gzip",
"here": "Ici",

"host": "Hôte",

Check failure on line 111 in @xen-orchestra/lite/src/locales/fr.json

View workflow job for this annotation

GitHub Actions / CI

duplicate key 'host' in 'fr'. "./@xen-orchestra/web/src/locales/fr.json" has the same key
"host.active": "Actif | Actif | Actifs",
"host.inactive": "Inactif | Inactif | Inactifs",

Expand Down Expand Up @@ -147,6 +148,8 @@
"no-tasks": "Aucune tâche",
"not-found": "Non trouvé",
"object": "Objet",
"off": "Eteint",
"on": "Allumé",
"ok": "OK",
"on-object": "sur {object}",
"or": "Ou",
Expand Down
117 changes: 92 additions & 25 deletions @xen-orchestra/lite/src/stores/xen-api/network.store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { XenApiNetwork, XenApiPif } from '@/libs/xen-api/xen-api.types'
import { createXapiStoreConfig } from '@/stores/xen-api/create-xapi-store-config'
import { useHostMetricsStore } from '@/stores/xen-api/host-metrics.store'
import { useHostStore } from '@/stores/xen-api/host.store'
import { usePifStore } from '@/stores/xen-api/pif.store'
import { usePoolStore } from '@/stores/xen-api/pool.store'
Expand All @@ -13,6 +14,7 @@ export const useNetworkStore = defineStore('xen-api-network', () => {
poolStore: usePoolStore(),
hostStore: useHostStore(),
pifStore: usePifStore(),
metricsStore: useHostMetricsStore(),
}

const { context: baseContext, ...configRest } = createXapiStoreConfig('network', {
Expand All @@ -22,66 +24,131 @@ export const useNetworkStore = defineStore('xen-api-network', () => {
const poolContext = deps.poolStore.getContext()
const hostContext = deps.hostStore.getContext()
const pifContext = deps.pifStore.getContext()
const metricsContext = deps.metricsStore.getContext()

const PIFsByNetwork = computed(() => {
const PIFsByNetworkMap = new Map<string, XenApiPif[]>()

poolContext.records.value.forEach(pool => {
const masterPoolRef = pool.master
const currentHostRef = hostContext.records.value.find(host => host.$ref === masterPoolRef)
if (currentHostRef) {
pifContext.records.value
.filter(pif => pif.host === masterPoolRef)
.forEach(pif => {
if (!PIFsByNetworkMap.has(pif.network)) {
PIFsByNetworkMap.set(pif.network, [])
}
PIFsByNetworkMap.get(pif.network)?.push(pif)
})
}
})
const poolMasterRef = poolContext.pool.value?.master

const currentHostRef = hostContext.records.value.find(host => host.$ref === poolMasterRef)
if (currentHostRef) {
pifContext.records.value
.filter(pif => pif.host === poolMasterRef)
.forEach(pif => {
if (!PIFsByNetworkMap.has(pif.network)) {
PIFsByNetworkMap.set(pif.network, [])
}
PIFsByNetworkMap.get(pif.network)?.push(pif)
})
}

return PIFsByNetworkMap
})

const determineStatus = (PIFs: XenApiPif[]): string => {
if (PIFs.length === 0) {
return 'disconnected'
}
const currentlyAttached = PIFs.map(PIF => PIF.currently_attached)
if (currentlyAttached.every(attached => attached)) {

if (currentlyAttached.every(Boolean)) {
return 'connected'
} else if (currentlyAttached.some(attached => attached)) {
}

if (currentlyAttached.some(Boolean)) {
return 'partially connected'
}

return 'disconnected'
}

const networksWithVLANs = computed(() => {
const networksInfoMap = new Map<
string,
{ network: XenApiNetwork; vlan: string; status: string; selected: boolean }
>()

return baseContext.records.value
.filter(network => network.PIFs.length > 0)
.map(network => {
const relatedPifs = PIFsByNetwork.value.get(network.$ref) || []
const vlan = relatedPifs.length > 0 ? (relatedPifs[0].VLAN === -1 ? 'None' : relatedPifs[0].VLAN) : ''

const vlan =
relatedPifs.length > 0 ? (relatedPifs[0].VLAN === -1 ? 'None' : relatedPifs[0].VLAN.toString()) : ''

const status = determineStatus(relatedPifs)

return {
...network,
const networkWithDetails = {
network,
selected: false,
vlan,
status,
}
if (!networksInfoMap.has(network.$ref)) {
networksInfoMap.set(network.$ref, networkWithDetails)
}
networksInfoMap.set(network.$ref, networkWithDetails)

return networkWithDetails
})
})

const hostPrivateNetworks = computed(() => {
const hostPrivateNetworksInfoMap = new Map<string, { network: XenApiNetwork; selected: boolean }>()

return baseContext.records.value
.filter(network => network.PIFs.length === 0) // Only networks without PIFs
.map(network => ({
...network,
selected: false,
}))
.map(network => {
const hostPrivateNetworkWithDetails = {
network,
selected: false,
}

if (!hostPrivateNetworksInfoMap.has(network.$ref)) {
hostPrivateNetworksInfoMap.set(network.$ref, hostPrivateNetworkWithDetails)
}
hostPrivateNetworksInfoMap.set(network.$ref, hostPrivateNetworkWithDetails)

return hostPrivateNetworkWithDetails
})
})

const PIFsInfoByNetwork = computed(() => {
const PIFsInfoMap = new Map<
string,
{
PIF: XenApiPif
host?: {
name_label?: string
status?: boolean
}
}[]
>()

pifContext.records.value.forEach(PIF => {
const hostInfo = hostContext.getByOpaqueRef(PIF.host)
const hostStatus = hostInfo?.metrics ? metricsContext.getByOpaqueRef(hostInfo.metrics)?.live || false : false

const enrichedPIF = {
PIF,
host: {
name_label: hostInfo?.name_label,
hostStatus,
},
}

if (!PIFsInfoMap.has(PIF.network)) {
PIFsInfoMap.set(PIF.network, [])
}
PIFsInfoMap.get(PIF.network)?.push(enrichedPIF)
})

return PIFsInfoMap
})

const getPIFsInformationByNetwork = (network: XenApiNetwork) => {
const PIFsOpaqueRefNetwork = network.PIFs
return PIFsOpaqueRefNetwork.map(ref => pifContext.records.value.find(pif => pif.$ref === ref)).filter(pif => !!pif)
return PIFsInfoByNetwork.value.get(network?.$ref) || []
}

const context = {
Expand Down
Loading

0 comments on commit 763101a

Please sign in to comment.