Skip to content

Commit

Permalink
F #5901: Add VmGroup Tab (#2775)
Browse files Browse the repository at this point in the history
  • Loading branch information
vichansson authored Oct 18, 2023
1 parent 3d7c4f4 commit c461d30
Show file tree
Hide file tree
Showing 47 changed files with 4,063 additions and 32 deletions.
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2973,6 +2973,7 @@ FIREEDGE_SUNSTONE_ETC="src/fireedge/etc/sunstone/sunstone-server.conf \

FIREEDGE_SUNSTONE_ETC_VIEW_ADMIN="src/fireedge/etc/sunstone/admin/vm-tab.yaml \
src/fireedge/etc/sunstone/admin/vm-template-tab.yaml \
src/fireedge/etc/sunstone/admin/vm-group-tab.yaml \
src/fireedge/etc/sunstone/admin/marketplace-app-tab.yaml \
src/fireedge/etc/sunstone/admin/vnet-tab.yaml \
src/fireedge/etc/sunstone/admin/image-tab.yaml\
Expand Down
51 changes: 51 additions & 0 deletions src/fireedge/etc/sunstone/admin/vm-group-tab.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
# This file describe the information add actions available in the VM GROUP TEMPLATES tab

# Resource

resource_name: "VM-GROUP"

# Actions - Which buttons are visible to operate over the resource

actions:
create_dialog: true
update_dialog: true
enable: true
disable: true
chgrp: true
chown: true
delete: true

# Filters - List of criteria to filter the resource

filters:
label: true
state: true



# Info Tabs - Which info tabs are used to show extended information

info-tabs:
info:
enabled: true
information_panel:
enabled: true
actions:
rename: true
permissions_panel:
enabled: true
actions:
chmod: true
ownership_panel:
enabled: true
actions:
chown: true
cgrp: true
roles_panel:
enabled: true
roles-affinity_panel:
enabled: true
vms:
enabled: true

