Compare commits

..

30 Commits

Author SHA1 Message Date
BCedric
1083aba33c add message for current operation 2017-06-23 16:51:46 +02:00
BCedric
d90156ff15 tabManagement, remove displaying vm list if the group is empty 2017-06-23 16:17:25 +02:00
BCedric
45b6e010df correct getMemoryTotal function 2017-06-23 16:14:43 +02:00
BCedric
1fbdb7799e display current operations 2017-06-23 16:12:45 +02:00
BCedric
3050fd7ce1 display an halted icon if the groupe is empty 2017-06-23 16:09:04 +02:00
BCedric
1988934f8a use proptypes decorator 2017-06-23 16:04:31 +02:00
BCedric
5331ced4fe add dragNDropOrder generic component 2017-06-22 15:57:56 +02:00
BCedric
74066f7d44 move NewVmGroup in new folder 2017-06-22 15:57:56 +02:00
BCedric
98e3aa89bb use intl in vm list 2017-06-22 15:57:56 +02:00
BCedric
070bb65740 use connectStore in VmGroup TabGeneral 2017-06-22 15:57:56 +02:00
BCedric
4e51959e3b add function removeAppliance 2017-06-22 15:57:56 +02:00
BCedric
b5ff695c74 add functions to calculate stats 2017-06-22 15:57:56 +02:00
BCedric
f879e2ace0 add VmGroup handlers in Home mainActions 2017-06-22 15:55:58 +02:00
BCedric
9aeabce4d8 add createVmGroup function 2017-06-22 15:55:58 +02:00
BCedric
2f17cd4ba9 allow to delete a vmGroup 2017-06-22 15:55:58 +02:00
BCedric
60e70a08c1 allow vms management 2017-06-22 15:55:58 +02:00
BCedric
6e0ba2bae3 add editVmGroup function 2017-06-22 15:55:58 +02:00
BCedric
feb996890e management of icon color 2017-06-22 15:55:58 +02:00
BCedric
a06bc85142 allow edition of a vmGroup 2017-06-22 15:55:58 +02:00
BCedric
f530aef92b remove vmGroup tag 2017-06-22 15:55:58 +02:00
BCedric
2eb7330335 add functions on action-bar 2017-06-22 15:55:58 +02:00
BCedric
89157e7b7e rename vm-groupe to vmGroup 2017-06-22 15:55:58 +02:00
BCedric
3834e2ef91 expose vmGroup, remove subscription 2017-06-22 15:55:58 +02:00
BCedric
a711231955 add creation of a vmGroup 2017-06-22 15:55:58 +02:00
BCedric
0a5e301b3e add stats tab 2017-06-22 15:55:58 +02:00
BCedric
c82b9893c5 add advanced tab 2017-06-22 15:55:58 +02:00
BCedric
f4dfabc34c add management tab 2017-06-22 15:55:58 +02:00
BCedric
059521aeda add general tab 2017-06-22 15:55:58 +02:00
BCedric
debca09e2c remove _getItems, rename VMGroupItem => VmGroupItem 2017-06-22 15:55:58 +02:00
BCedric
0699cfc449 display VM-Groups list 2017-06-22 15:55:58 +02:00
35 changed files with 1380 additions and 562 deletions

View File

