mirror of
https://github.com/OpenNebula/one.git
synced 2026-12-03 05:35:42 +09:00
F OpenNebula/one#5422: Add rename action
This commit is contained in:
13 files changed
+256
-200
No files matched your search
@@ -1,145 +0,0 @@
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* Copyright 2002-2021, 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 * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { makeStyles, Typography } from '@material-ui/core'
|
||||
|
||||
import { useDialog } from 'client/hooks'
|
||||
import { DialogConfirmation } from 'client/components/Dialogs'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
import * as Actions from 'client/components/Tabs/Common/Attribute/Actions'
|
||||
import * as Inputs from 'client/components/Tabs/Common/Attribute/Inputs'
|
||||
|
||||
const useStyles = makeStyles({
|
||||
wrapper: {
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
'& > *:first-child': {
|
||||
flexGrow: 1
|
||||
}
|
||||
},
|
||||
select: {
|
||||
textOverflow: 'ellipsis'
|
||||
}
|
||||
})
|
||||
|
||||
const Attribute = React.memo(({
|
||||
canDelete,
|
||||
canEdit,
|
||||
handleEdit,
|
||||
handleDelete,
|
||||
handleGetOptionList,
|
||||
name,
|
||||
value,
|
||||
valueInOptionList
|
||||
}) => {
|
||||
const classes = useStyles()
|
||||
const [isEditing, setIsEditing] = React.useState(() => false)
|
||||
const [options, setOptions] = React.useState(() => [])
|
||||
const { display, show, hide } = useDialog()
|
||||
const inputRef = React.createRef()
|
||||
|
||||
const handleEditAttribute = async () => {
|
||||
await handleEdit?.(inputRef.current.value)
|
||||
setIsEditing(false)
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
setIsEditing(false)
|
||||
}
|
||||
|
||||
const handleActiveEditForm = async () => {
|
||||
const response = await handleGetOptionList?.() ?? []
|
||||
const isFormatValid = response?.every?.(({ text, value } = {}) => !!text && !!value)
|
||||
|
||||
if (!handleGetOptionList || isFormatValid) {
|
||||
setOptions(response)
|
||||
setIsEditing(true)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeleteAttribute = async () => {
|
||||
await handleDelete?.()
|
||||
hide()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Typography noWrap variant='body2' title={Tr(name)}>
|
||||
{Tr(name)}
|
||||
</Typography>
|
||||
<div className={classes.wrapper}>
|
||||
{isEditing ? (
|
||||
<>
|
||||
{handleGetOptionList ? (
|
||||
<Inputs.Select
|
||||
name={name}
|
||||
value={valueInOptionList}
|
||||
ref={inputRef}
|
||||
options={options} />
|
||||
) : (
|
||||
<Inputs.Text name={name} value={value} ref={inputRef} />
|
||||
)}
|
||||
<Actions.Accept name={name} handleClick={handleEditAttribute} />
|
||||
<Actions.Cancel name={name} handleClick={handleCancel} />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Typography
|
||||
noWrap
|
||||
variant='body2'
|
||||
title={typeof value === 'string' ? value : undefined}
|
||||
>
|
||||
{value}
|
||||
</Typography>
|
||||
{canEdit && (
|
||||
<Actions.Edit name={name} handleClick={handleActiveEditForm} />
|
||||
)}
|
||||
{canDelete && (
|
||||
<Actions.Delete name={name} handleClick={show} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{display && (
|
||||
<DialogConfirmation
|
||||
title={`Delete attribute: ${name}`}
|
||||
handleAccept={handleDeleteAttribute}
|
||||
handleCancel={hide}
|
||||
>
|
||||
<p>Are you sure?</p>
|
||||
</DialogConfirmation>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
})
|
||||
|
||||
Attribute.propTypes = {
|
||||
canDelete: PropTypes.bool,
|
||||
canEdit: PropTypes.bool,
|
||||
handleEdit: PropTypes.func,
|
||||
handleDelete: PropTypes.func,
|
||||
handleGetOptionList: PropTypes.func,
|
||||
name: PropTypes.string.isRequired,
|
||||
value: PropTypes.string.isRequired,
|
||||
valueInOptionList: PropTypes.string.isRequired
|
||||
}
|
||||
|
||||
Attribute.displayName = 'Attribute'
|
||||
|
||||
export default Attribute
|
||||
@@ -13,6 +13,138 @@
|
||||
* See the License for the specific language governing permissions and *
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
import Attribute from 'client/components/Tabs/Common/Attribute/Attribute'
|
||||
import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { makeStyles, Typography } from '@material-ui/core'
|
||||
|
||||
import { useDialog } from 'client/hooks'
|
||||
import { DialogConfirmation } from 'client/components/Dialogs'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
import * as Actions from 'client/components/Tabs/Common/Attribute/Actions'
|
||||
import * as Inputs from 'client/components/Tabs/Common/Attribute/Inputs'
|
||||
|
||||
const useStyles = makeStyles({
|
||||
wrapper: {
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
'& > *:first-child': {
|
||||
flexGrow: 1
|
||||
}
|
||||
},
|
||||
select: {
|
||||
textOverflow: 'ellipsis'
|
||||
}
|
||||
})
|
||||
|
||||
const Attribute = React.memo(({
|
||||
canDelete,
|
||||
canEdit,
|
||||
handleEdit,
|
||||
handleDelete,
|
||||
handleGetOptionList,
|
||||
name,
|
||||
value,
|
||||
valueInOptionList
|
||||
}) => {
|
||||
const classes = useStyles()
|
||||
const [isEditing, setIsEditing] = React.useState(() => false)
|
||||
const [options, setOptions] = React.useState(() => [])
|
||||
const { display, show, hide } = useDialog()
|
||||
const inputRef = React.createRef()
|
||||
|
||||
const handleEditAttribute = async () => {
|
||||
await handleEdit?.(inputRef.current.value)
|
||||
setIsEditing(false)
|
||||
}
|
||||
|
||||
const handleCancel = () => {
|
||||
setIsEditing(false)
|
||||
}
|
||||
|
||||
const handleActiveEditForm = async () => {
|
||||
const response = await handleGetOptionList?.() ?? []
|
||||
const isFormatValid = response?.every?.(({ text, value } = {}) => !!text && !!value)
|
||||
|
||||
if (!handleGetOptionList || isFormatValid) {
|
||||
setOptions(response)
|
||||
setIsEditing(true)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDeleteAttribute = async () => {
|
||||
await handleDelete?.()
|
||||
hide()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Typography noWrap variant='body2' title={Tr(name)}>
|
||||
{Tr(name)}
|
||||
</Typography>
|
||||
<div className={classes.wrapper}>
|
||||
{isEditing ? (
|
||||
<>
|
||||
{handleGetOptionList ? (
|
||||
<Inputs.Select
|
||||
name={name}
|
||||
value={valueInOptionList}
|
||||
ref={inputRef}
|
||||
options={options} />
|
||||
) : (
|
||||
<Inputs.Text name={name} value={value} ref={inputRef} />
|
||||
)}
|
||||
<Actions.Accept name={name} handleClick={handleEditAttribute} />
|
||||
<Actions.Cancel name={name} handleClick={handleCancel} />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Typography
|
||||
noWrap
|
||||
variant='body2'
|
||||
title={typeof value === 'string' ? value : undefined}
|
||||
>
|
||||
{value}
|
||||
</Typography>
|
||||
{canEdit && (
|
||||
<Actions.Edit name={name} handleClick={handleActiveEditForm} />
|
||||
)}
|
||||
{canDelete && (
|
||||
<Actions.Delete name={name} handleClick={show} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{display && (
|
||||
<DialogConfirmation
|
||||
title={`Delete attribute: ${name}`}
|
||||
handleAccept={handleDeleteAttribute}
|
||||
handleCancel={hide}
|
||||
>
|
||||
<p>Are you sure?</p>
|
||||
</DialogConfirmation>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
})
|
||||
|
||||
export const AttributePropType = {
|
||||
canDelete: PropTypes.bool,
|
||||
canEdit: PropTypes.bool,
|
||||
handleEdit: PropTypes.func,
|
||||
handleDelete: PropTypes.func,
|
||||
handleGetOptionList: PropTypes.func,
|
||||
name: PropTypes.string.isRequired,
|
||||
value: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.object
|
||||
]).isRequired,
|
||||
valueInOptionList: PropTypes.string
|
||||
}
|
||||
|
||||
Attribute.propTypes = AttributePropType
|
||||
|
||||
Attribute.displayName = 'Attribute'
|
||||
|
||||
export default Attribute
|
||||
@@ -19,7 +19,7 @@ import PropTypes from 'prop-types'
|
||||
|
||||
import { makeStyles, List as MList, ListItem, Typography, Paper } from '@material-ui/core'
|
||||
|
||||
import Attribute from 'client/components/Tabs/Common/Attribute'
|
||||
import Attribute, { AttributePropType } from 'client/components/Tabs/Common/Attribute'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
@@ -65,16 +65,9 @@ const List = ({ title, list = [], ...props }) => {
|
||||
|
||||
List.propTypes = {
|
||||
title: PropTypes.string,
|
||||
list: PropTypes.arrayOf(PropTypes.shape({
|
||||
canDelete: PropTypes.bool,
|
||||
canEdit: PropTypes.bool,
|
||||
handleEdit: PropTypes.func,
|
||||
handleDelete: PropTypes.func,
|
||||
handleGetOptionList: PropTypes.func,
|
||||
name: PropTypes.string.isRequired,
|
||||
value: PropTypes.any.isRequired,
|
||||
valueInOptionList: PropTypes.string.isRequired
|
||||
}))
|
||||
list: PropTypes.arrayOf(
|
||||
PropTypes.shape(AttributePropType)
|
||||
)
|
||||
}
|
||||
|
||||
List.displayName = 'List'
|
||||
|
||||
@@ -18,9 +18,10 @@ import PropTypes from 'prop-types'
|
||||
|
||||
import { useUserApi, useGroupApi, RESOURCES } from 'client/features/One'
|
||||
import { List } from 'client/components/Tabs/Common'
|
||||
import { T, SERVERADMIN_ID } from 'client/constants'
|
||||
import { T, SERVERADMIN_ID, ACTIONS } from 'client/constants'
|
||||
|
||||
const Ownership = React.memo(({
|
||||
actions,
|
||||
groupId,
|
||||
groupName,
|
||||
handleEdit,
|
||||
@@ -54,7 +55,7 @@ const Ownership = React.memo(({
|
||||
name: T.Owner,
|
||||
value: userName,
|
||||
valueInOptionList: userId,
|
||||
canEdit: true,
|
||||
canEdit: actions?.includes?.(ACTIONS.CHANGE_OWNER),
|
||||
handleGetOptionList: getUserOptions,
|
||||
handleEdit: user => handleEdit?.({ user })
|
||||
},
|
||||
@@ -62,7 +63,7 @@ const Ownership = React.memo(({
|
||||
name: T.Group,
|
||||
value: groupName,
|
||||
valueInOptionList: groupId,
|
||||
canEdit: true,
|
||||
canEdit: actions?.includes?.(ACTIONS.CHANGE_GROUP),
|
||||
handleGetOptionList: getGroupOptions,
|
||||
handleEdit: group => handleEdit?.({ group })
|
||||
}
|
||||
@@ -74,6 +75,7 @@ const Ownership = React.memo(({
|
||||
})
|
||||
|
||||
Ownership.propTypes = {
|
||||
actions: PropTypes.arrayOf(PropTypes.string),
|
||||
userId: PropTypes.string.isRequired,
|
||||
userName: PropTypes.string.isRequired,
|
||||
groupId: PropTypes.string.isRequired,
|
||||
|
||||
@@ -21,7 +21,7 @@ import { Check as CheckIcon, Square as BlankSquareIcon } from 'iconoir-react'
|
||||
|
||||
import { Action } from 'client/components/Cards/SelectCard'
|
||||
import { Tr } from 'client/components/HOC'
|
||||
import { T } from 'client/constants'
|
||||
import { T, ACTIONS } from 'client/constants'
|
||||
|
||||
import * as Helper from 'client/models/Helper'
|
||||
|
||||
@@ -43,7 +43,7 @@ const useStyles = makeStyles(theme => ({
|
||||
}
|
||||
}))
|
||||
|
||||
const Permissions = React.memo(({ handleEdit, ...permissions }) => {
|
||||
const Permissions = React.memo(({ handleEdit, actions, ...permissions }) => {
|
||||
const classes = useStyles()
|
||||
|
||||
const handleChange = async (name, value) => {
|
||||
@@ -54,6 +54,8 @@ const Permissions = React.memo(({ handleEdit, ...permissions }) => {
|
||||
await handleEdit?.(newPermission)
|
||||
}
|
||||
|
||||
const getIcon = checked => +checked ? <CheckIcon size={18} /> : <BlankSquareIcon size={18} />
|
||||
|
||||
return (
|
||||
<Paper variant='outlined'>
|
||||
<List className={classes.list}>
|
||||
@@ -75,14 +77,14 @@ const Permissions = React.memo(({ handleEdit, ...permissions }) => {
|
||||
.filter(([key, _]) => key.toLowerCase().startsWith(category))
|
||||
.map(([key, permission]) => (
|
||||
<span key={key}>
|
||||
<Action
|
||||
cy={`permission-${key}`}
|
||||
disabled={permission === undefined}
|
||||
icon={
|
||||
+permission ? <CheckIcon size={18} /> : <BlankSquareIcon size={18} />
|
||||
}
|
||||
handleClick={() => handleChange(key, permission)}
|
||||
/>
|
||||
{actions?.includes?.(ACTIONS.CHANGE_MODE) ? (
|
||||
<Action
|
||||
cy={`permission-${key}`}
|
||||
disabled={permission === undefined}
|
||||
icon={getIcon(permission)}
|
||||
handleClick={() => handleChange(key, permission)}
|
||||
/>
|
||||
) : getIcon(permission)}
|
||||
</span>
|
||||
))
|
||||
}
|
||||
@@ -94,6 +96,7 @@ const Permissions = React.memo(({ handleEdit, ...permissions }) => {
|
||||
})
|
||||
|
||||
Permissions.propTypes = {
|
||||
actions: PropTypes.arrayOf(PropTypes.string),
|
||||
groupAdmin: PropTypes.string.isRequired,
|
||||
groupManage: PropTypes.string.isRequired,
|
||||
groupUse: PropTypes.string.isRequired,
|
||||
|
||||
@@ -18,27 +18,42 @@ import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { useVmApi } from 'client/features/One'
|
||||
import { Permissions, Ownership } from 'client/components/Tabs/Common'
|
||||
import { TabContext } from 'client/components/Tabs/TabProvider'
|
||||
import { Permissions, Ownership } from 'client/components/Tabs/Common'
|
||||
import Information from 'client/components/Tabs/Vm/Info/information'
|
||||
|
||||
const VmInfoTab = ({ tabProps }) => {
|
||||
const { changeOwnership, changePermissions } = useVmApi()
|
||||
const { handleRefetch, data } = React.useContext(TabContext)
|
||||
const { ID, UNAME, UID, GNAME, GID, PERMISSIONS } = data
|
||||
import * as VirtualMachine from 'client/models/VirtualMachine'
|
||||
import * as Helper from 'client/models/Helper'
|
||||
|
||||
const VmInfoTab = ({ tabProps = {} }) => {
|
||||
const {
|
||||
information_panel: informationPanel,
|
||||
permissions_panel: permissionsPanel,
|
||||
ownership_panel: ownershipPanel
|
||||
} = tabProps
|
||||
|
||||
const { changeOwnership, changePermissions, rename } = useVmApi()
|
||||
const { handleRefetch, data: vm } = React.useContext(TabContext)
|
||||
const { ID, UNAME, UID, GNAME, GID, PERMISSIONS } = vm
|
||||
|
||||
const handleChangeOwnership = async newOwnership => {
|
||||
const response = await changeOwnership(ID, newOwnership)
|
||||
|
||||
String(response) === String(ID) && await handleRefetch?.()
|
||||
}
|
||||
|
||||
const handleChangePermission = async newPermission => {
|
||||
const response = await changePermissions(ID, newPermission)
|
||||
|
||||
String(response) === String(ID) && await handleRefetch?.()
|
||||
}
|
||||
|
||||
const handleRename = async newName => {
|
||||
const response = await rename(ID, newName)
|
||||
String(response) === String(ID) && await handleRefetch?.()
|
||||
}
|
||||
|
||||
const hypervisor = VirtualMachine.getHypervisor(vm)
|
||||
const getActions = actions => Helper.getActionsAvailable(actions, hypervisor)
|
||||
|
||||
return (
|
||||
<div style={{
|
||||
display: 'grid',
|
||||
@@ -46,11 +61,16 @@ const VmInfoTab = ({ tabProps }) => {
|
||||
gridTemplateColumns: 'repeat(auto-fit, minmax(480px, 1fr))',
|
||||
padding: '0.8em'
|
||||
}}>
|
||||
{tabProps?.information_panel?.enabled &&
|
||||
<Information {...data} />
|
||||
{informationPanel?.enabled &&
|
||||
<Information
|
||||
actions={getActions(informationPanel?.actions)}
|
||||
handleRename={handleRename}
|
||||
vm={vm}
|
||||
/>
|
||||
}
|
||||
{tabProps?.permissions_panel?.enabled &&
|
||||
{permissionsPanel?.enabled &&
|
||||
<Permissions
|
||||
actions={getActions(permissionsPanel?.actions)}
|
||||
ownerUse={PERMISSIONS.OWNER_U}
|
||||
ownerManage={PERMISSIONS.OWNER_M}
|
||||
ownerAdmin={PERMISSIONS.OWNER_A}
|
||||
@@ -63,8 +83,9 @@ const VmInfoTab = ({ tabProps }) => {
|
||||
handleEdit={handleChangePermission}
|
||||
/>
|
||||
}
|
||||
{tabProps?.ownership_panel?.enabled &&
|
||||
{ownershipPanel?.enabled &&
|
||||
<Ownership
|
||||
actions={getActions(ownershipPanel?.actions)}
|
||||
userId={UID}
|
||||
userName={UNAME}
|
||||
groupId={GID}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
* ------------------------------------------------------------------------- */
|
||||
/* eslint-disable jsdoc/require-jsdoc */
|
||||
import * as React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
|
||||
import { StatusChip } from 'client/components/Status'
|
||||
import { List } from 'client/components/Tabs/Common'
|
||||
@@ -22,27 +23,25 @@ import Multiple from 'client/components/Tables/Vms/multiple'
|
||||
|
||||
import * as VirtualMachine from 'client/models/VirtualMachine'
|
||||
import * as Helper from 'client/models/Helper'
|
||||
import { T } from 'client/constants'
|
||||
import { T, VM_ACTIONS } from 'client/constants'
|
||||
|
||||
const InformationPanel = data => {
|
||||
const { ID, NAME, RESCHED, STIME, ETIME, LOCK, DEPLOY_ID } = data
|
||||
const InformationPanel = ({ vm = {}, handleRename, actions }) => {
|
||||
const { ID, NAME, RESCHED, STIME, ETIME, LOCK, DEPLOY_ID } = vm
|
||||
|
||||
const { name: stateName, color: stateColor } = VirtualMachine.getState(data)
|
||||
const { name: stateName, color: stateColor } = VirtualMachine.getState(vm)
|
||||
|
||||
const { HID: hostId, HOSTNAME: hostname = '--', CID: clusterId } = VirtualMachine.getLastHistory(data)
|
||||
const { HID: hostId, HOSTNAME: hostname = '--', CID: clusterId } = VirtualMachine.getLastHistory(vm)
|
||||
const clusterName = clusterId === '-1' ? 'default' : '--' // TODO: get from cluster list
|
||||
|
||||
const ips = VirtualMachine.getIps(data)
|
||||
const ips = VirtualMachine.getIps(vm)
|
||||
|
||||
const info = [
|
||||
{ name: T.ID, value: ID },
|
||||
{
|
||||
name: T.Name,
|
||||
value: NAME,
|
||||
canEdit: true,
|
||||
handleEdit: newName => {
|
||||
|
||||
}
|
||||
canEdit: actions?.includes?.(VM_ACTIONS.RENAME),
|
||||
handleEdit: handleRename
|
||||
},
|
||||
{
|
||||
name: T.State,
|
||||
@@ -89,4 +88,10 @@ const InformationPanel = data => {
|
||||
|
||||
InformationPanel.displayName = 'InformationPanel'
|
||||
|
||||
InformationPanel.propTypes = {
|
||||
actions: PropTypes.arrayOf(PropTypes.string),
|
||||
handleRename: PropTypes.func,
|
||||
vm: PropTypes.object
|
||||
}
|
||||
|
||||
export default InformationPanel
|
||||
@@ -0,0 +1,25 @@
|
||||
/* ------------------------------------------------------------------------- *
|
||||
* Copyright 2002-2021, 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. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
// INFORMATION
|
||||
export const RENAME = 'rename'
|
||||
|
||||
// PERMISSION
|
||||
export const CHANGE_MODE = 'chmod'
|
||||
|
||||
// OWNERSHIP
|
||||
export const CHANGE_OWNER = 'chown'
|
||||
export const CHANGE_GROUP = 'chgrp'
|
||||
@@ -81,6 +81,7 @@ export const SOCKETS = {
|
||||
}
|
||||
|
||||
export * as T from 'client/constants/translates'
|
||||
export * as ACTIONS from 'client/constants/actions'
|
||||
export * as STATES from 'client/constants/states'
|
||||
export * from 'client/constants/flow'
|
||||
export * from 'client/constants/provision'
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
* limitations under the License. *
|
||||
* ------------------------------------------------------------------------- */
|
||||
import * as STATES from 'client/constants/states'
|
||||
import * as ACTIONS from 'client/constants/actions'
|
||||
import COLOR from 'client/constants/color'
|
||||
|
||||
/** @type {STATES.StateInfo[]} Virtual machine states */
|
||||
@@ -465,15 +466,10 @@ export const VM_ACTIONS = {
|
||||
SAVE_RDP: 'save_rdp',
|
||||
SAVE_VIRT_VIEWER: 'save_virt_viewer',
|
||||
|
||||
// INFORMATION
|
||||
RENAME: 'rename',
|
||||
|
||||
// PERMISSION
|
||||
CHMOD: 'chmod',
|
||||
|
||||
// OWNERSHIP
|
||||
CHOWN: 'chown',
|
||||
CHANGE_GROUP: 'chgrp',
|
||||
RENAME: ACTIONS.RENAME,
|
||||
CHANGE_MODE: ACTIONS.CHANGE_MODE,
|
||||
CHANGE_OWNER: ACTIONS.CHANGE_OWNER,
|
||||
CHANGE_GROUP: ACTIONS.CHANGE_GROUP,
|
||||
|
||||
// CAPACITY
|
||||
RESIZE_CAPACITY: 'resize_capacity',
|
||||
|
||||
@@ -40,6 +40,7 @@ export const terminateVm = createAction(
|
||||
})
|
||||
)
|
||||
|
||||
export const rename = createAction('vm/rename', vmService.rename)
|
||||
export const changePermissions = createAction('vm/chmod', vmService.changePermissions)
|
||||
export const changeOwnership = createAction('vm/chown', vmService.changeOwnership)
|
||||
export const detachNic = createAction('vm/detach/nic', vmService.detachNic)
|
||||
@@ -36,6 +36,7 @@ export const useVmApi = () => {
|
||||
getVm: id => unwrapDispatch(actions.getVm({ id })),
|
||||
getVms: options => unwrapDispatch(actions.getVms(options)),
|
||||
terminateVm: id => unwrapDispatch(actions.terminateVm({ id })),
|
||||
rename: (id, name) => unwrapDispatch(actions.rename({ id, name })),
|
||||
changePermissions: (id, permissions) =>
|
||||
unwrapDispatch(actions.changePermissions({ id, permissions })),
|
||||
changeOwnership: (id, ownership) =>
|
||||
|
||||
@@ -98,6 +98,27 @@ export const vmService = ({
|
||||
return res?.data?.VM ?? {}
|
||||
},
|
||||
|
||||
/**
|
||||
* Renames a virtual machine.
|
||||
*
|
||||
* @param {object} params - Request parameters
|
||||
* @param {string|number} params.id - Virtual machine id
|
||||
* @param {string} params.name - New name
|
||||
* @returns {number} Virtual machine id
|
||||
* @throws Fails when response isn't code 200
|
||||
*/
|
||||
rename: async ({ id, name: newName }) => {
|
||||
const name = Actions.VM_RENAME
|
||||
const command = { name, ...Commands[name] }
|
||||
const config = requestConfig({ id, name: newName }, command)
|
||||
|
||||
const res = await RestClient.request(config)
|
||||
|
||||
if (!res?.id || res?.id !== httpCodes.ok.id) throw res?.data
|
||||
|
||||
return res?.data
|
||||
},
|
||||
|
||||
/**
|
||||
* Changes the permission bits of a virtual machine.
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user