46 changes: 44 additions & 2 deletions src/fireedge/src/client/apps/sunstone/routesOne.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
RefreshDouble as BackupIcon,
Server as ClusterIcon,
Db as DatastoreIcon,
Folder as FileIcon,
Archive as FileIcon,
Folder as VmGroupIcon,
Group as GroupIcon,
HardDrive as HostIcon,
BoxIso as ImageIcon,
Expand Down Expand Up @@ -69,6 +70,7 @@ const ServiceDetail = loadable(
const VmTemplates = loadable(() => import('client/containers/VmTemplates'), {
ssr: false,
})

const InstantiateVmTemplate = loadable(
() => import('client/containers/VmTemplates/Instantiate'),
{ ssr: false }
Expand All @@ -82,7 +84,19 @@ const VMTemplateDetail = loadable(
{ ssr: false }
)
// const VrTemplates = loadable(() => import('client/containers/VrTemplates'), { ssr: false })
// const VmGroups = loadable(() => import('client/containers/VmGroups'), { ssr: false })
const VmGroups = loadable(() => import('client/containers/VmGroups'), {
ssr: false,
})

const CreateVmGroup = loadable(
() => import('client/containers/VmGroups/Create'),
{ ssr: false }
)

// const VmGroupDetail = loadable(
// () => import('client/containers/VmGroups/Detail'),
// { ssr: false }
// )

const ServiceTemplates = loadable(
() => import('client/containers/ServiceTemplates'),
Expand Down Expand Up @@ -242,6 +256,12 @@ export const PATH = {
CREATE: `/${RESOURCE_NAMES.VM_TEMPLATE}/create`,
DETAIL: `/${RESOURCE_NAMES.VM_TEMPLATE}/:id`,
},
VMGROUP: {
LIST: `/${RESOURCE_NAMES.VM_GROUP}`,
INSTANTIATE: `/${RESOURCE_NAMES.VM_GROUP}/instantiate`,
CREATE: `/${RESOURCE_NAMES.VM_GROUP}/create`,
DETAIL: `/${RESOURCE_NAMES.VM_GROUP}/:id`,
},
SERVICES: {
LIST: `/${RESOURCE_NAMES.SERVICE_TEMPLATE}`,
DETAIL: `/${RESOURCE_NAMES.SERVICE_TEMPLATE}/:id`,
Expand Down Expand Up @@ -431,6 +451,28 @@ const ENDPOINTS = [
path: PATH.TEMPLATE.SERVICES.DETAIL,
Component: ServiceTemplateDetail,
},
{
title: (_, state) =>
state?.ID !== undefined ? T.UpdateVmGroup : T.CreateVmGroup,
description: (_, state) =>
state?.ID !== undefined && `#${state.ID} ${state.NAME}`,
path: PATH.TEMPLATE.VMGROUP.CREATE,
Component: CreateVmGroup,
},
{
title: T.VMGroups,
path: PATH.TEMPLATE.VMGROUP.LIST,
description: (params) => `#${params?.id}`,
icon: VmGroupIcon,
sidebar: true,
Component: VmGroups,
},
// {
// title: T.VMGroup,
// description: (params) => `#${params?.id}`,
// path: PATH.TEMPLATE.VMGROUP.DETAIL,
// Component: VmGroupDetail,
// },
],
},
{
Expand Down
254 changes: 254 additions & 0 deletions src/fireedge/src/client/components/Cards/VmGroupCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
/* ------------------------------------------------------------------------- *
* Copyright 2002-2023, OpenNebula Project, OpenNebula Systems *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain *
* a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* ------------------------------------------------------------------------- */
import PropTypes from 'prop-types'
import { Component } from 'react'
import { Group, Lock } from 'iconoir-react'
import {
Typography,
Chip,
Box,
Tooltip,
Accordion,
AccordionSummary,
AccordionDetails,
} from '@mui/material'

import { StatusCircle } from 'client/components/Status'
import { getState } from 'client/models/VmGroup'
import { T } from 'client/constants'

/**
* VmGroupCard component to display vmgroup details.
*
* @param {object} props - Component props
* @param {object} props.vmgroup - VmGroup details
* @param {object} props.rootProps - Additional props for the root element
* @returns {Component} VmGroupCard component
*/
const VmGroupCard = ({ vmgroup, rootProps }) => {
const { ID, NAME, GNAME, LOCK, ROLES } = vmgroup
const { color: stateColor, name: stateName } = getState(LOCK)

return (
<Box {...rootProps} sx={{ display: 'flex', p: 2, gap: 2 }}>
<Box
display="flex"
sx={{
width: 250,
display: 'flex',
flexDirection: 'column',
justifyContent: 'space-between',
}}
>
<Box display="flex" alignItems="center">
<StatusCircle color={stateColor} tooltip={stateName} />
<Typography noWrap ml={1}>
{NAME}
</Typography>
{LOCK && (
<Tooltip title="Locked">
<Lock ml={1} />
</Tooltip>
)}
</Box>
<Box
display="flex"
flexDirection="column"
alignItems="flex-start"
mt={2}
>
<Typography variant="caption">{`#${ID}`}</Typography>
<Box display="flex" alignItems="center" mt={1}>
<Tooltip title={`Group: ${GNAME}`}>
<Box display="flex" alignItems="center" mr={2}>
<Group />
<Typography variant="caption" ml={1}>
{GNAME}
</Typography>
</Box>
</Tooltip>
</Box>
</Box>
</Box>
<Box sx={{ flexGrow: 1, mt: 1, zIndex: 998, display: 'flex' }}>
{ROLES?.ROLE && <RolesComponent roles={ROLES.ROLE} />}
</Box>
</Box>
)
}

/**
* RolesComponent to display roles in accordions.
*
* @param {object} props - The props object.
* @param {Array} props.roles - The roles array.
* @returns {Component} Roles component.
*/
const RolesComponent = ({ roles }) => {
const rolesArray = Array.isArray(roles) ? roles : [roles]

const affinedRoles = rolesArray.filter((role) => role?.POLICY === 'AFFINED')
const antiAffinedRoles = rolesArray.filter(
(role) => role?.POLICY === 'ANTI_AFFINED'
)

const renderRoles = (roleList) => (
<Box
sx={{
display: 'flex',
flexDirection: 'column',
flexWrap: 'wrap',
gap: 0.5,
}}
>
{roleList.map((role, index) => {
if (!role?.ID || !role?.NAME) return null

const tooltipContent = (
<div>
<div>ID: {role.ID}</div>
<div>
{T.Name}: {role.NAME}
</div>
{role.HOST_AFFINED && (
<div>
{T.HostAffined}: {role.HOST_AFFINED}
</div>
)}
{role.HOST_ANTI_AFFINED && (
<div>
{T.HostAntiAffined}: {role.HOST_ANTI_AFFINED}
</div>
)}
</div>
)

return (
<Tooltip
key={index}
title={tooltipContent}
arrow
placement={role?.POLICY === 'AFFINED' ? 'left' : 'right'}
>
<Chip
sx={{
margin: 0.5,
opacity: 0.8,
maxWidth: 375,
'& .MuiChip-label': {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
},
}}
label={role.NAME}
/>
</Tooltip>
)
})}
</Box>
)

return (
<Box sx={{ display: 'flex', flexGrow: 1 }}>
<Accordion
square={true}
onClick={(e) => e.stopPropagation()}
elevation={1}
disabled={affinedRoles?.length <= 0}
sx={{
mr: 1,
overflow: 'hidden',
borderRadius: '0 0 0.5rem 0.5rem',
'&:not(.Mui-expanded)': {
maxHeight: '48px',
},
'&.Mui-expanded': {
maxHeight: 'none',
},
'.MuiAccordionSummary-root': {
borderRadius: '0 0 0.5rem 0.5rem',
'&:hover': {
borderRadius: '0 0 0.5rem 0.5rem',
},
},
}}
>
<AccordionSummary>
<Typography variant="caption">Affined Roles</Typography>
</AccordionSummary>
<AccordionDetails sx={{ overflow: 'hidden' }}>
{renderRoles(affinedRoles)}
</AccordionDetails>
</Accordion>
<Accordion
square={true}
onClick={(e) => e.stopPropagation()}
elevation={1}
disabled={antiAffinedRoles?.length <= 0}
sx={{
mr: 1,
borderRadius: '0 0 0.5rem 0.5rem',
'&:not(.Mui-expanded)': {
maxHeight: '48px',
},
'&.Mui-expanded': {
maxHeight: 'none',
},
'.MuiAccordionSummary-root': {
borderRadius: '0 0 0.5rem 0.5rem',
'&:hover': {
borderRadius: '0 0 0.5rem 0.5rem',
},
},
}}
>
<AccordionSummary>
<Typography variant="caption">Anti-Affined Roles</Typography>
</AccordionSummary>
<AccordionDetails>{renderRoles(antiAffinedRoles)}</AccordionDetails>
</Accordion>
</Box>
)
}

RolesComponent.propTypes = {
roles: PropTypes.oneOfType([
PropTypes.arrayOf(
PropTypes.shape({
POLICY: PropTypes.string.isRequired,
NAME: PropTypes.string.isRequired,
ID: PropTypes.string.isRequired,
})
),
PropTypes.object,
]).isRequired,
}

VmGroupCard.propTypes = {
vmgroup: PropTypes.shape({
ID: PropTypes.string.isRequired,
NAME: PropTypes.string.isRequired,
GNAME: PropTypes.string.isRequired,
LOCK: PropTypes.object,
ROLES: PropTypes.oneOfType([PropTypes.object, PropTypes.string]).isRequired,
}),
rootProps: PropTypes.object,
}

VmGroupCard.displayName = 'VmGroupCard'

export default VmGroupCard
Loading

0 comments on commit c461d30

Please sign in to comment.