feat(vm/tab-advanced): editable CPU weight and cap (#1293)

Fixes #1283
This commit is contained in:
Pierre Donias
2016-07-20 09:44:24 +02:00
committed by Julien Fontanet
parent b16097767a
commit 24d4610b04
3 changed files with 36 additions and 8 deletions

View File

@@ -277,20 +277,34 @@ export class Password extends Text {
}
@propTypes({
value: propTypes.number.isRequired
nullable: propTypes.bool,
value: propTypes.number
})
export class Number extends Component {
get value () {
return +this.refs.input.value
}
_onChange = value => this.props.onChange(+value)
_onChange = value => {
if (value === '') {
if (this.props.nullable) {
value = null
} else {
return
}
} else {
value = +value
}
this.props.onChange(value)
}
render () {
const { value } = this.props
return <Text
{...this.props}
onChange={this._onChange}
value={String(this.props.value)}
value={value === null ? '' : String(value)}
/>
}
}

View File

@@ -504,7 +504,9 @@ var messages = {
uuid: 'UUID',
virtualizationMode: 'Virtualization mode',
cpuWeightLabel: 'CPU weight',
defaultCpuWeight: 'Default',
defaultCpuWeight: 'Default ({value, number})',
cpuCapLabel: 'CPU cap',
defaultCpuCap: 'Default ({value, number})',
pvArgsLabel: 'PV args',
xenToolsStatus: 'Xen tools status',
xenToolsStatusValue: {

View File

@@ -20,6 +20,9 @@ import {
suspendVm
} from 'xo'
const XEN_DEFAULT_WEIGHT = 256
const XEN_DEFAULT_CAP = 0
const forceReboot = vm => restartVm(vm, true)
const forceShutdown = vm => stopVm(vm, true)
const fullCopy = vm => cloneVm(vm, true)
@@ -136,10 +139,19 @@ export default ({
}
<tr>
<th>{_('cpuWeightLabel')}</th>
{vm.cpuWeight
? <td>{vm.cpuWeight}</td>
: <td>{_('defaultCpuWeight')}</td>
}
<td>
<Number value={vm.cpuWeight == null ? null : vm.cpuWeight} onChange={value => editVm(vm, { cpuWeight: value })} nullable>
{vm.cpuWeight == null ? _('defaultCpuWeight', { value: XEN_DEFAULT_WEIGHT }) : vm.cpuWeight}
</Number>
</td>
</tr>
<tr>
<th>{_('cpuCapLabel')}</th>
<td>
<Number value={vm.cpuCap == null ? null : vm.cpuCap} onChange={value => editVm(vm, { cpuCap: value })} nullable>
{vm.cpuCap == null ? _('defaultCpuCap', { value: XEN_DEFAULT_CAP }) : vm.cpuCap}
</Number>
</td>
</tr>
<tr>
<th>{_('autoPowerOn')}</th>