feat(xo-web/proxy): bind license to a (re)deployed proxy (#4916)

See xoa#52
This commit is contained in:
badrAZ 2020-04-14 09:42:38 +02:00 committed by Julien Fontanet
parent 09096fef5b
commit 15ef84e238
4 changed files with 56 additions and 13 deletions

View File

@ -76,6 +76,7 @@ const messages = {
normal: 'Normal',
withMemory: 'With memory',
offline: 'Offline',
noLicenseAvailable: 'No license available',
// ----- Modals -----
alertOk: 'OK',

View File

@ -3095,8 +3095,13 @@ export const getApplianceInfo = () => _call('xoa.getApplianceInfo')
// Proxy --------------------------------------------------------------------
export const deployProxyAppliance = (sr, { network, proxy, ...props } = {}) =>
export const deployProxyAppliance = (
license,
sr,
{ network, proxy, ...props } = {}
) =>
_call('proxy.deploy', {
license: resolveId(license),
network: resolveId(network),
proxy: resolveId(proxy),
sr: resolveId(sr),

View File

@ -4,11 +4,11 @@ import Icon from 'icon'
import React from 'react'
import SingleLineRow from 'single-line-row'
import Tooltip from 'tooltip'
import { alert, form } from 'modal'
import { Col, Container } from 'grid'
import { connectStore } from 'utils'
import { createGetObjectsOfType } from 'selectors'
import { deployProxyAppliance, isSrWritable } from 'xo'
import { form } from 'modal'
import { generateId } from 'reaclette-utils'
import { get } from '@xen-orchestra/defined'
import { injectIntl } from 'react-intl'
@ -228,8 +228,24 @@ const Modal = decorate([
),
])
const deployProxy = proxy => {
const deployProxy = ({ license, proxy }) => {
const isRedeployMode = proxy !== undefined
const header = (
<span>
<Icon icon='proxy' />{' '}
{isRedeployMode ? _('redeployProxy') : _('deployProxy')}
</span>
)
if (license === undefined) {
return alert(
header,
<div className='text-muted'>
<Icon icon='info' /> {_('noLicenseAvailable')}
</div>
)
}
return form({
defaultValue: {
dns: '',
@ -239,14 +255,9 @@ const deployProxy = proxy => {
networkMode: 'dhcp',
},
render: props => <Modal {...props} redeploy={isRedeployMode} />,
header: (
<span>
<Icon icon='proxy' />{' '}
{isRedeployMode ? _('redeployProxy') : _('deployProxy')}
</span>
),
header,
}).then(({ sr, network, networkMode, ip, netmask, gateway, dns }) =>
deployProxyAppliance(sr, {
deployProxyAppliance(license, sr, {
network: network === null ? undefined : network,
networkConfiguration:
networkMode === 'static'

View File

@ -8,14 +8,16 @@ import NoObjects from 'no-objects'
import React from 'react'
import SortedTable from 'sorted-table'
import { adminOnly } from 'utils'
import { provideState, injectState } from 'reaclette'
import { Text, XoSelect } from 'editable'
import { Vm } from 'render-xo-item'
import { withRouter } from 'react-router'
import {
checkProxyHealth,
destroyProxyAppliances,
forgetProxyAppliances,
editProxyAppliance,
forgetProxyAppliances,
getLicenses,
subscribeProxies,
upgradeProxyAppliance,
} from 'xo'
@ -57,7 +59,14 @@ const ACTIONS = [
const INDIVIDUAL_ACTIONS = [
{
handler: deployProxy,
handler: (proxy, { validLicensePerProxyVm }) =>
deployProxy({
proxy,
license: defined(
validLicensePerProxyVm[proxy.vmUuid],
validLicensePerProxyVm.none
),
}),
icon: 'refresh',
label: _('redeployProxyAction'),
level: 'warning',
@ -159,12 +168,28 @@ export default decorate([
addSubscriptions({
proxies: subscribeProxies,
}),
({ proxies, router }) => (
provideState({
computed: {
licenses: () => getLicenses({ productType: 'xoproxy' }),
validLicensePerProxyVm: ({ licenses = [] }) => {
const result = {}
licenses.forEach(license => {
if (!(license.expires < Date.now())) {
result[defined(license.boundObjectId, 'none')] = license
}
})
return result
},
},
}),
injectState,
({ proxies, router, state }) => (
<Page header={HEADER} title='proxies' formatTitle>
<div>
<div className='mt-1 mb-1'>
<ActionButton
btnStyle='success'
data-license={state.validLicensePerProxyVm.none}
handler={deployProxy}
icon='proxy'
size='large'
@ -178,6 +203,7 @@ export default decorate([
columns={COLUMNS}
component={SortedTable}
data-router={router}
data-validLicensePerProxyVm={state.validLicensePerProxyVm}
emptyMessage={
<span className='text-muted'>
<Icon icon='alarm' />