@@ -1,28 +1,5 @@
# ChangeLog
## **5.10.0** (2017-05-31)
### Enhancements
- Improve backup log display [\#2239](https://github.com/vatesfr/xo-web/issues/2239)
- Patch SR detection improvement [\#2215](https://github.com/vatesfr/xo-web/issues/2215)
- Less strict coalesce detection [\#2207](https://github.com/vatesfr/xo-web/issues/2207)
- IP pool UI improvement [\#2203](https://github.com/vatesfr/xo-web/issues/2203)
- Ability to clear "Auto power on" flag for DR-ed VM [\#2097](https://github.com/vatesfr/xo-web/issues/2097)
- [Delta backup restoration] Choose SR for each VDIs [\#2070](https://github.com/vatesfr/xo-web/issues/2070)
- Ability to forget an host (even if no longer present) [\#1934](https://github.com/vatesfr/xo-web/issues/1934)
### Bug fixes
- Cross pool migrate fail [\#2248](https://github.com/vatesfr/xo-web/issues/2248)
- ActionButtons with modals stay in pending state forever [\#2222](https://github.com/vatesfr/xo-web/issues/2222)
- Permission issue for a user on self service VMs [\#2212](https://github.com/vatesfr/xo-web/issues/2212)
- Self-Service resource loophole [\#2198](https://github.com/vatesfr/xo-web/issues/2198)
- Backup log no longer shows the name of destination VM [\#2195](https://github.com/vatesfr/xo-web/issues/2195)
- State not restored when exiting modal dialog [\#2194](https://github.com/vatesfr/xo-web/issues/2194)
- [Xapi#exportDeltaVm] Cannot read property 'managed' of undefined [\#2189](https://github.com/vatesfr/xo-web/issues/2189)
- VNC keyboard layout change [\#404](https://github.com/vatesfr/xo-web/issues/404)
## **5.9.0** (2017-05-31)
### Enhancements

View File

@@ -1,7 +1,7 @@
{
"private": false,
"name": "xo-web",
"version": "5.10.0",
"version": "5.9.1",
"license": "AGPL-3.0",
"description": "Web interface client for Xen-Orchestra",
"keywords": [
@@ -31,7 +31,6 @@
"npm": ">=3"
},
"devDependencies": {
"@nraynaud/novnc": "^0.6.1-1",
"ansi_up": "^1.3.0",
"asap": "^2.0.4",
"babel-eslint": "^7.0.0",
@@ -94,6 +93,7 @@
"moment": "^2.13.0",
"moment-timezone": "^0.5.4",
"notifyjs": "^3.0.0",
"novnc-node": "^0.5.3",
"promise-toolbox": "^0.9.4",
"random-password": "^0.1.2",
"react": "^15.4.1",

View File

@@ -0,0 +1,128 @@
import _ from 'intl'
import ActionButton from 'action-button'
import Component from 'base-component'
import HTML5Backend from 'react-dnd-html5-backend'
import Icon from 'icon'
import map from 'lodash/map'
import propTypes from 'prop-types-decorator'
import React from 'react'
import { DragDropContext, DragSource, DropTarget } from 'react-dnd'
import { Toggle } from 'form'
const orderItemSource = {
beginDrag: props => ({
id: props.id,
index: props.index
})
}
const orderItemTarget = {
hover: (props, monitor, component) => {
const dragIndex = monitor.getItem().index
const hoverIndex = props.index
if (dragIndex === hoverIndex) {
return
}
props.move(dragIndex, hoverIndex)
monitor.getItem().index = hoverIndex
}
}
@DropTarget('orderItem', orderItemTarget, connect => ({
connectDropTarget: connect.dropTarget()
}))
@DragSource('orderItem', orderItemSource, (connect, monitor) => ({
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging()
}))
@propTypes({
connectDragSource: propTypes.func.isRequired,
connectDropTarget: propTypes.func.isRequired,
index: propTypes.number.isRequired,
isDragging: propTypes.bool.isRequired,
id: propTypes.any.isRequired,
item: propTypes.object.isRequired,
move: propTypes.func.isRequired
})
class OrderItem extends Component {
_toggle = checked => {
const { item } = this.props
item.active = checked
this.forceUpdate()
}
render () {
const { item, connectDragSource, connectDropTarget, toggle } = this.props
return connectDragSource(connectDropTarget(
<li className='list-group-item'>
<Icon icon='grab' />
{' '}
<Icon icon='grab' />
{' '}
{item.text}
{toggle && <span className='pull-right'>
<Toggle value={item.active} onChange={this._toggle} />
</span>}
</li>
))
}
}
@propTypes({
onClose: propTypes.func
})
@DragDropContext(HTML5Backend)
export default class DragNDropOrder extends Component {
constructor (props) {
super(props)
const { parseOrderParam, parseOrder } = props
this.state = parseOrder(parseOrderParam)
}
_moveOrderItem = (dragIndex, hoverIndex) => {
const order = this.state.order.slice()
const dragItem = order.splice(dragIndex, 1)
if (dragItem.length) {
order.splice(hoverIndex, 0, dragItem.pop())
this.setState({order})
}
}
_reset = () => {
const { parseOrderParam, parseOrder } = this.props
this.state = this.setState(parseOrder(parseOrderParam))
}
_save = () => {
const { order, toggleActive } = this.state
this.props.setOrder(this.props.parseOrderParam, order, toggleActive)
}
_toggleOnChange = event => this.setState({toggleActive: event})
render () {
const { order, toggleActive } = this.state
const { toggleItems } = this.props
return <form>
{!toggleItems && <Toggle value={toggleActive} onChange={this._toggleOnChange} />}
<ul>
{map(order, (item, index) => <OrderItem
toggle={toggleItems}
key={index}
index={index}
id={item.id}
// FIXME missing translation
item={item}
move={this._moveOrderItem}
/>)}
</ul>
<fieldset className='form-inline'>
<span className='pull-right'>
<ActionButton icon='save' btnStyle='primary' handler={this._save}>{_('saveBootOption')}</ActionButton>
{' '}
<ActionButton icon='reset' handler={this._reset}>{_('resetBootOption')}</ActionButton>
</span>
</fieldset>
</form>
}
}

View File

@@ -31,3 +31,8 @@ export const SR = {
...common,
homeFilterTags: 'tags:'
}
export const vmGroup = {
...common,
homeFilterTags: 'tags:'
}

View File

@@ -38,6 +38,7 @@ var messages = {
// ----- Titles -----
homePage: 'Home',
homeVmPage: 'VMs',
homeVmGroupPage: 'VM-Groups',
homeHostPage: 'Hosts',
homePoolPage: 'Pools',
homeTemplatePage: 'Templates',
@@ -66,6 +67,7 @@ var messages = {
taskMenu: 'Tasks',
taskPage: 'Tasks',
newVmPage: 'VM',
newVmGroupPage: 'VM-Group',
newSrPage: 'Storage',
newServerPage: 'Server',
newImport: 'Import',
@@ -121,6 +123,7 @@ var messages = {
homeTypePool: 'Pool',
homeTypeHost: 'Host',
homeTypeVm: 'VM',
homeTypeVmGroup: 'VM group',
homeTypeSr: 'SR',
homeTypeVmTemplate: 'Template',
homeSort: 'Sort',
@@ -218,11 +221,6 @@ var messages = {
cronPattern: 'Cron Pattern:',
backupEditNotFoundTitle: 'Cannot edit backup',
backupEditNotFoundMessage: 'Missing required info for edition',
successfulJobCall: 'Successful',
failedJobCall: 'Failed',
jobCallInProgess: 'In progress',
jobTransferredDataSize: 'size:',
jobTransferredDataSpeed: 'speed:',
job: 'Job',
jobModalTitle: 'Job {job}',
jobId: 'ID',
@@ -629,6 +627,7 @@ var messages = {
advancedTabName: 'Advanced',
networkTabName: 'Network',
disksTabName: 'Disk{disks, plural, one {} other {s}}',
managementTabName: 'Management',
powerStateHalted: 'halted',
powerStateRunning: 'running',
@@ -666,6 +665,7 @@ var messages = {
copyToClipboardLabel: 'Copy',
ctrlAltDelButtonLabel: 'Ctrl+Alt+Del',
tipLabel: 'Tip:',
tipConsoleLabel: 'Due to a XenServer issue, non-US keyboard layouts aren\'t well supported. Switch your own layout to US to workaround it.',
hideHeaderTooltip: 'Hide infos',
showHeaderTooltip: 'Show infos',
@@ -938,6 +938,32 @@ var messages = {
newVmHideAdvanced: 'Hide advanced settings',
newVmShare: 'Share this VM',
// ----- VM-Group-----
newVmGroupTitle: 'Create a new Vm-Group on ',
newVmGroupNameLabel: 'Label',
newVmGroupDescriptionLabel: 'Description',
newVmGroupReset: 'Reset',
newVmGroupCreate: 'Create',
newVmGroupInfoPanel: 'Infos',
// ----- VM-Group item -----
powerStateVmGroupRunning: 'All vms are running',
powerStateVmGroupHalted: 'All vms are halted',
powerStateVmGroupBusy: 'Contains vms halted and vms running',
// ----- VM-Group management Tab -----
'attachVmButton': 'new VM',
'vmsBootOrder': 'Boot order',
'vmGroupLabel': 'Label',
'vmGroupDescription': 'Description',
'vmGroupActions': 'Actions',
// ----- VM-Group general Tab -----
'vmGroupCurrentStatus': 'Current status',
// ----- VM-Group stats Tab -----
'vmGroupAllVm': 'All VMs',
// ----- Self -----
resourceSets: 'Resource sets',
noResourceSets: 'No resource sets.',
@@ -1015,10 +1041,6 @@ var messages = {
availableBackupsColumn: 'Available Backups',
backupRestoreErrorTitle: 'Missing parameters',
backupRestoreErrorMessage: 'Choose a SR and a backup',
backupRestoreSelectDefaultSr: 'Select default SR…',
backupRestoreChooseSrForEachVdis: 'Choose a SR for each VDI',
backupRestoreVdiLabel: 'VDI',
backupRestoreSrLabel: 'SR',
displayBackup: 'Display backups',
importBackupTitle: 'Import VM',
importBackupMessage: 'Starting your backup import',
@@ -1082,22 +1104,20 @@ var messages = {
migrateVmModalTitle: 'Migrate VM',
migrateVmSelectHost: 'Select a destination host:',
migrateVmSelectMigrationNetwork: 'Select a migration network:',
migrateVmSelectSrs: 'For each VDI, select an SR:',
migrateVmSelectNetworks: 'For each VIF, select a network:',
migrateVmsSelectSr: 'Select a destination SR:',
migrateVmsSelectSrIntraPool: 'Select a destination SR for local disks:',
migrateVmsSelectNetwork: 'Select a network on which to connect each VIF:',
migrateVmsSmartMapping: 'Smart mapping',
migrateVmName: 'Name',
migrateVmSr: 'SR',
migrateVmVif: 'VIF',
migrateVmNetwork: 'Network',
migrateVmNoTargetHost: 'No target host',
migrateVmNoTargetHostMessage: 'A target host is required to migrate a VM',
migrateVmNoDefaultSrError: 'No default SR',
migrateVmNotConnectedDefaultSrError: 'Default SR not connected to host',
chooseSrForEachVdisModalSelectSr: 'For each VDI, select an SR:',
chooseSrForEachVdisModalMainSr: 'Select main SR…',
chooseSrForEachVdisModalVdiLabel: 'VDI',
chooseSrForEachVdisModalSrLabel: 'SR*',
chooseSrForEachVdisModalOptionalEntry: '* optional',
deleteVmGroupModalTitle: 'Delete VM-Group',
deleteVmGroupModalMessage: 'Are you sure you want to delete this VMGroup ?',
deleteVdiModalTitle: 'Delete VDI',
deleteVdiModalMessage: 'Are you sure you want to delete this disk? ALL DATA ON THIS DISK WILL BE LOST',
revertVmModalTitle: 'Revert your VM',
@@ -1166,11 +1186,6 @@ var messages = {
detachHostModalMessage: 'Are you sure you want to detach {host} from its pool? THIS WILL REMOVE ALL VMs ON ITS LOCAL STORAGE AND REBOOT THE HOST.',
detachHost: 'Detach',
// ----- Forget host -----
forgetHostModalTitle: 'Forget host',
forgetHostModalMessage: 'Are you sure you want to forget {host} from its pool? Be sure this host can\'t be back online, or use detach instead.',
forgetHost: 'Forget',
// ----- Network -----
newNetworkCreate: 'Create network',
newBondedNetworkCreate: 'Create bonded network',

View File

@@ -1,7 +1,8 @@
import React, { Component } from 'react'
import RFB from '@nraynaud/novnc/lib/rfb'
import { createBackoff } from 'jsonrpc-websocket-client'
import { RFB } from 'novnc-node'
import {
format as formatUrl,
parse as parseUrl,
resolve as resolveUrl
} from 'url'
@@ -90,18 +91,14 @@ export default class NoVnc extends Component {
const rfb = this._rfb = new RFB({
encrypt: isSecure,
target: this.refs.canvas,
wsProtocols: [ 'chat' ],
onClipboard: onClipboardChange && ((_, text) => {
onClipboardChange(text)
}),
onUpdateState: this._onUpdateState
})
// remove leading slashes from the path
//
// a leading slassh will be added by noVNC
const clippedPath = url.path.replace(/^\/+/, '')
rfb.connect(url.hostname, url.port, null, clippedPath)
rfb.connect(formatUrl(url))
disableShortcuts()
}

View File

@@ -268,11 +268,6 @@ export const formatSize = bytes => humanFormat(bytes, { scale: 'binary', unit: '
export const formatSizeRaw = bytes => humanFormat.raw(bytes, { scale: 'binary', unit: 'B' })
export const formatSpeed = (bytes, milliseconds) => humanFormat(
bytes * 1e3 / milliseconds,
{ scale: 'binary', unit: 'B/s' }
)
export const parseSize = size => {
let bytes = humanFormat.parse.raw(size, { scale: 'binary' })
if (bytes.unit && bytes.unit !== 'B') {

View File

@@ -8,6 +8,7 @@ import {
find,
flatten,
floor,
forEach,
map,
max,
size,
@@ -16,7 +17,7 @@ import {
} from 'lodash'
import propTypes from '../prop-types-decorator'
import { computeArraysSum } from '../xo-stats'
import { computeArraysSum, computeArraysAvg } from '../xo-stats'
import { formatSize } from '../utils'
import styles from './index.css'
@@ -214,6 +215,54 @@ export const PoolCpuLineChart = injectIntl(propTypes({
)
}))
export const VmGroupCpuLineChart = injectIntl(propTypes({
addSumSeries: propTypes.bool,
data: propTypes.object.isRequired,
options: propTypes.object
})(({ addSumSeries, data, options = {}, intl }) => {
const firstVmData = data[0]
const length = getStatsLength(firstVmData.stats.cpus)
if (!length) {
return templateError
}
const series = map(data, ({ vm, stats }) => ({
name: vm,
data: computeArraysSum(stats.cpus)
}))
if (addSumSeries) {
series.push({
name: intl.formatMessage(messages.vmGroupAllVm),
data: computeArraysSum(map(series, 'data')),
className: styles.dashedLine
})
}
const nbCpusByVm = map(data, ({ stats }) => stats.cpus.length)
return (
<ChartistGraph
type='Line'
data={{
series
}}
options={{
...makeOptions({
intl,
nValues: length,
endTimestamp: firstVmData.endTimestamp,
interval: firstVmData.interval,
valueTransform: value => `${floor(value)}%`
}),
high: 100 * (addSumSeries ? sum(nbCpusByVm) : max(nbCpusByVm)),
...options
}}
/>
)
}))
export const MemoryLineChart = injectIntl(propTypes({
data: propTypes.object.isRequired,
options: propTypes.object
@@ -302,6 +351,57 @@ export const PoolMemoryLineChart = injectIntl(propTypes({
)
}))
export const VmGroupMemoryLineChart = injectIntl(propTypes({
addSumSeries: propTypes.bool,
data: propTypes.object.isRequired,
options: propTypes.object
})(({ addSumSeries, data, options = {}, intl }) => {
const firstVmData = data[0]
const {
memory,
memoryUsed
} = firstVmData.stats
if (!memory || !memoryUsed) {
return templateError
}
const series = map(data, ({ vm, stats }) => ({
name: vm,
data: stats.memoryUsed
}))
if (addSumSeries) {
series.push({
name: intl.formatMessage(messages.vmGroupAllVm),
data: computeArraysSum(map(data, 'stats.memoryUsed')),
className: styles.dashedLine
})
}
const currentMemoryByHost = map(data, ({ stats }) => stats.memory[stats.memory.length - 1])
return (
<ChartistGraph
type='Line'
data={{
series
}}
options={{
...makeOptions({
intl,
nValues: firstVmData.stats.memoryUsed.length,
endTimestamp: firstVmData.endTimestamp,
interval: firstVmData.interval,
valueTransform: formatSize
}),
high: addSumSeries ? sum(currentMemoryByHost) : max(currentMemoryByHost),
...options
}}
/>
)
}))
export const XvdLineChart = injectIntl(propTypes({
addSumSeries: propTypes.bool,
data: propTypes.object.isRequired,
@@ -334,6 +434,60 @@ export const XvdLineChart = injectIntl(propTypes({
)
}))
export const VmGroupXvdLineChart = injectIntl(propTypes({
addSumSeries: propTypes.bool,
data: propTypes.object.isRequired,
options: propTypes.object
})(({ addSumSeries, data, options = {}, intl }) => {
const firstVmData = data[0]
const {
memory,
memoryUsed
} = firstVmData.stats
if (!memory || !memoryUsed) {
return templateError
}
const series = flatten(map(data, ({ stats, vm }) =>
map(stats.xvds, (xvd, key) => {
return {
name: `${vm} (${key})`,
data: computeArraysAvg(stats.xvds[key])
}
})
))
const datas = []
forEach(series, ({ data }) => datas.push(data))
if (addSumSeries) {
series.push({
name: intl.formatMessage(messages.vmGroupAllVm),
data: computeArraysSum(datas),
className: styles.dashedLine
})
}
return (
<ChartistGraph
type='Line'
data={{
series
}}
options={{
...makeOptions({
intl,
nValues: firstVmData.stats.xvds.r.length,
endTimestamp: data.endTimestamp,
interval: data.interval,
valueTransform: formatSize
}),
...options
}}
/>
)
}))
export const VifLineChart = injectIntl(propTypes({
addSumSeries: propTypes.bool,
data: propTypes.object.isRequired,
@@ -443,6 +597,48 @@ export const PoolPifLineChart = injectIntl(propTypes({
)
}))
export const VmGroupVifLineChart = injectIntl(propTypes({
addSumSeries: propTypes.bool,
data: propTypes.object.isRequired,
options: propTypes.object
})(({ addSumSeries, data, options = {}, intl }) => {
const firstVmData = data[0]
const length = firstVmData.stats && getStatsLength(firstVmData.stats.vifs.rx)
if (!length) {
return templateError
}
const series = addSumSeries
? map(ios, io => ({
name: `${intl.formatMessage(messages.vmGroupAllVm)} (${io})`,
data: computeArraysSum(map(data, ({ stats }) => computeArraysSum(stats.vifs[io])))
}))
: flatten(map(data, ({ stats, vm }) =>
map(ios, io => ({
name: `${vm} (${io})`,
data: computeArraysSum(stats.vifs[io])
}))
))
return (
<ChartistGraph
type='Line'
data={{
series
}}
options={{
...makeOptions({
intl,
nValues: length,
endTimestamp: firstVmData.endTimestamp,
interval: firstVmData.interval,
valueTransform: formatSize
}),
...options
}}
/>
)
}))
export const LoadLineChart = injectIntl(propTypes({
data: propTypes.object.isRequired,
options: propTypes.object

View File

@@ -1,139 +0,0 @@
import Collapse from 'collapse'
import Component from 'base-component'
import React from 'react'
import { every, forEach, map } from 'lodash'
import _ from '../../intl'
import propTypes from '../../prop-types-decorator'
import SingleLineRow from '../../single-line-row'
import { createSelector } from '../../selectors'
import { SelectSr } from '../../select-objects'
import { isSrWritable } from 'xo'
import {
Container,
Col
} from 'grid'
// Can 2 SRs on the same pool have 2 VDIs used by the same VM
const areSrsCompatible = (sr1, sr2) =>
sr1.shared || sr2.shared || sr1.$container === sr2.$container
const Collapsible = ({collapsible, children, ...props}) => collapsible
? <Collapse {...props}>{children}</Collapse>
: <div>
<span>{props.buttonText}</span>
<br />
{children}
</div>
Collapsible.propTypes = {
collapsible: propTypes.bool.isRequired,
children: propTypes.node.isRequired
}
@propTypes({
vdis: propTypes.array.isRequired,
predicate: propTypes.func
})
export default class ChooseSrForEachVdisModal extends Component {
state = {
mapVdisSrs: {}
}
componentWillReceiveProps (newProps) {
if (
this.props.predicate !== undefined &&
newProps.predicate !== this.props.predicate
) {
this.state = {
mainSr: undefined,
mapVdisSrs: {}
}
}
}
_onChange = props => {
this.setState(props)
this.props.onChange(props)
}
_onChangeMainSr = newSr => {
const oldSr = this.state.mainSr
if (oldSr == null || newSr == null || oldSr.$pool !== newSr.$pool) {
this.setState({
mapVdisSrs: {}
})
} else if (!newSr.shared) {
const mapVdisSrs = {...this.state.mapVdisSrs}
forEach(mapVdisSrs, (sr, vdi) => {
if (sr != null && newSr !== sr && sr.$container !== newSr.$container && !sr.shared) {
delete mapVdisSrs[vdi]
}
})
this._onChange({mapVdisSrs})
}
this._onChange({
mainSr: newSr
})
}
_getSrPredicate = createSelector(
() => this.state.mainSr,
() => this.state.mapVdisSrs,
(mainSr, mapVdisSrs) => sr =>
isSrWritable(sr) &&
mainSr.$pool === sr.$pool &&
areSrsCompatible(mainSr, sr) &&
every(mapVdisSrs, selectedSr => selectedSr == null || areSrsCompatible(selectedSr, sr))
)
render () {
const { props, state } = this
const { vdis } = props
const {
mainSr,
mapVdisSrs
} = state
const srPredicate = props.predicate || this._getSrPredicate()
return <div>
<SelectSr
onChange={mainSr => props.predicate !== undefined
? this._onChange({mainSr})
: this._onChangeMainSr(mainSr)
}
predicate={props.predicate || isSrWritable}
placeholder={_('chooseSrForEachVdisModalMainSr')}
value={mainSr}
/>
<br />
{vdis != null && mainSr != null &&
<Collapsible collapsible={vdis.length >= 3} buttonText={_('chooseSrForEachVdisModalSelectSr')}>
<br />
<Container>
<SingleLineRow>
<Col size={6}><strong>{_('chooseSrForEachVdisModalVdiLabel')}</strong></Col>
<Col size={6}><strong>{_('chooseSrForEachVdisModalSrLabel')}</strong></Col>
</SingleLineRow>
{map(vdis, vdi =>
<SingleLineRow key={vdi.uuid}>
<Col size={6}>{ vdi.name_label || vdi.name }</Col>
<Col size={6}>
<SelectSr
onChange={sr => this._onChange({ mapVdisSrs: { ...mapVdisSrs, [vdi.uuid]: sr } })}
value={mapVdisSrs[vdi.uuid]}
predicate={srPredicate}
/>
</Col>
</SingleLineRow>
)}
<i>{_('chooseSrForEachVdisModalOptionalEntry')}</i>
</Container>
</Collapsible>
}
</div>
}
}

View File

@@ -48,7 +48,7 @@ export const XEN_VIDEORAM_VALUES = [1, 2, 4, 8, 16]
// ===================================================================
export const isSrWritable = sr => sr && sr.content_type !== 'iso' && sr.size > 0
export const isSrShared = sr => sr && sr.shared
export const isSrShared = sr => sr && sr.$PBDs.length > 1
export const isVmRunning = vm => vm && vm.power_state === 'Running'
// ===================================================================
@@ -275,6 +275,8 @@ export const subscribeIpPools = createSubscription(() => _call('ipPool.getAll'))
export const subscribeResourceCatalog = createSubscription(() => _call('cloud.getResourceCatalog'))
export const subscribeVmGroups = createSubscription(() => _call('vmGroup.get'))
const xosanSubscriptions = {}
export const subscribeIsInstallingXosan = (pool, cb) => {
const poolId = resolveId(pool)
@@ -415,16 +417,6 @@ export const detachHost = host => (
)
)
export const forgetHost = host => (
confirm({
icon: 'host-forget',
title: _('forgetHostModalTitle'),
body: _('forgetHostModalMessage', { host: <strong>{host.name_label}</strong> })
}).then(
() => _call('host.forget', { host: resolveId(host) })
)
)
export const setDefaultSr = sr => (
_call('pool.setDefaultSr', { sr: resolveId(sr) })
)
@@ -962,13 +954,8 @@ export const importBackup = ({ remote, file, sr }) => (
_call('vm.importBackup', resolveIds({ remote, file, sr }))
)
export const importDeltaBackup = ({ remote, file, sr, mapVdisSrs }) => (
_call('vm.importDeltaBackup', resolveIds({
remote,
filePath: file,
sr,
mapVdisSrs: resolveIds(mapVdisSrs)
}))
export const importDeltaBackup = ({ remote, file, sr }) => (
_call('vm.importDeltaBackup', resolveIds({ remote, filePath: file, sr }))
)
import RevertSnapshotModalBody from './revert-snapshot-modal' // eslint-disable-line import/first
@@ -1050,6 +1037,10 @@ export const attachDiskToVm = (vdi, vm, { bootable, mode, position }) => (
})
)
export const removeAppliance = vm => {
_call('vm.removeAppliance', { id: resolveId(vm) })
}
// DISK ---------------------------------------------------------------
export const createDisk = (name, size, sr) => (
@@ -1966,3 +1957,33 @@ export const downloadAndInstallXosanPack = pool =>
)
export const registerXosan = namespace => _call('cloud.registerResource', { namespace: 'xosan' })
// VM-Group ----------------------------------------------------------------------
export const startVmGroup = vmGroup => {
_call('vmGroup.start', { id: resolveId(vmGroup) })
}
export const shutdownVmGroup = vmGroup => _call('vmGroup.shutdown', { id: resolveId(vmGroup) })
export const rebootVmGroup = async vmGroup => {
await shutdownVmGroup(vmGroup)
await startVmGroup(vmGroup)
}
export const editVmGroup = (vmGroup, props) => _call('vmGroup.set', { id: resolveId(vmGroup), ...props })
export const deleteVmGroup = (vmGroup, vms) =>
confirm({
title: _('deleteVmGroupModalTitle'),
body: _('deleteVmGroupModalMessage')
}).then(() => {
forEach(vms, vm => removeAppliance(vm))
_call('vmGroup.destroy', { id: resolveId(vmGroup) })
}, Promise.reject())
export const createVmGroup = ({ pool, name_label, name_description }) => _call('vmGroup.create', { id: resolveId(pool), name_label, name_description })
export const startVmGroups = (vmGroupIds) => {
forEach(vmGroupIds, id => startVmGroup({id: id}))
}
export const shutdownVmGroups = (vmGroupIds) => {
forEach(vmGroupIds, id => shutdownVmGroup({id: id}))
}
export const rebootVmGroups = (vmGroupIds) => {
forEach(vmGroupIds, id => rebootVmGroup({id: id}))
}

View File

@@ -3,23 +3,23 @@ import every from 'lodash/every'
import forEach from 'lodash/forEach'
import find from 'lodash/find'
import map from 'lodash/map'
import mapValues from 'lodash/mapValues'
import React from 'react'
import store from 'store'
import _ from '../../intl'
import ChooseSrForEachVdisModal from '../choose-sr-for-each-vdis-modal'
import invoke from '../../invoke'
import SingleLineRow from '../../single-line-row'
import { Col } from '../../grid'
import { getDefaultNetworkForVif } from '../utils'
import {
SelectHost,
SelectNetwork
SelectNetwork,
SelectSr
} from '../../select-objects'
import {
connectStore,
mapPlus,
resolveIds
mapPlus
} from '../../utils'
import {
createGetObjectsOfType,
@@ -138,8 +138,7 @@ export default class MigrateVmModalBody extends BaseComponent {
get value () {
return {
targetHost: this.state.host && this.state.host.id,
sr: this.state.mainSr && this.state.mainSr.id,
mapVdisSrs: resolveIds(this.state.mapVdisSrs),
mapVdisSrs: this.state.mapVdisSrs,
mapVifsNetworks: this.state.mapVifsNetworks,
migrationNetwork: this.state.migrationNetworkId
}
@@ -159,10 +158,11 @@ export default class MigrateVmModalBody extends BaseComponent {
return
}
const { vbds, vm } = this.props
const { pools, vbds, vdis, vm } = this.props
const intraPool = vm.$pool === host.$pool
// Intra-pool
const defaultSr = pools[host.$pool].default_SR
if (intraPool) {
let doNotMigrateVdis
if (vm.$container === host.id) {
@@ -181,6 +181,7 @@ export default class MigrateVmModalBody extends BaseComponent {
doNotMigrateVdis,
host,
intraPool,
mapVdisSrs: doNotMigrateVdis ? undefined : mapValues(vdis, vdi => defaultSr),
mapVifsNetworks: undefined,
migrationNetwork: undefined
})
@@ -211,6 +212,7 @@ export default class MigrateVmModalBody extends BaseComponent {
doNotMigrateVdis: false,
host,
intraPool,
mapVdisSrs: mapValues(vdis, vdi => defaultSr),
mapVifsNetworks: defaultNetworksForVif,
migrationNetworkId: defaultMigrationNetworkId
})
@@ -224,6 +226,7 @@ export default class MigrateVmModalBody extends BaseComponent {
doNotMigrateVdis,
host,
intraPool,
mapVdisSrs,
mapVifsNetworks,
migrationNetworkId
} = this.state
@@ -242,14 +245,25 @@ export default class MigrateVmModalBody extends BaseComponent {
</div>
{host && !doNotMigrateVdis && <div className={styles.groupBlock}>
<SingleLineRow>
<Col size={12}>
<ChooseSrForEachVdisModal
onChange={props => this.setState(props)}
predicate={this._getSrPredicate()}
vdis={vdis}
/>
</Col>
<Col>{_('migrateVmSelectSrs')}</Col>
</SingleLineRow>
<br />
<SingleLineRow>
<Col size={6}><span className={styles.listTitle}>{_('migrateVmName')}</span></Col>
<Col size={6}><span className={styles.listTitle}>{_('migrateVmSr')}</span></Col>
</SingleLineRow>
{map(vdis, vdi => <div className={styles.listItem} key={vdi.id}>
<SingleLineRow>
<Col size={6}>{vdi.name_label}</Col>
<Col size={6}>
<SelectSr
onChange={sr => this.setState({ mapVdisSrs: { ...mapVdisSrs, [vdi.id]: sr.id } })}
predicate={this._getSrPredicate()}
value={mapVdisSrs[vdi.id]}
/>
</Col>
</SingleLineRow>
</div>)}
</div>}
{intraPool !== undefined &&
(!intraPool &&

View File

@@ -12,10 +12,8 @@ import some from 'lodash/some'
import store from 'store'
import _ from '../../intl'
import Icon from 'icon'
import invoke from '../../invoke'
import SingleLineRow from '../../single-line-row'
import Tooltip from '../../tooltip'
import { Col } from '../../grid'
import { getDefaultNetworkForVif } from '../utils'
import {
@@ -219,7 +217,6 @@ export default class MigrateVmsModalBody extends BaseComponent {
const { pools, pifs } = this.props
const defaultMigrationNetworkId = find(pifs, pif => pif.$host === host.id && pif.management).$network
const defaultSrId = pools[host.$pool].default_SR
const defaultSrConnectedToHost = some(host.$PBDs, pbd => this._getObject(pbd).SR === defaultSrId)
const doNotMigrateVmVdis = {}
const doNotMigrateVdi = {}
forEach(this.props.vbdsByVm, (vbds, vm) => {
@@ -237,8 +234,6 @@ export default class MigrateVmsModalBody extends BaseComponent {
})
const noVdisMigration = every(doNotMigrateVmVdis)
this.setState({
defaultSrConnectedToHost,
defaultSrId,
host,
intraPool: every(this.props.vms, vm => vm.$pool === host.$pool),
doNotMigrateVdi,
@@ -247,7 +242,7 @@ export default class MigrateVmsModalBody extends BaseComponent {
networkId: defaultMigrationNetworkId,
noVdisMigration,
smartVifMapping: true,
srId: defaultSrConnectedToHost ? defaultSrId : undefined
srId: defaultSrId
})
}
_selectMigrationNetwork = migrationNetwork => this.setState({ migrationNetworkId: migrationNetwork.id })
@@ -257,8 +252,6 @@ export default class MigrateVmsModalBody extends BaseComponent {
render () {
const {
defaultSrConnectedToHost,
defaultSrId,
host,
intraPool,
migrationNetworkId,
@@ -297,24 +290,7 @@ export default class MigrateVmsModalBody extends BaseComponent {
{host && (!intraPool || !noVdisMigration) &&
<div key='sr' style={LINE_STYLE}>
<SingleLineRow>
<Col size={6}>
{!intraPool ? _('migrateVmsSelectSr') : _('migrateVmsSelectSrIntraPool')}
{' '}
{(defaultSrId === undefined || !defaultSrConnectedToHost) &&
<Tooltip
content={defaultSrId !== undefined
? _('migrateVmNotConnectedDefaultSrError')
: _('migrateVmNoDefaultSrError')
}
>
<Icon
icon={defaultSrId !== undefined ? 'alarm' : 'info'}
className={defaultSrId !== undefined ? 'text-warning' : 'text-info'}
size='lg'
/>
</Tooltip>
}
</Col>
<Col size={6}>{!intraPool ? _('migrateVmsSelectSr') : _('migrateVmsSelectSrIntraPool')}</Col>
<Col size={6}>
<SelectSr
onChange={this._selectSr}

View File

@@ -452,10 +452,6 @@
@extend .fa-server;
@extend .text-warning;
}
&-forget {
@extend .fa;
@extend .fa-ban;
}
&-working {
@extend .fa;
@extend .fa-circle;

View File

@@ -1,11 +1,8 @@
import _, { messages } from 'intl'
import ChooseSrForEachVdisModal from 'xo/choose-sr-for-each-vdis-modal'
import Component from 'base-component'
import every from 'lodash/every'
import filter from 'lodash/filter'
import find from 'lodash/find'
import forEach from 'lodash/forEach'
import getEventValue from 'get-event-value'
import groupBy from 'lodash/groupBy'
import Icon from 'icon'
import isEmpty from 'lodash/isEmpty'
@@ -18,27 +15,22 @@ import SortedTable from 'sorted-table'
import uniq from 'lodash/uniq'
import Upgrade from 'xoa-upgrade'
import { confirm } from 'modal'
import { createSelector } from 'selectors'
import { addSubscriptions, noop } from 'utils'
import { Container, Row, Col } from 'grid'
import { FormattedDate, injectIntl } from 'react-intl'
import { info, error } from 'notification'
import { SelectPlainObject, Toggle } from 'form'
import { SelectSr } from 'select-objects'
import {
importBackup,
importDeltaBackup,
isSrWritable,
listRemote,
listRemoteBackups,
startVm,
subscribeRemotes
} from 'xo'
// Can 2 SRs on the same pool have 2 VDIs used by the same VM
const areSrsCompatible = (sr1, sr2) =>
sr1.shared || sr2.shared || sr1.$container === sr2.$container
const parseDate = date => +moment(date, 'YYYYMMDDTHHmmssZ').format('x')
const backupOptionRenderer = backup => <span>
@@ -84,8 +76,8 @@ const openImportModal = ({ backups }) => confirm({
body: <ImportModalBody vmName={backups[0].name} backups={backups} />
}).then(doImport)
const doImport = ({ backup, mainSr, start, mapVdisSrs }) => {
if (!mainSr || !backup) {
const doImport = ({ backup, sr, start }) => {
if (!sr || !backup) {
error(_('backupRestoreErrorTitle'), _('backupRestoreErrorMessage'))
return
}
@@ -95,7 +87,7 @@ const doImport = ({ backup, mainSr, start, mapVdisSrs }) => {
}
info(_('importBackupTitle'), _('importBackupMessage'))
try {
const importPromise = importMethods[backup.type]({remote: backup.remoteId, sr: mainSr, file: backup.path, mapVdisSrs}).then(id => {
const importPromise = importMethods[backup.type]({remote: backup.remoteId, sr, file: backup.path}).then(id => {
return id
})
if (start) {
@@ -107,59 +99,16 @@ const doImport = ({ backup, mainSr, start, mapVdisSrs }) => {
}
class _ModalBody extends Component {
constructor () {
super()
this.state = {
mapVdisSrs: {}
}
}
get value () {
return this.state
}
_getSrPredicate = createSelector(
() => this.state.sr,
() => this.state.mapVdisSrs,
(defaultSr, mapVdisSrs) => sr =>
sr !== defaultSr &&
isSrWritable(sr) &&
defaultSr.$pool === sr.$pool &&
areSrsCompatible(defaultSr, sr) &&
every(mapVdisSrs, selectedSr => selectedSr == null || areSrsCompatible(selectedSr, sr))
)
_onChangeDefaultSr = event => {
const oldSr = this.state.sr
const newSr = getEventValue(event)
if (oldSr == null || newSr == null || oldSr.$pool !== newSr.$pool) {
this.setState({
mapVdisSrs: {}
})
} else if (!newSr.shared) {
const mapVdisSrs = {...this.state.mapVdisSrs}
forEach(mapVdisSrs, (sr, vdi) => {
if (sr != null && newSr !== sr && sr.$container !== newSr.$container && !sr.shared) {
delete mapVdisSrs[vdi]
}
})
this.setState({
mapVdisSrs
})
}
this.setState({
sr: newSr
})
}
render () {
const { backups, intl } = this.props
const vdis = this.state.backup && this.state.backup.vdis
return <div>
<SelectSr onChange={this.linkState('sr')} predicate={isSrWritable} />
<br />
<SelectPlainObject
onChange={this.linkState('backup')}
optionKey='path'
@@ -168,11 +117,6 @@ class _ModalBody extends Component {
placeholder={intl.formatMessage(messages.importBackupModalSelectBackup)}
/>
<br />
<ChooseSrForEachVdisModal
vdis={vdis}
onChange={props => this.setState(props)}
/>
<br />
<Toggle onChange={this.linkState('start')} /> {_('importBackupModalStart')}
</div>
}
@@ -192,26 +136,16 @@ export default class Restore extends Component {
}
_listAll = async remotes => {
const remotesInfo = await Promise.all(map(remotes, async remote => ({
files: await listRemote(remote.id),
backupsInfo: await listRemoteBackups(remote.id)
})))
const remotesFiles = await Promise.all(map(remotes, remote => listRemote(remote.id)))
const backupInfoByVm = {}
forEach(remotesInfo, (remoteInfo, index) => {
forEach(remotesFiles, (remoteFiles, index) => {
const remote = remotes[index]
forEach(remoteInfo.files, file => {
forEach(remoteFiles, file => {
let backup
const deltaInfo = /^vm_delta_(.*)_([^/]+)\/([^_]+)_(.*)$/.exec(file)
if (deltaInfo) {
const [ , tag, id, date, name ] = deltaInfo
const vdis = find(remoteInfo.backupsInfo, {
id: `${file}.json`
}).disks
backup = {
type: 'delta',
date: parseDate(date),
@@ -220,8 +154,7 @@ export default class Restore extends Component {
path: file,
tag,
remoteId: remote.id,
remoteName: remote.name,
vdis
remoteName: remote.name
}
} else {
const backupInfo = /^([^_]+)_([^_]+)_(.*)\.xva$/.exec(file)

View File

@@ -42,12 +42,15 @@ import {
forgetSrs,
isSrShared,
migrateVms,
rebootVmGroups,
reconnectAllHostsSrs,
rescanSrs,
restartHosts,
restartHostsAgents,
restartVms,
shutdownVmGroups,
snapshotVms,
startVmGroups,
startVms,
stopHosts,
stopVms,
@@ -86,6 +89,7 @@ import {
import styles from './index.css'
import HostItem from './host-item'
import PoolItem from './pool-item'
import VmGroupItem from './vm-group-item'
import VmItem from './vm-item'
import TemplateItem from './template-item'
import SrItem from './sr-item'
@@ -150,6 +154,20 @@ const OPTIONS = {
{ labelId: 'homeSortByCpus', sortBy: 'CPUs.number', sortOrder: 'desc' }
]
},
'VmGroup': {
defaultFilter: '',
filters: homeFilters.vmGroup,
mainActions: [
{ handler: shutdownVmGroups, icon: 'vm-stop', tooltip: _('stopVmLabel') },
{ handler: startVmGroups, icon: 'vm-start', tooltip: _('startVmLabel') },
{ handler: rebootVmGroups, icon: 'vm-reboot', tooltip: _('rebootVmLabel') }
],
Item: VmGroupItem,
sortOptions: [
{ labelId: 'homeSortByName', sortBy: 'name_label', sortOrder: 'asc' },
{ labelId: 'homeSortByPowerstate', sortBy: 'power_state', sortOrder: 'desc' }
]
},
pool: {
defaultFilter: '',
filters: homeFilters.pool,
@@ -196,6 +214,7 @@ const OPTIONS = {
const TYPES = {
VM: _('homeTypeVm'),
VmGroup: _('homeTypeVmGroup'),
'VM-template': _('homeTypeVmTemplate'),
host: _('homeTypeHost'),
pool: _('homeTypePool'),
@@ -212,14 +231,18 @@ const DEFAULT_TYPE = 'VM'
createGetObjectsOfType('host'),
hosts => state => isEmpty(hosts(state))
)
const type = (_, props) => props.location.query.t || DEFAULT_TYPE
const getType = (_, props) => props.location.query.t || DEFAULT_TYPE
const getObjectsByType = createGetObjectsOfType(getType)
return {
areObjectsFetched,
items: createGetObjectsOfType(type),
noServersConnected,
type,
user: getUser
return (state, props) => {
const type = getType(state, props)
return {
areObjectsFetched: areObjectsFetched(state, props),
items: getObjectsByType(state, props),
noServersConnected: noServersConnected(state, props),
type,
user: getUser(state, props)
}
}
})
export default class Home extends Component {
@@ -806,7 +829,7 @@ export default class Home extends Component {
</OverlayTrigger>
)}
{' '}
<OverlayTrigger
{type !== 'VmGroup' && <OverlayTrigger
autoFocus
trigger='click'
rootClose
@@ -824,7 +847,7 @@ export default class Home extends Component {
}
>
<Button btnStyle='link'><Icon icon='tags' /> {_('homeAllTags')}</Button>
</OverlayTrigger>
</OverlayTrigger> }
{' '}
<DropdownButton bsStyle='link' id='sort' title={_('homeSortBy')}>
{map(options.sortOptions, ({ labelId, sortBy: _sortBy, sortOrder }, key) => (

View File

@@ -0,0 +1,77 @@
import _ from 'intl'
import Component from 'base-component'
import Ellipsis, { EllipsisContainer } from 'ellipsis'
import forEach from 'lodash/forEach'
import Icon from 'icon'
import isEmpty from 'lodash/isEmpty'
import map from 'lodash/map'
import React from 'react'
import SingleLineRow from 'single-line-row'
import Tooltip from 'tooltip'
import { BlockLink } from 'link'
import { Col } from 'grid'
import { connectStore } from 'utils'
import { createGetObject } from 'selectors'
import { editVmGroup } from 'xo'
import { Text } from 'editable'
import styles from './index.css'
@connectStore(() => {
return (state, props) => {
const vms = {}
forEach(props.item.$VMs, vmId => {
const getVM = createGetObject(() => vmId)
vms[vmId] = getVM(state, props)
})
return {
vms
}
}
})
export default class VmGroupItem extends Component {
toggleState = stateField => () => this.setState({ [stateField]: !this.state[stateField] })
_onSelect = () => this.props.onSelect(this.props.item.id)
_setNameDescription = description => editVmGroup(this.props.item, {name_description: description})
_setNameLabel = label => editVmGroup(this.props.item, {name_label: label})
_getVmGroupState = (vmGroup) => {
const states = map(this.props.vms, vm => vm.power_state)
return isEmpty(states)
? 'Busy'
: states.indexOf('Halted') === -1
? states[0]
: states.indexOf('Running') === -1
? states[0]
: 'Busy'
}
render () {
const { item: vmGroup, selected, vms } = this.props
return <div className={styles.item}>
<BlockLink to={`/vm-group/${vmGroup.id}`}>
<SingleLineRow>
<Col smallSize={10} mediumSize={9} largeSize={3}>
<EllipsisContainer>
<input type='checkbox' checked={selected} onChange={this._onSelect} value={vmGroup.id} />
&nbsp;&nbsp;
<Ellipsis>
<Tooltip content={_(`powerStateVmGroup${this._getVmGroupState(vmGroup)}`)}>
<Icon icon={isEmpty(vms) ? 'halted' : `${this._getVmGroupState(vmGroup).toLowerCase()}`} />
</Tooltip>
<Text value={vmGroup.name_label} onChange={this._setNameLabel} useLongClick />
</Ellipsis>
&nbsp;&nbsp;
</EllipsisContainer>
</Col>
<Col mediumSize={4} className='hidden-md-down'>
<EllipsisContainer>
<Ellipsis>
<Text value={vmGroup.name_description} onChange={this._setNameDescription} useLongClick />
</Ellipsis>
</EllipsisContainer>
</Col>
</SingleLineRow>
</BlockLink>
</div>
}
}

View File

@@ -54,6 +54,11 @@ export default class VmItem extends Component {
return vm && vm.power_state === 'Running'
}
_getMigrationPredicate = createSelector(
() => this.props.container,
container => host => host.id !== container.id
)
_getResourceSet = createFinder(
() => this.props.resourceSets,
createSelector(
@@ -139,6 +144,7 @@ export default class VmItem extends Component {
labelProp='name_label'
onChange={this._migrateVm}
placeholder={_('homeMigrateTo')}
predicate={this._getMigrationPredicate()}
useLongClick
value={container}
xoType='host'

View File

@@ -5,7 +5,7 @@ import TabButton from 'tab-button'
import SelectFiles from 'select-files'
import Upgrade from 'xoa-upgrade'
import { Toggle } from 'form'
import { enableHost, detachHost, disableHost, forgetHost, restartHost, installSupplementalPack } from 'xo'
import { enableHost, detachHost, disableHost, restartHost, installSupplementalPack } from 'xo'
import { FormattedRelative, FormattedTime } from 'react-intl'
import { Container, Row, Col } from 'grid'
import {
@@ -59,15 +59,6 @@ export default ({
icon='host-eject'
labelId='detachHost'
/>
{host.power_state !== 'Running' &&
<TabButton
btnStyle='danger'
handler={forgetHost}
handlerParam={host}
icon='host-forget'
labelId='forgetHost'
/>
}
</Col>
</Row>
<Row>

View File

@@ -92,6 +92,7 @@ export default class extends Component {
<Row className='console'>
<Col>
<NoVnc ref='noVnc' url={resolveUrl(`consoles/${vmController.id}`)} onClipboardChange={this._getRemoteClipboard} />
<p><em><Icon icon='info' /> {_('tipLabel')} {_('tipConsoleLabel')}</em></p>
</Col>
</Row>
</Container>

View File

@@ -36,6 +36,7 @@ import Sr from './sr'
import Tasks from './tasks'
import User from './user'
import Vm from './vm'
import VmGroup from './vm-group'
import VmImport from './vm-import'
import XoaUpdates from './xoa-updates'
import Xosan from './xosan'
@@ -86,6 +87,7 @@ const BODY_STYLE = {
'vms/import': VmImport,
'vms/new': NewVm,
'vms/:id': Vm,
'vm-group/:id': VmGroup,
'xoa-update': XoaUpdates,
'xosan': Xosan
})

View File

@@ -15,13 +15,10 @@ import renderXoItem from 'render-xo-item'
import SortedTable from 'sorted-table'
import Tooltip from 'tooltip'
import { alert, confirm } from 'modal'
import { connectStore } from 'utils'
import { createGetObject } from 'selectors'
import { FormattedDate } from 'react-intl'
import {
connectStore,
formatSize,
formatSpeed
} from 'utils'
import {
Card,
CardHeader,
@@ -73,33 +70,9 @@ class JobReturn extends Component {
}
}
const JobCallStateInfos = ({ end, error }) => {
const [ icon, tooltip ] = error !== undefined
? ['halted', 'failedJobCall']
: end !== undefined
? ['running', 'successfulJobCall']
: ['busy', 'jobCallInProgess']
return <Tooltip content={_(tooltip)}>
<Icon icon={icon} />
</Tooltip>
}
const JobTransferredDataInfos = ({ start, end, size }) => <div>
<span><strong>{_('jobTransferredDataSize')}</strong> {formatSize(size)}</span>
<br />
<span><strong>{_('jobTransferredDataSpeed')}</strong> {formatSpeed(size, end - start)}</span>
</div>
const Log = props => <ul className='list-group'>
{map(props.log.calls, call => {
const {
end,
error,
returnedValue,
start
} = call
const { returnedValue } = call
let id
if (returnedValue != null) {
id = returnedValue.id
@@ -109,9 +82,8 @@ const Log = props => <ul className='list-group'>
}
return <li key={call.callKey} className='list-group-item'>
<strong className='text-info'>{call.method}: </strong><JobCallStateInfos end={end} error={error} /><br />
<strong className='text-info'>{call.method}: </strong><br />
{map(call.params, (value, key) => [ <JobParam id={value} paramKey={key} key={key} />, <br /> ])}
{returnedValue != null && returnedValue.size !== undefined && <JobTransferredDataInfos start={start} end={end} size={returnedValue.size} />}
{id !== undefined && <span>{' '}<JobReturn id={id} /></span>}
{call.error &&
<span className='text-danger'>
@@ -236,7 +208,6 @@ export default class LogList extends Component {
callKey: logKey,
params: data.params,
method: data.method,
start: time,
time
}
} else if (data.event === 'jobCall.end') {
@@ -248,7 +219,6 @@ export default class LogList extends Component {
entry.meta = 'error'
} else {
call.returnedValue = data.returnedValue
call.end = time
}
}
}

View File

@@ -127,6 +127,7 @@ export default class Menu extends Component {
const items = [
{ to: '/home', icon: 'menu-home', label: 'homePage', subMenu: [
{ to: '/home?t=VM', icon: 'vm', label: 'homeVmPage' },
{ to: '/home?t=VmGroup', icon: 'vm', label: 'homeVmGroupPage' },
nHosts !== 0 && { to: '/home?t=host', icon: 'host', label: 'homeHostPage' },
!isEmpty(pools) && { to: '/home?t=pool', icon: 'pool', label: 'homePoolPage' },
isAdmin && { to: '/home?t=VM-template', icon: 'template', label: 'homeTemplatePage' },
@@ -167,6 +168,7 @@ export default class Menu extends Component {
isAdmin && { to: '/xosan', icon: 'menu-xosan', label: 'xosan' },
!(noOperatablePools && noResourceSets) && { to: '/vms/new', icon: 'menu-new', label: 'newMenu', subMenu: [
{ to: '/vms/new', icon: 'menu-new-vm', label: 'newVmPage' },
{ to: '/new/vm-group', icon: 'menu-new-vm', label: 'newVmGroupPage' },
isAdmin && { to: '/new/sr', icon: 'menu-new-sr', label: 'newSrPage' },
isAdmin && { to: '/settings/servers', icon: 'menu-settings-servers', label: 'newServerPage' },
!noOperatablePools && { to: '/vms/import', icon: 'menu-new-import', label: 'newImport' }

View File

@@ -1,9 +1,11 @@
import { routes } from 'utils'
import Sr from './sr'
import VmGroup from './vm-group'
const New = routes('vm', {
sr: Sr
sr: Sr,
'vm-group': VmGroup
})(
({ children }) => children
)

View 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}&nbsp;</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 VmGroup 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>
)
}
}

View File

@@ -312,15 +312,15 @@ export class Edit extends Component {
// -----------------------------------------------------------------------------
_onChangeIpPool = newIpPool => {
const { ipPools, newIpPoolQuantity } = this.state
_addIpPool = () => {
const { ipPools, newIpPool, newIpPoolQuantity } = this.state
this.setState({
ipPools: [ ...ipPools, { id: newIpPool.id, quantity: newIpPoolQuantity } ],
newIpPool: undefined,
newIpPoolQuantity: ''
})
}
_removeIpPool = index => {
const ipPools = [ ...this.state.ipPools ]
remove(ipPools, (_, i) => index === i)
@@ -444,30 +444,33 @@ export class Edit extends Component {
<Row>
<Col mediumSize={4}>
<Row>
<Col mediumSize={3}>
<strong>{_('quantity')}</strong>
</Col>
<Col mediumSize={7}>
<strong>{_('ipPool')}</strong>
</Col>
<Col mediumSize={3}>
<strong>{_('quantity')}</strong>
</Col>
</Row>
{map(state.ipPools, (ipPool, index) => <Row className='mb-1' key={index}>
<Col mediumSize={3}>
<input className='form-control' type='number' min={0} onChange={this.linkState(`ipPools.${index}.quantity`)} value={firstDefined(ipPool.quantity, '')} placeholder='∞' />
</Col>
<Col mediumSize={7}>
<SelectIpPool onChange={this.linkState(`ipPools.${index}.id`, 'id')} value={ipPool.id} />
</Col>
<Col mediumSize={3}>
<input className='form-control' type='number' min={0} onChange={this.linkState(`ipPools.${index}.quantity`)} value={firstDefined(ipPool.quantity, '')} placeholder='∞' />
</Col>
<Col mediumSize={2}>
<ActionButton icon='delete' handler={this._removeIpPool} handlerParam={index} />
</Col>
</Row>)}
<Row>
<Col mediumSize={7}>
<SelectIpPool onChange={this.linkState('newIpPool')} value={state.newIpPool} predicate={this._getIpPoolPredicate()} />
</Col>
<Col mediumSize={3}>
<input className='form-control' type='number' min={0} onChange={this.linkState('newIpPoolQuantity')} value={state.newIpPoolQuantity || ''} placeholder='∞' />
</Col>
<Col mediumSize={7}>
<SelectIpPool onChange={this._onChangeIpPool} value='' predicate={this._getIpPoolPredicate()} />
<Col mediumSize={2}>
<ActionButton icon='add' handler={this._addIpPool} />
</Col>
</Row>
</Col>

View File

@@ -0,0 +1,53 @@
import ActionBar from 'action-bar'
import React from 'react'
import { connectStore } from 'utils'
import { includes } from 'lodash'
import { isAdmin } from 'selectors'
import {
rebootVmGroup,
startVmGroup,
shutdownVmGroup
} from 'xo'
const vmGroupActionBarByState = ({ isAdmin, vmGroup }) => {
const actions = []
if (vmGroup.allowed_operations.includes('start') || vmGroup.allowed_operations.length === 0) {
actions.push({
icon: 'vm-start',
label: 'startVmLabel',
handler: startVmGroup,
pending: includes(vmGroup.current_operations, 'start')
})
}
if (vmGroup.allowed_operations.includes('shutdown') || vmGroup.allowed_operations.length === 0) {
actions.push({
icon: 'vm-stop',
label: 'stopVmLabel',
handler: shutdownVmGroup,
pending: includes(vmGroup.current_operations, 'shutdown')
})
}
actions.push({
icon: 'vm-reboot',
label: 'rebootVmLabel',
handler: rebootVmGroup,
pending: includes(vmGroup.current_operations, 'shutdown') || includes(vmGroup.current_operations, 'start')
})
return <ActionBar
actions={actions}
display='icon'
param={vmGroup}
/>
}
const VmGroupActionBar = connectStore({
isAdmin
})(({ isAdmin, vmGroup }) => {
const ActionBar = vmGroupActionBarByState
if (!ActionBar) {
return <p>No action bar for state</p>
}
return <ActionBar isAdmin={isAdmin} vmGroup={vmGroup} />
})
export default VmGroupActionBar

View File

@@ -0,0 +1,131 @@
import _ from 'intl'
import BaseComponent from 'base-component'
import Icon from 'icon'
import isEmpty from 'lodash/isEmpty'
import React, { cloneElement } from 'react'
import {
connectStore,
routes
} from 'utils'
import {
assign,
forEach,
map,
pick
} from 'lodash'
import { Container, Row, Col } from 'grid'
import { createGetObject } from 'selectors'
import { editVmGroup } from 'xo'
import { NavLink, NavTabs } from 'nav'
import { Text } from 'editable'
import Page from '../page'
import TabAdvanced from './tab-advanced'
import TabGeneral from './tab-general'
import TabManagement from './tab-management'
import TabStats from './tab-stats'
import VmGroupActionBar from './action-bar'
// ===================================================================
@routes('general', {
advanced: TabAdvanced,
general: TabGeneral,
management: TabManagement,
stats: TabStats
})
@connectStore(() => {
const getVmGroup = createGetObject()
return (state, props) => {
const vmGroup = getVmGroup(state, props)
if (!vmGroup) {
return {}
}
const vms = {}
forEach(vmGroup.$VMs, vmId => {
const getVM = createGetObject(() => vmId)
vms[vmId] = getVM(state, props)
})
return {
vmGroup,
vms
}
}
})
export default class VmGroup extends BaseComponent {
static contextTypes = {
router: React.PropTypes.object
}
_setNameDescription = description => editVmGroup(this.props.vmGroup, {name_description: description})
_setNameLabel = label => editVmGroup(this.props.vmGroup, {name_label: label})
_getVmGroupState = () => {
const states = map(this.props.vms, vm => vm.power_state)
return (isEmpty(states)
? 'busy'
: states.indexOf('Halted') === -1
? states[0]
: states.indexOf('Running') === -1
? states[0]
: 'busy').toLowerCase()
}
header () {
const { vmGroup, vms } = this.props
if (!vmGroup) {
return <Icon icon='loading' />
}
return <Container>
<Row>
<Col mediumSize={6} className='header-title'>
<h2>
<Icon icon={isEmpty(vms) ? `vm-halted` : `vm-${this._getVmGroupState()}`} />
{' '}
<Text value={vmGroup.name_label} onChange={this._setNameLabel} />
</h2>
<span>
<Text
value={vmGroup.name_description}
onChange={this._setNameDescription}
/>
<span className='text-muted'>
{' '}
</span>
</span>
</Col>
<Col mediumSize={6} className='text-xs-center'>
<div>
<VmGroupActionBar vmGroup={vmGroup} />
</div>
</Col>
</Row>
<br />
<Row>
<Col>
<NavTabs>
<NavLink to={`/vm-group/${vmGroup.id}/general`}>{_('generalTabName')}</NavLink>
<NavLink to={`/vm-group/${vmGroup.id}/stats`}>{_('statsTabName')}</NavLink>
<NavLink to={`/vm-group/${vmGroup.id}/management`}>{_('managementTabName')}</NavLink>
<NavLink to={`/vm-group/${vmGroup.id}/advanced`}>{_('advancedTabName')}</NavLink>
</NavTabs>
</Col>
</Row>
</Container>
}
render () {
const { container, vmGroup } = this.props
if (!vmGroup) {
return <h1>{_('statusLoading')}</h1>
}
const childProps = assign(pick(this.props, [
'vmGroup',
'vms'
]))
return <Page header={this.header()} title={`${vmGroup.name_label}${container ? ` (${container.name_label})` : ''}`}>
{cloneElement(this.props.children, { ...childProps })}
</Page>
}
}

View File

@@ -0,0 +1,55 @@
import _ from 'intl'
import Component from 'base-component'
import Copiable from 'copiable'
import React from 'react'
import TabButton from 'tab-button'
import { Container, Row, Col } from 'grid'
import { deleteVmGroup } from 'xo'
import { noop } from 'utils'
export default class TabAdvanced extends Component {
static contextTypes = {
router: React.PropTypes.object
}
_deleteVmGroup = (vmGroup, vms) => {
deleteVmGroup(vmGroup, vms).then(
() => this.context.router.push('home?s=&t=VmGroup'),
noop
)
}
render () {
const { vmGroup, vms } = this.props
return (
<Container>
<Row>
<Col className='text-xs-right'>
<TabButton
btnStyle='danger'
handler={() => this._deleteVmGroup(vmGroup, vms)}
icon='vm-delete'
labelId='vmRemoveButton'
/>
</Col>
<div>
<h3>{_('xenSettingsLabel')}</h3>
{ vmGroup &&
<table className='table'>
<tbody>
<tr>
<th>{_('uuid')}</th>
<Copiable tagName='td'>
{vmGroup.id}
</Copiable>
</tr>
</tbody>
</table>
}
</div>
</Row>
</Container>
)
}
}

View File

@@ -0,0 +1,67 @@
import _ from 'intl'
import forEach from 'lodash/forEach'
import Icon from 'icon'
import isEmpty from 'lodash/isEmpty'
import map from 'lodash/map'
import reduce from 'lodash/reduce'
import React from 'react'
import size from 'lodash/size'
import { connectStore, formatSize } from 'utils'
import { Container, Row, Col } from 'grid'
import { getObject } from 'selectors'
export default connectStore(() => {
const getMemoryTotal = (state, props) => {
const vdiIds = new Set()
forEach(props.vms, vm => forEach(vm.$VBDs, vbdId => vdiIds.add(getObject(state, vbdId).VDI)))
return reduce(Array.from(vdiIds), (sum, vdiId) => {
const vdi = getObject(state, vdiId)
return vdi !== undefined
? sum + vdi.size
: sum
}, 0)
}
const getMemoryDynamicTotal = props => reduce(props.vms, (sum, vm) => vm.memory.dynamic[1] + sum, 0)
const getNbCPU = props => reduce(props.vms, (sum, vm) => vm.CPUs.number + sum, 0)
return (state, props) => ({
memoryTotal: getMemoryTotal(state, props),
memoryDynamical: getMemoryDynamicTotal(props),
nbCPU: getNbCPU(props)
})
})(({ vms, memoryTotal, memoryDynamical, nbCPU, vmGroup }) => {
return (
<Container>
<br />
<div>
<Row className='text-xs-center'>
<Col mediumSize={3}>
<h2>{size(vms)}x <Icon icon='vm' size='lg' /></h2>
</Col>
<Col mediumSize={3}>
<h2>{nbCPU}x <Icon icon='cpu' size='lg' /></h2>
</Col>
<Col mediumSize={3}>
<h2 className='form-inline'>
{formatSize(memoryDynamical)}
&nbsp;<span><Icon icon='memory' size='lg' /></span>
</h2>
</Col>
<Col mediumSize={3}>
<h2>{formatSize(memoryTotal)} <Icon icon='disk' size='lg' /></h2>
</Col>
</Row>
{isEmpty(vmGroup.current_operations)
? null
: <Row className='text-xs-center'>
<Col>
<h4>{_('vmGroupCurrentStatus')}{' '}{map(vmGroup.current_operations)[0]}</h4>
</Col>
</Row>
}
</div>
</Container>
)
})

View File

@@ -0,0 +1,145 @@
import _ from 'intl'
import ActionButton from 'action-button'
import ActionRowButton from 'action-row-button'
import Component from 'base-component'
import DragNDropOrder from 'drag-n-drop-order'
import forEach from 'lodash/forEach'
import Icon from 'icon'
import isEmpty from 'lodash/isEmpty'
import Link from 'link'
import map from 'lodash/map'
import React from 'react'
import sortBy from 'lodash/sortBy'
import SortedTable from 'sorted-table'
import TabButton from 'tab-button'
import Tooltip from 'tooltip'
import { editVm, removeAppliance } from 'xo'
import { Row, Col } from 'grid'
import { SelectVm } from 'select-objects'
const VM_COLUMNS = [
{
name: _('vmGroupLabel'),
itemRenderer: vm => (<span><Tooltip
content={isEmpty(vm.current_operations)
? _(`powerState${vm.power_state}`)
: <div>{_(`powerState${vm.power_state}`)}{' ('}{map(vm.current_operations)[0]}{')'}</div>
}
>
{isEmpty(vm.current_operations)
? <Icon icon={`${vm.power_state.toLowerCase()}`} />
: <Icon icon='busy' />
}
</Tooltip>
&nbsp;
<Link to={`/vms/${vm.id}`}>
{vm.name_label}
</Link>
</span>),
sortCriteria: vm => vm.name_label
},
{
name: _('vmGroupDescription'),
itemRenderer: vm => vm.name_description,
sortCriteria: vm => vm.name_description
},
{
name: _('vmGroupActions'),
itemRenderer: vm => (
<ActionRowButton
btnStyle='danger'
handler={(vm) => removeAppliance(vm)}
handlerParam={vm}
icon='delete'
/>
)
}
]
export default class TabManagement extends Component {
constructor (props) {
super(props)
this.state = {
attachVm: false,
bootOrder: false
}
}
parseBootOrder = vms => {
// FIXME missing translation
var previousOrder = vms[Object.keys(vms)[0]].order
var toggleActive = false
const orderVms = sortBy(vms, vm => {
if (vm.order !== previousOrder) toggleActive = true
return vm.order
})
const order = []
forEach(orderVms, vm => {
order.push({id: vm.id, text: vm.name_label})
})
return {order, toggleActive}
}
setVmBootOrder = (vms, order, toggleActive) => {
var orderValue = 0
forEach(order, (vm, key) => {
editVm(vms[vm.id], { order: toggleActive ? orderValue : 0 })
orderValue += 1
})
}
_addVm = () => {
forEach(this.state.vmsToAdd, vm => editVm(vm, { appliance: this.props.vmGroup.id }))
}
_selectVm = vmsToAdd => this.setState({vmsToAdd})
_toggleBootOrder = () => this.setState({
bootOrder: !this.state.bootOrder,
attachVm: false
})
_toggleNewVm = () => this.setState({
attachVm: !this.state.attachVm,
bootOrder: false
})
_vmPredicate = vm => vm.appliance === null
render () {
const { vms } = this.props
const { attachVm, bootOrder } = this.state
return isEmpty(vms)
? <form id='attachVm'>
<SelectVm multi onChange={this._selectVm} predicate={this._vmPredicate} required />
<span className='pull-right'>
<ActionButton form='attachVm' icon='add' btnStyle='primary' handler={this._addVm}>{_('add')}</ActionButton>
</span>
</form>
: (<div>
<Row>
<Col className='text-xs-right'>
<TabButton
btnStyle={attachVm ? 'info' : 'primary'}
handler={this._toggleNewVm}
icon='add'
labelId='attachVmButton'
/>
<TabButton
btnStyle={bootOrder ? 'info' : 'primary'}
handler={this._toggleBootOrder}
icon='sort'
labelId='vmsBootOrder'
/>
</Col>
</Row>
{bootOrder && <div><DragNDropOrder parseOrderParam={vms} parseOrder={this.parseBootOrder} setOrder={this.setVmBootOrder} toggleItems={false} onClose={this._toggleBootOrder} /><hr /></div>}
{attachVm && <div>
<form id='attachVm'>
<SelectVm multi onChange={this._selectVm} predicate={this._vmPredicate} required />
<span className='pull-right'>
<ActionButton form='attachVm' icon='add' btnStyle='primary' handler={this._addVm}>{_('add')}</ActionButton>
</span>
</form>
</div>}
<SortedTable collection={vms} columns={VM_COLUMNS} />
</div>
)
}
}

View File

@@ -0,0 +1,138 @@
import _ from 'intl'
import Component from 'base-component'
import filter from 'lodash/filter'
import Icon from 'icon'
import map from 'lodash/map'
import React from 'react'
import Tooltip from 'tooltip'
import Upgrade from 'xoa-upgrade'
import { Container, Row, Col } from 'grid'
import { Toggle } from 'form'
import { fetchVmStats } from 'xo'
import {
VmGroupCpuLineChart,
VmGroupMemoryLineChart,
VmGroupVifLineChart,
VmGroupXvdLineChart
} from 'xo-line-chart'
export default class TabStats extends Component {
constructor (props) {
super(props)
this.state.useCombinedValues = false
}
loop (vmGroup = this.props.vmGroup) {
if (this.cancel) {
this.cancel()
}
let cancelled = false
this.cancel = () => { cancelled = true }
Promise.all(map(filter(this.props.vms, vm => vm.power_state === 'Running'), vm =>
fetchVmStats(vm, this.state.granularity).then(
stats => ({
vm: vm.name_label,
...stats
})
)
)).then(stats => {
if (cancelled || !stats[0]) {
return
}
this.cancel = null
clearTimeout(this.timeout)
this.setState({
stats,
selectStatsLoading: false
}, () => {
this.timeout = setTimeout(this.loop, stats[0].interval * 1000)
})
})
}
loop = ::this.loop
handleSelectStats (event) {
const granularity = event.target.value
clearTimeout(this.timeout)
this.setState({
granularity,
selectStatsLoading: true
}, this.loop)
}
handleSelectStats = ::this.handleSelectStats
componentWillMount () {
this.loop()
}
componentWillUnmount () {
clearTimeout(this.timeout)
}
render () {
const {
granularity,
selectStatsLoading,
stats,
useCombinedValues
} = this.state
return !stats
? <p>No stats.</p>
: process.env.XOA_PLAN > 2
? <Container>
<Row>
<Col mediumSize={5}>
<div className='form-group'>
<Tooltip content={_('useStackedValuesOnStats')}>
<Toggle value={useCombinedValues} onChange={this.linkState('useCombinedValues')} />
</Tooltip>
</div>
</Col>
<Col mediumSize={1}>
{selectStatsLoading && (
<div className='text-xs-right'>
<Icon icon='loading' size={2} />
</div>
)}
</Col>
<Col mediumSize={6}>
<div className='btn-tab'>
<select className='form-control' onChange={this.handleSelectStats} defaultValue={granularity} >
{_('statLastTenMinutes', message => <option value='seconds'>{message}</option>)}
{_('statLastTwoHours', message => <option value='minutes'>{message}</option>)}
{_('statLastWeek', message => <option value='hours'>{message}</option>)}
{_('statLastYear', message => <option value='days'>{message}</option>)}
</select>
</div>
</Col>
</Row>
<Row>
<Col mediumSize={6}>
<h5 className='text-xs-center'><Icon icon='cpu' size={1} /> {_('statsCpu')}</h5>
<VmGroupCpuLineChart addSumSeries={useCombinedValues} data={stats} />
</Col>
<Col mediumSize={6}>
<h5 className='text-xs-center'><Icon icon='memory' size={1} /> {_('statsMemory')}</h5>
<VmGroupMemoryLineChart addSumSeries={useCombinedValues} data={stats} />
</Col>
</Row>
<br />
<hr />
<Row>
<Col mediumSize={6}>
<h5 className='text-xs-center'><Icon icon='network' size={1} /> {_('statsNetwork')}</h5>
<VmGroupVifLineChart key={useCombinedValues ? 'stacked' : 'unstacked'} addSumSeries={useCombinedValues} data={stats} />
</Col>
<Col mediumSize={6}>
<h5 className='text-xs-center'><Icon icon='disk' size={1} /> {_('statDisk')}</h5>
<VmGroupXvdLineChart addSumSeries={useCombinedValues} data={stats} />
</Col>
</Row>
</Container>
: <Container><Upgrade place='hostStats' available={3} /></Container>
}
}

View File

@@ -31,7 +31,7 @@ const vmActionBarByState = {
handler: restartVm,
pending: includes(vm.current_operations, 'clean_reboot')
},
{
(isAdmin || !vm.resourceSet) && {
icon: 'vm-migrate',
label: 'migrateVmLabel',
handler: migrateVm,
@@ -77,7 +77,7 @@ const vmActionBarByState = {
handler: cloneVm,
pending: includes(vm.current_operations, 'clone')
},
{
(isAdmin || !vm.resourceSet) && {
icon: 'vm-migrate',
label: 'migrateVmLabel',
handler: migrateVm,

View File

@@ -150,6 +150,7 @@ export default class TabConsole extends Component {
scale={scale}
url={resolveUrl(`consoles/${vm.id}`)}
/>
{!minimalLayout && <p><em><Icon icon='info' /> <a href='https://bugs.xenserver.org/browse/XSO-650' target='_blank'>{_('tipLabel')} {_('tipConsoleLabel')}</a></em></p>}
</Col>
</Row>
</Container>

View File

@@ -2,9 +2,8 @@ import _, { messages } from 'intl'
import ActionButton from 'action-button'
import ActionRowButton from 'action-row-button'
import Component from 'base-component'
import DragNDropOrder from 'drag-n-drop-order'
import forEach from 'lodash/forEach'
import HTML5Backend from 'react-dnd-html5-backend'
import Icon from 'icon'
import isEmpty from 'lodash/isEmpty'
import IsoDevice from 'iso-device'
import Link from 'link'
@@ -18,7 +17,6 @@ import TabButton from 'tab-button'
import Tooltip from 'tooltip'
import { Container, Row, Col } from 'grid'
import { createSelector } from 'selectors'
import { DragDropContext, DragSource, DropTarget } from 'react-dnd'
import { injectIntl } from 'react-intl'
import { noop } from 'utils'
import { SelectSr, SelectVdi } from 'select-objects'
@@ -41,26 +39,6 @@ import {
setVmBootOrder
} from 'xo'
const parseBootOrder = bootOrder => {
// FIXME missing translation
const bootOptions = {
c: 'Hard-Drive',
d: 'DVD-Drive',
n: 'Network'
}
const order = []
if (bootOrder) {
for (const id of bootOrder) {
if (id in bootOptions) {
order.push({id, text: bootOptions[id], active: true})
delete bootOptions[id]
}
}
}
forEach(bootOptions, (text, id) => { order.push({id, text, active: false}) })
return order
}
@injectIntl
@propTypes({
onClose: propTypes.func,
@@ -196,129 +174,6 @@ class AttachDisk extends Component {
}
}
const orderItemSource = {
beginDrag: props => ({
id: props.id,
index: props.index
})
}
const orderItemTarget = {
hover: (props, monitor, component) => {
const dragIndex = monitor.getItem().index
const hoverIndex = props.index
if (dragIndex === hoverIndex) {
return
}
props.move(dragIndex, hoverIndex)
monitor.getItem().index = hoverIndex
}
}
@DropTarget('orderItem', orderItemTarget, connect => ({
connectDropTarget: connect.dropTarget()
}))
@DragSource('orderItem', orderItemSource, (connect, monitor) => ({
connectDragSource: connect.dragSource(),
isDragging: monitor.isDragging()
}))
@propTypes({
connectDragSource: propTypes.func.isRequired,
connectDropTarget: propTypes.func.isRequired,
index: propTypes.number.isRequired,
isDragging: propTypes.bool.isRequired,
id: propTypes.any.isRequired,
item: propTypes.object.isRequired,
move: propTypes.func.isRequired
})
class OrderItem extends Component {
_toggle = checked => {
const { item } = this.props
item.active = checked
this.forceUpdate()
}
render () {
const { item, connectDragSource, connectDropTarget } = this.props
return connectDragSource(connectDropTarget(
<li className='list-group-item'>
<Icon icon='grab' />
{' '}
<Icon icon='grab' />
{' '}
{item.text}
<span className='pull-right'>
<Toggle value={item.active} onChange={this._toggle} />
</span>
</li>
))
}
}
@propTypes({
onClose: propTypes.func,
vm: propTypes.object.isRequired
})
@DragDropContext(HTML5Backend)
class BootOrder extends Component {
constructor (props) {
super(props)
const { vm } = props
const order = parseBootOrder(vm.boot && vm.boot.order)
this.state = {order}
}
_moveOrderItem = (dragIndex, hoverIndex) => {
const order = this.state.order.slice()
const dragItem = order.splice(dragIndex, 1)
if (dragItem.length) {
order.splice(hoverIndex, 0, dragItem.pop())
this.setState({order})
}
}
_reset = () => {
const { vm } = this.props
const order = parseBootOrder(vm.boot && vm.boot.order)
this.setState({order})
}
_save = () => {
const { vm, onClose = noop } = this.props
const { order: newOrder } = this.state
let order = ''
forEach(newOrder, item => { item.active && (order += item.id) })
return setVmBootOrder(vm, order)
.then(onClose)
}
render () {
const { order } = this.state
return <form>
<ul>
{map(order, (item, index) => <OrderItem
key={index}
index={index}
id={item.id}
// FIXME missing translation
item={item}
move={this._moveOrderItem}
/>)}
</ul>
<fieldset className='form-inline'>
<span className='pull-right'>
<ActionButton icon='save' btnStyle='primary' handler={this._save}>{_('saveBootOption')}</ActionButton>
{' '}
<ActionButton icon='reset' handler={this._reset}>{_('resetBootOption')}</ActionButton>
</span>
</fieldset>
</form>
}
}
class MigrateVdiModalBody extends Component {
get value () {
return this.state
@@ -360,6 +215,34 @@ export default class TabDisks extends Component {
}
}
parseBootOrder = bootOrder => {
// FIXME missing translation
const bootOptions = {
c: 'Hard-Drive',
d: 'DVD-Drive',
n: 'Network'
}
const order = []
if (bootOrder) {
for (const id of bootOrder) {
if (id in bootOptions) {
order.push({id, text: bootOptions[id], active: true})
delete bootOptions[id]
}
}
}
forEach(bootOptions, (text, id) => { order.push({id, text, active: false}) })
return {order}
}
setVmBootOrder = (_, newOrder) => {
const { vm } = this.props
let order = ''
forEach(newOrder, item => { item.active && (order += item.id) })
return setVmBootOrder(vm, order)
.then(noop)
}
_toggleNewDisk = () => this.setState({
newDisk: !this.state.newDisk,
attachDisk: false,
@@ -432,8 +315,8 @@ export default class TabDisks extends Component {
<Row>
<Col>
{newDisk && <div><NewDisk vm={vm} onClose={this._toggleNewDisk} /><hr /></div>}
{attachDisk && <div><AttachDisk vm={vm} vbds={vbds} onClose={this._toggleAttachDisk} /><hr /></div>}
{bootOrder && <div><BootOrder vm={vm} onClose={this._toggleBootOrder} /><hr /></div>}
{attachDisk && <div><AttachDisk vm={vm} vbds={vbds} /><hr /></div>}
{bootOrder && <div><DragNDropOrder parseOrderParam={vm.boot && vm.boot.order} parseOrder={this.parseBootOrder} setOrder={this.setVmBootOrder} toggleItems onClose={this._toggleBootOrder} /><hr /></div>}
</Col>
</Row>
<Row>

View File

@@ -19,12 +19,6 @@
normalize-path "^2.0.1"
through2 "^2.0.3"
"@nraynaud/novnc@^0.6.1-1":
version "0.6.1"
resolved "https://registry.yarnpkg.com/@nraynaud/novnc/-/novnc-0.6.1.tgz#995459bb6f7bd5dd9bd7899b021f68f7744cf1b3"
dependencies:
pako "^1.0.3"
JSONStream@^1.0.3:
version "1.3.1"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.1.tgz#707f761e01dae9e16f1bcf93703b78c70966579a"
@@ -1210,6 +1204,10 @@ bootstrap@4.0.0-alpha.5:
jquery "1.9.1 - 3"
tether "^1.3.7"
bowser@^0.7.2:
version "0.7.3"
resolved "https://registry.yarnpkg.com/bowser/-/bowser-0.7.3.tgz#4fc0cb4e0e2bdd9b394df0d2038c32c2cc2712c8"
brace-expansion@^1.1.7:
version "1.1.8"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292"
@@ -5281,6 +5279,13 @@ notifyjs@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/notifyjs/-/notifyjs-3.0.0.tgz#7418c9d6c0533aebaa643414214af53b521d1b28"
novnc-node@^0.5.3:
version "0.5.3"
resolved "https://registry.yarnpkg.com/novnc-node/-/novnc-node-0.5.3.tgz#69f20a4a2ff0c54ca2f942ff59553f523eb61fa7"
dependencies:
bowser "^0.7.2"
debug "^2.2.0"
now-and-later@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/now-and-later/-/now-and-later-1.0.0.tgz#23e798ccaaf0e8acbef0687f82086274746e0893"
@@ -5515,10 +5520,6 @@ p-reduce@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/p-reduce/-/p-reduce-1.0.0.tgz#18c2b0dd936a4690a529f8231f58a0fdb6a47dfa"
pako@^1.0.3:
version "1.0.5"
resolved "https://registry.yarnpkg.com/pako/-/pako-1.0.5.tgz#d2205dfe5b9da8af797e7c163db4d1f84e4600bc"
pako@~0.2.0:
version "0.2.9"
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"