add creation of a vmGroup
This commit is contained in:
@@ -67,6 +67,7 @@ var messages = {
|
|||||||
taskMenu: 'Tasks',
|
taskMenu: 'Tasks',
|
||||||
taskPage: 'Tasks',
|
taskPage: 'Tasks',
|
||||||
newVmPage: 'VM',
|
newVmPage: 'VM',
|
||||||
|
newVmGroupPage: 'VM-Group',
|
||||||
newSrPage: 'Storage',
|
newSrPage: 'Storage',
|
||||||
newServerPage: 'Server',
|
newServerPage: 'Server',
|
||||||
newImport: 'Import',
|
newImport: 'Import',
|
||||||
@@ -937,6 +938,14 @@ var messages = {
|
|||||||
newVmHideAdvanced: 'Hide advanced settings',
|
newVmHideAdvanced: 'Hide advanced settings',
|
||||||
newVmShare: 'Share this VM',
|
newVmShare: 'Share this VM',
|
||||||
|
|
||||||
|
// ----- VM-Group-----
|
||||||
|
newVmGroupTitle: 'Create a new Vm-Group on ',
|
||||||
|
newVmGroupNameLabel: 'Label',
|
||||||
|
newVmGroupDescriptionLabel: 'Description',
|
||||||
|
newVmGroupReset: 'Reset',
|
||||||
|
newVmGroupCreate: 'Create',
|
||||||
|
newVmGroupInfoPanel: 'Infos',
|
||||||
|
|
||||||
// ----- Self -----
|
// ----- Self -----
|
||||||
resourceSets: 'Resource sets',
|
resourceSets: 'Resource sets',
|
||||||
noResourceSets: 'No resource sets.',
|
noResourceSets: 'No resource sets.',
|
||||||
|
|||||||
@@ -1957,3 +1957,4 @@ export const registerXosan = namespace => _call('cloud.registerResource', { name
|
|||||||
// VM-Group ----------------------------------------------------------------------
|
// VM-Group ----------------------------------------------------------------------
|
||||||
|
|
||||||
export const fetchVmGroupStats = (host, granularity) => { /* TODO */ }
|
export const fetchVmGroupStats = (host, granularity) => { /* TODO */ }
|
||||||
|
export const createVmGroup = ({ pool, name_label, name_description }) => _call('vmGroup.create', { id: resolveId(pool), name_label, name_description })
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import Menu from './menu'
|
|||||||
import Modal, { alert } from 'modal'
|
import Modal, { alert } from 'modal'
|
||||||
import New from './new'
|
import New from './new'
|
||||||
import NewVm from './new-vm'
|
import NewVm from './new-vm'
|
||||||
|
import NewVmGroup from './new-vm-group'
|
||||||
import Pool from './pool'
|
import Pool from './pool'
|
||||||
import Self from './self'
|
import Self from './self'
|
||||||
import Settings from './settings'
|
import Settings from './settings'
|
||||||
@@ -87,6 +88,7 @@ const BODY_STYLE = {
|
|||||||
'vms/import': VmImport,
|
'vms/import': VmImport,
|
||||||
'vms/new': NewVm,
|
'vms/new': NewVm,
|
||||||
'vms/:id': Vm,
|
'vms/:id': Vm,
|
||||||
|
'vm-group/new': NewVmGroup,
|
||||||
'vm-group/:id': VmGroup,
|
'vm-group/:id': VmGroup,
|
||||||
'xoa-update': XoaUpdates,
|
'xoa-update': XoaUpdates,
|
||||||
'xosan': Xosan
|
'xosan': Xosan
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ export default class Menu extends Component {
|
|||||||
isAdmin && { to: '/xosan', icon: 'menu-xosan', label: 'xosan' },
|
isAdmin && { to: '/xosan', icon: 'menu-xosan', label: 'xosan' },
|
||||||
!(noOperatablePools && noResourceSets) && { to: '/vms/new', icon: 'menu-new', label: 'newMenu', subMenu: [
|
!(noOperatablePools && noResourceSets) && { to: '/vms/new', icon: 'menu-new', label: 'newMenu', subMenu: [
|
||||||
{ to: '/vms/new', icon: 'menu-new-vm', label: 'newVmPage' },
|
{ to: '/vms/new', icon: 'menu-new-vm', label: 'newVmPage' },
|
||||||
|
{ to: '/vm-group/new', icon: 'menu-new-vm', label: 'newVmGroupPage' },
|
||||||
isAdmin && { to: '/new/sr', icon: 'menu-new-sr', label: 'newSrPage' },
|
isAdmin && { to: '/new/sr', icon: 'menu-new-sr', label: 'newSrPage' },
|
||||||
isAdmin && { to: '/settings/servers', icon: 'menu-settings-servers', label: 'newServerPage' },
|
isAdmin && { to: '/settings/servers', icon: 'menu-settings-servers', label: 'newServerPage' },
|
||||||
!noOperatablePools && { to: '/vms/import', icon: 'menu-new-import', label: 'newImport' }
|
!noOperatablePools && { to: '/vms/import', icon: 'menu-new-import', label: 'newImport' }
|
||||||
|
|||||||
153
src/xo-app/new-vm-group/index.js
Normal file
153
src/xo-app/new-vm-group/index.js
Normal file
@@ -0,0 +1,153 @@
|
|||||||
|
import _ from 'intl'
|
||||||
|
import ActionButton from 'action-button'
|
||||||
|
import BaseComponent from 'base-component'
|
||||||
|
import classNames from 'classnames'
|
||||||
|
import DebounceInput from 'react-debounce-input'
|
||||||
|
import Icon from 'icon'
|
||||||
|
import Page from '../page'
|
||||||
|
import React from 'react'
|
||||||
|
import Wizard, { Section } from 'wizard'
|
||||||
|
import { Container, Row, Col } from 'grid'
|
||||||
|
import {
|
||||||
|
createVmGroup,
|
||||||
|
subscribeCurrentUser,
|
||||||
|
subscribePermissions,
|
||||||
|
subscribeResourceSets
|
||||||
|
} from 'xo'
|
||||||
|
import {
|
||||||
|
createSelector,
|
||||||
|
createGetObjectsOfType,
|
||||||
|
getUser
|
||||||
|
} from 'selectors'
|
||||||
|
import { SelectPool } from 'select-objects'
|
||||||
|
import { addSubscriptions, connectStore } from 'utils'
|
||||||
|
|
||||||
|
import styles from '../new-vm/index.css'
|
||||||
|
|
||||||
|
const SectionContent = ({ column, children }) => (
|
||||||
|
<div className={classNames(
|
||||||
|
'form-inline',
|
||||||
|
styles.sectionContent,
|
||||||
|
column && styles.sectionContentColumn
|
||||||
|
)}>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
|
||||||
|
const Item = ({ label, children, className }) => (
|
||||||
|
<span className={styles.item}>
|
||||||
|
{label && <span>{label} </span>}
|
||||||
|
<span className={classNames(styles.input, className)}>{children}</span>
|
||||||
|
</span>
|
||||||
|
)
|
||||||
|
|
||||||
|
@addSubscriptions({
|
||||||
|
resourceSets: subscribeResourceSets,
|
||||||
|
permissions: subscribePermissions,
|
||||||
|
user: subscribeCurrentUser
|
||||||
|
})
|
||||||
|
@connectStore(() => ({
|
||||||
|
isAdmin: createSelector(
|
||||||
|
getUser,
|
||||||
|
user => user && user.permission === 'admin'
|
||||||
|
),
|
||||||
|
pools: createGetObjectsOfType('pool')
|
||||||
|
}))
|
||||||
|
export default class NewVmGroup extends BaseComponent {
|
||||||
|
static contextTypes = {
|
||||||
|
router: React.PropTypes.object
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor () {
|
||||||
|
super()
|
||||||
|
this.state = {name_label: '', name_description: ''}
|
||||||
|
}
|
||||||
|
|
||||||
|
_selectPool = pool => {
|
||||||
|
this.setState({ pool })
|
||||||
|
this._reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
_getCanOperate = createSelector(
|
||||||
|
() => this.props.isAdmin,
|
||||||
|
() => this.props.permissions,
|
||||||
|
(isAdmin, permissions) => isAdmin
|
||||||
|
? () => true
|
||||||
|
: ({ id }) => permissions && permissions[id] && permissions[id].operate
|
||||||
|
)
|
||||||
|
|
||||||
|
_renderHeader = () => {
|
||||||
|
const { pool } = this.state
|
||||||
|
return <Container>
|
||||||
|
<Row>
|
||||||
|
<Col mediumSize={12}>
|
||||||
|
<h2><Icon icon='sr' /> {_('newVmGroupTitle')}
|
||||||
|
<SelectPool
|
||||||
|
onChange={this._selectPool}
|
||||||
|
predicate={this._getCanOperate()}
|
||||||
|
value={pool}
|
||||||
|
/>
|
||||||
|
</h2>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</Container>
|
||||||
|
}
|
||||||
|
_reset = () => this.setState({poolId: '', name_label: '', name_description: ''})
|
||||||
|
_create = () => {
|
||||||
|
createVmGroup(this.state)
|
||||||
|
this.context.router.push('home?s=&t=VmGroup')
|
||||||
|
}
|
||||||
|
_getOnChange = item => ({target}) => this.setState({[item]: target.value})
|
||||||
|
|
||||||
|
render () {
|
||||||
|
const {pool, name_label: nameLabel, name_description: nameDescription} = this.state
|
||||||
|
return (
|
||||||
|
<Page header={this._renderHeader()}>
|
||||||
|
<form id='vmGroupCreation'>
|
||||||
|
<Wizard>
|
||||||
|
<Section icon='new-vm-infos' title='newVmGroupInfoPanel'>
|
||||||
|
<SectionContent>
|
||||||
|
<Item label={_('newVmGroupNameLabel')}>
|
||||||
|
<DebounceInput
|
||||||
|
className='form-control'
|
||||||
|
// debounceTimeout={DEBOUNCE_TIMEOUT}
|
||||||
|
onChange={this._getOnChange('name_label')}
|
||||||
|
value={nameLabel}
|
||||||
|
/>
|
||||||
|
</Item>
|
||||||
|
<Item label={_('newVmGroupDescriptionLabel')}>
|
||||||
|
<DebounceInput
|
||||||
|
className='form-control'
|
||||||
|
// debounceTimeout={DEBOUNCE_TIMEOUT}
|
||||||
|
onChange={this._getOnChange('name_description')}
|
||||||
|
value={nameDescription}
|
||||||
|
/>
|
||||||
|
</Item>
|
||||||
|
</SectionContent>
|
||||||
|
</Section>
|
||||||
|
</Wizard>
|
||||||
|
<div className={styles.submitSection}>
|
||||||
|
<ActionButton
|
||||||
|
className={styles.button}
|
||||||
|
handler={this._reset}
|
||||||
|
icon='new-vm-reset'
|
||||||
|
>
|
||||||
|
{_('newVmGroupReset')}
|
||||||
|
</ActionButton>
|
||||||
|
<ActionButton
|
||||||
|
btnStyle='primary'
|
||||||
|
className={styles.button}
|
||||||
|
disabled={nameLabel === '' || pool === undefined}
|
||||||
|
form='vmGroupCreation'
|
||||||
|
handler={this._create}
|
||||||
|
icon='new-vm-create'
|
||||||
|
redirectOnSuccess={this._getRedirectionUrl}
|
||||||
|
>
|
||||||
|
{_('newVmGroupCreate')}
|
||||||
|
</ActionButton>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</Page>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user