mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-04 22:21:36 +09:00
F OpenNebula/one#5422: Add vnets table
This commit is contained in:
9 files changed
+307
-3
No files matched your search
@@ -44,7 +44,7 @@ const Images = loadable(() => import('client/containers/Images'), { ssr: false }
|
||||
const Marketplaces = loadable(() => import('client/containers/Marketplaces'), { ssr: false })
|
||||
const MarketplaceApps = loadable(() => import('client/containers/MarketplaceApps'), { ssr: false })
|
||||
|
||||
// const VirtualNetworks = loadable(() => import('client/containers/VirtualNetworks'), { ssr: false })
|
||||
const VirtualNetworks = loadable(() => import('client/containers/VirtualNetworks'), { ssr: false })
|
||||
// const NetworkTemplates = loadable(() => import('client/containers/NetworkTemplates'), { ssr: false })
|
||||
// const NetworkTopologies = loadable(() => import('client/containers/NetworkTopologies'), { ssr: false })
|
||||
// const SecurityGroups = loadable(() => import('client/containers/SecurityGroups'), { ssr: false })
|
||||
@@ -188,6 +188,20 @@ export const ENDPOINTS = [
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Networks',
|
||||
sidebar: true,
|
||||
icon: NetworkIcon,
|
||||
routes: [
|
||||
{
|
||||
label: 'Virtual Networks',
|
||||
path: PATH.NETWORK.VNETS.LIST,
|
||||
sidebar: true,
|
||||
icon: NetworkIcon,
|
||||
Component: VirtualNetworks
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
label: 'Infrastructure',
|
||||
sidebar: true,
|
||||
|
||||
@@ -28,7 +28,7 @@ const Row = ({ original, value, ...props }) => {
|
||||
<Folder size={16} />
|
||||
<span>{` ${DATASTORES}`}</span>
|
||||
</span>
|
||||
<span title={`Total VNets: ${VNETS}`}>
|
||||
<span title={`Total Virtual Networks: ${VNETS}`}>
|
||||
<NetworkAlt size={16} />
|
||||
<span>{` ${VNETS}`}</span>
|
||||
</span>
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { Cancel, Minus, Plus } from 'iconoir-react'
|
||||
import { List, ListSubheader, IconButton } from '@material-ui/core'
|
||||
import { TreeView, TreeItem } from '@material-ui/lab'
|
||||
|
||||
import { Tr } from 'client/components/HOC'
|
||||
|
||||
const buildTree = (data = [], separator = '/') => {
|
||||
const mapper = {}
|
||||
const tree = {
|
||||
id: 'root',
|
||||
name: 'Labels',
|
||||
children: []
|
||||
}
|
||||
|
||||
for (const labelString of data) {
|
||||
const splits = labelString.split(separator)
|
||||
let label = ''
|
||||
|
||||
splits.reduce((parent, place) => {
|
||||
if (label) {
|
||||
label += `${separator}${place}`
|
||||
} else {
|
||||
label = place
|
||||
}
|
||||
|
||||
if (place && !mapper[label]) {
|
||||
const o = { id: label }
|
||||
mapper[label] = o
|
||||
mapper[label].name = place
|
||||
parent.children = parent.children || []
|
||||
parent.children.push(o)
|
||||
}
|
||||
|
||||
return mapper[label]
|
||||
}, tree)
|
||||
}
|
||||
|
||||
return tree
|
||||
}
|
||||
|
||||
const LabelFilter = ({ title, column }) => {
|
||||
/** @type {import('react-table').UseFiltersInstanceProps} */
|
||||
const { setFilter, id, preFilteredRows, filterValue = [] } = column
|
||||
|
||||
React.useEffect(() => () => setFilter([]), [])
|
||||
|
||||
const labels = React.useMemo(() => {
|
||||
const labels = new Set()
|
||||
|
||||
preFilteredRows?.forEach(row => {
|
||||
const labelsFromTemplate = row.values[id]
|
||||
|
||||
labelsFromTemplate.forEach(labels.add, labels)
|
||||
})
|
||||
|
||||
return [...labels.values()]
|
||||
}, [id, preFilteredRows])
|
||||
|
||||
const tree = React.useMemo(() => buildTree(labels), [labels])
|
||||
|
||||
const handleSelect = value =>
|
||||
setFilter([...filterValue, value])
|
||||
|
||||
const handleUnselect = value =>
|
||||
setFilter(filterValue.filter(v => v !== value))
|
||||
|
||||
const handleClear = () => setFilter(undefined)
|
||||
|
||||
const isFiltered = React.useMemo(() => (
|
||||
filterValue?.length > 0
|
||||
), [filterValue])
|
||||
|
||||
const renderTree = ({ id, name, children }) => (
|
||||
<TreeItem key={id} nodeId={id} label={name}>
|
||||
{Array.isArray(children)
|
||||
? children.map(node => renderTree(node)) : null}
|
||||
</TreeItem>
|
||||
)
|
||||
|
||||
console.log({ filterValue })
|
||||
|
||||
return (
|
||||
<List dense disablePadding>
|
||||
{title && (
|
||||
<ListSubheader disableSticky disableGutters
|
||||
title={Tr(title)}
|
||||
style={{ display: 'flex', alignItems: 'center' }}
|
||||
>
|
||||
{Tr(title)}
|
||||
{isFiltered && (
|
||||
<IconButton disableRipple disablePadding size='small' onClick={handleClear}>
|
||||
<Cancel/>
|
||||
</IconButton>
|
||||
)}
|
||||
</ListSubheader>
|
||||
)}
|
||||
|
||||
<TreeView
|
||||
selected={filterValue}
|
||||
defaultExpanded={['root', ...labels]}
|
||||
onNodeSelect={(evt, value) => {
|
||||
evt.preventDefault()
|
||||
|
||||
filterValue.includes?.(value)
|
||||
? handleUnselect(value)
|
||||
: handleSelect(value)
|
||||
}}
|
||||
>
|
||||
{renderTree(tree)}
|
||||
</TreeView>
|
||||
</List>
|
||||
)
|
||||
}
|
||||
|
||||
LabelFilter.propTypes = {
|
||||
column: PropTypes.object,
|
||||
icon: PropTypes.node,
|
||||
title: PropTypes.string
|
||||
}
|
||||
|
||||
export default LabelFilter
|
||||
@@ -0,0 +1,25 @@
|
||||
import * as VirtualNetworkModel from 'client/models/VirtualNetwork'
|
||||
|
||||
const getTotalOfResources = resources => [resources?.ID ?? []].flat().length || 0
|
||||
|
||||
export default [
|
||||
{ Header: 'ID', accessor: 'ID', sortType: 'number' },
|
||||
{ Header: 'Name', accessor: 'NAME' },
|
||||
{ Header: 'Owner', accessor: 'UNAME' },
|
||||
{ Header: 'Group', accessor: 'GNAME' },
|
||||
{ Header: 'Locked', accessor: 'LOCK' },
|
||||
{
|
||||
Header: 'Total Clusters',
|
||||
id: 'CLUSTERS',
|
||||
accessor: row => getTotalOfResources(row?.CLUSTERS),
|
||||
sortType: 'number'
|
||||
},
|
||||
{ Header: 'Used Leases', accessor: 'USED_LEASES', sortType: 'number' },
|
||||
{
|
||||
Header: 'Total Leases',
|
||||
id: 'TOTAL_LEASES',
|
||||
accessor: row => VirtualNetworkModel.getTotalLeases(row),
|
||||
sortType: 'number'
|
||||
}
|
||||
|
||||
]
|
||||
@@ -0,0 +1,36 @@
|
||||
import React, { useEffect } from 'react'
|
||||
|
||||
import { useFetch } from 'client/hooks'
|
||||
import { useVNetwork, useVNetworkApi } from 'client/features/One'
|
||||
|
||||
import { SkeletonTable, EnhancedTable } from 'client/components/Tables'
|
||||
import VNetworkColumns from 'client/components/Tables/VNetworks/columns'
|
||||
import VNetworkRow from 'client/components/Tables/VNetworks/row'
|
||||
|
||||
const VNetworksTable = () => {
|
||||
const columns = React.useMemo(() => VNetworkColumns, [])
|
||||
|
||||
const vNetworks = useVNetwork()
|
||||
const { getVNetworks } = useVNetworkApi()
|
||||
|
||||
const { status, fetchRequest, loading, reloading, STATUS } = useFetch(getVNetworks)
|
||||
const { INIT, PENDING } = STATUS
|
||||
|
||||
useEffect(() => { fetchRequest() }, [])
|
||||
|
||||
if (vNetworks?.length === 0 && [INIT, PENDING].includes(status)) {
|
||||
return <SkeletonTable />
|
||||
}
|
||||
|
||||
return (
|
||||
<EnhancedTable
|
||||
columns={columns}
|
||||
data={vNetworks}
|
||||
isLoading={loading || reloading}
|
||||
getRowId={row => String(row.ID)}
|
||||
RowComponent={VNetworkRow}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default VNetworksTable
|
||||
@@ -0,0 +1,68 @@
|
||||
import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { User, Group, Lock, Server, NetworkAlt } from 'iconoir-react'
|
||||
import { Typography } from '@material-ui/core'
|
||||
|
||||
import { LinearProgressWithLabel } from 'client/components/Status'
|
||||
import { rowStyles } from 'client/components/Tables/styles'
|
||||
|
||||
import * as VirtualNetworkModel from 'client/models/VirtualNetwork'
|
||||
|
||||
const Row = ({ original, value, ...props }) => {
|
||||
const classes = rowStyles()
|
||||
const {
|
||||
ID, NAME, UNAME, GNAME, LOCK,
|
||||
CLUSTERS, USED_LEASES, TOTAL_LEASES
|
||||
} = value
|
||||
|
||||
const { percentOfUsed, percentLabel } = VirtualNetworkModel.getLeasesInfo(original)
|
||||
|
||||
return (
|
||||
<div {...props}>
|
||||
<div className={classes.main}>
|
||||
<div className={classes.title}>
|
||||
<Typography className={classes.titleText} component='span'>
|
||||
{NAME}
|
||||
</Typography>
|
||||
<span className={classes.labels}>
|
||||
{LOCK && <Lock size={20} />}
|
||||
</span>
|
||||
</div>
|
||||
<div className={classes.caption}>
|
||||
<span>
|
||||
{`#${ID}`}
|
||||
</span>
|
||||
<span title={`Owner: ${UNAME}`}>
|
||||
<User size={16} />
|
||||
<span>{` ${UNAME}`}</span>
|
||||
</span>
|
||||
<span title={`Group: ${GNAME}`}>
|
||||
<Group size={16} />
|
||||
<span>{` ${GNAME}`}</span>
|
||||
</span>
|
||||
<span title={`Total Clusters: ${CLUSTERS}`}>
|
||||
<Server size={16} />
|
||||
<span>{` ${CLUSTERS}`}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className={classes.secondary}>
|
||||
<LinearProgressWithLabel
|
||||
title={`Used / Total Leases: ${USED_LEASES} / ${TOTAL_LEASES}`}
|
||||
value={percentOfUsed}
|
||||
label={percentLabel}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Row.propTypes = {
|
||||
original: PropTypes.object,
|
||||
value: PropTypes.object,
|
||||
isSelected: PropTypes.bool,
|
||||
handleClick: PropTypes.func
|
||||
}
|
||||
|
||||
export default Row
|
||||
@@ -11,6 +11,7 @@ import UsersTable from 'client/components/Tables/Users'
|
||||
import VirtualizedTable from 'client/components/Tables/Virtualized'
|
||||
import VmsTable from 'client/components/Tables/Vms'
|
||||
import VmTemplatesTable from 'client/components/Tables/VmTemplates'
|
||||
import VNetworksTable from 'client/components/Tables/VNetworks'
|
||||
|
||||
export {
|
||||
SkeletonTable,
|
||||
@@ -26,5 +27,6 @@ export {
|
||||
MarketplacesTable,
|
||||
UsersTable,
|
||||
VmsTable,
|
||||
VmTemplatesTable
|
||||
VmTemplatesTable,
|
||||
VNetworksTable
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import { Container, Box } from '@material-ui/core'
|
||||
|
||||
import * as Tables from 'client/components/Tables'
|
||||
|
||||
function VirtualMachines () {
|
||||
return (
|
||||
<Box
|
||||
height={1}
|
||||
py={2}
|
||||
overflow='auto'
|
||||
display='flex'
|
||||
flexDirection='column'
|
||||
component={Container}
|
||||
>
|
||||
<Tables.VNetworksTable />
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
export default VirtualMachines
|
||||
@@ -0,0 +1,13 @@
|
||||
export const getTotalLeases = ({ AR_POOL } = {}) => {
|
||||
const addressRanges = [AR_POOL?.AR ?? []].flat()
|
||||
|
||||
return addressRanges.reduce((total, { SIZE = 0 }) => total + (+SIZE), 0)
|
||||
}
|
||||
|
||||
export const getLeasesInfo = ({ USED_LEASES, ...virtualNetwork } = {}) => {
|
||||
const totalLeases = getTotalLeases(virtualNetwork)
|
||||
const percentOfUsed = +USED_LEASES * 100 / +totalLeases || 0
|
||||
const percentLabel = `${USED_LEASES} / ${totalLeases} (${Math.round(percentOfUsed)}%)`
|
||||
|
||||
return { percentOfUsed, percentLabel }
|
||||
}
|
||||
Reference in new issue
Block a user