Skip to content

Commit

Permalink
adding VtsConnectionStatus component and pif metrics store
Browse files Browse the repository at this point in the history
  • Loading branch information
J0ris-K committed Jan 2, 2025
1 parent dcf47d6 commit 2776068
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 49 deletions.
44 changes: 0 additions & 44 deletions @xen-orchestra/lite/src/components/host/network/HostPifStatus.vue

This file was deleted.

25 changes: 20 additions & 5 deletions @xen-orchestra/lite/src/components/host/network/HostPifTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<UiCheckbox v-if="column.id === 'checkbox'" v-model="selected" accent="info" :value="row.id" />
<VtsIcon v-else-if="column.id === 'more'" accent="info" :icon="faEllipsis" />
<div v-else-if="column.id === 'status'" v-tooltip>
<HostPifStatus class="status" :pif-status="column.value" />
<VtsConnectionStatus :status="column.value" />
</div>
<div v-else-if="column.id === 'network'" class="network">
<UiComplexIcon size="medium" class="icon">
Expand Down Expand Up @@ -94,11 +94,12 @@
</template>

<script lang="ts" setup>
import HostPifStatus from '@/components/host/network/HostPifStatus.vue'
import UiCardSpinner from '@/components/ui/UiCardSpinner.vue'
import useMultiSelect from '@/composables/multi-select.composable'
import type { XenApiNetwork, XenApiPif } from '@/libs/xen-api/xen-api.types'
import { useNetworkStore } from '@/stores/xen-api/network.store'
import { usePifMetricsStore } from '@/stores/xen-api/pif-metrics.store'
import VtsConnectionStatus from '@core/components/connection-status/VtsConnectionStatus.vue'
import VtsIcon from '@core/components/icon/VtsIcon.vue'
import ColumnTitle from '@core/components/table/ColumnTitle.vue'
import VtsTable from '@core/components/table/VtsTable.vue'
Expand Down Expand Up @@ -137,16 +138,30 @@ const { pifs } = defineProps<{
const { t } = useI18n()
const { getByOpaqueRef } = useNetworkStore().subscribe()
const { getPifCarrier } = usePifMetricsStore().subscribe()
const getNetworkName = (pif: string) => {
const network: XenApiNetwork = getByOpaqueRef(pif as XenApiNetwork['$ref'])!
const getNetworkName = (networkRef: string) => {
const network: XenApiNetwork = getByOpaqueRef(networkRef as XenApiNetwork['$ref'])!
return network?.name_label ? network.name_label : ''
}
const getVlanData = (vlan: number) => {
return vlan !== -1 ? vlan : t('none')
}
const getPifStatus = (pif: XenApiPif) => {
const carrier = getPifCarrier(pif)
const currentlyAttached = pif.currently_attached
if (currentlyAttached && carrier) {
return 'connected'
}
if (currentlyAttached && !carrier) {
return 'partially-connected'
}
return 'disconnected'
}
const searchQuery = ref('')
const filteredNetworks = computed(() => {
Expand All @@ -171,7 +186,7 @@ const { visibleColumns, rows } = useTable('pifs', filteredNetworks, {
define('checkbox', () => '', { label: '', isHideable: false }),
define('network', record => getNetworkName(record.network), { label: 'Network', isHideable: true }),
define('device', { label: 'Device', isHideable: true }),
define('status', record => record.currently_attached, { label: 'Status', isHideable: true }),
define('status', record => getPifStatus(record), { label: 'Status', isHideable: true }),
define('VLAN', record => getVlanData(record.VLAN), { label: 'Vlan', isHideable: true }),
define('IP', { label: 'IP', isHideable: true }),
define('MAC', { label: 'MAC', isHideable: true }),
Expand Down
20 changes: 20 additions & 0 deletions @xen-orchestra/lite/src/stores/xen-api/pif-metrics.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { XenApiPif } from '@/libs/xen-api/xen-api.types'
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 usePifMetricsStore = defineStore('xen-api-pif-metrics', () => {
const { context: baseContext, ...configRest } = createXapiStoreConfig('pif_metrics')

const getPifCarrier = (pif: XenApiPif) => {
const pifMetrics = baseContext.getByOpaqueRef(pif.metrics)
return pifMetrics.carrier
}

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

return createSubscribableStoreContext({ context, ...configRest }, {})
})

0 comments on commit 2776068

Please sign in to comment.