Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(xo-web/proxy): register an existing proxy #6556

Merged
merged 13 commits into from
Nov 29, 2022
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

- [Remotes] Prevent remote path from ending with `xo-vm-backups` as it's usually a mistake
- [OVA export] Speed up OVA generation by 2. Generated file will be bigger (as big as uncompressed XVA) (PR [#6487](https://github.com/vatesfr/xen-orchestra/pull/6487))
- [Proxies] Ability to register an existing proxy from the `Proxies` view (PR [#6556](https://github.com/vatesfr/xen-orchestra/pull/6556))

### Bug fixes

Expand Down
8 changes: 7 additions & 1 deletion packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ const messages = {
addCustomField: 'Add custom field',
editCustomField: 'Edit custom field',
deleteCustomField: 'Delete custom field',
onlyAvailableXoaUsers: 'Only available to XOA users',
pdonias marked this conversation as resolved.
Show resolved Hide resolved

// ----- Modals -----
alertOk: 'OK',
Expand Down Expand Up @@ -1331,6 +1332,8 @@ const messages = {
vmCoresPerSocketExceedsSocketsLimit: 'The selected value exceeds the sockets limit ({maxSockets, number})',
vmHaDisabled: 'Disabled',
vmMemoryLimitsLabel: 'Memory limits (min/max)',
vmUuid: 'VM UUID',
vmUuidNotMandatory: 'VM UUID is not mandatory when specifying the address but it is still recommended to fill it',
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
vmVgpu: 'vGPU',
vmVgpus: 'GPUs',
vmVgpuNone: 'None',
Expand Down Expand Up @@ -2470,7 +2473,7 @@ const messages = {
proxyUnknownVm: 'Unknown proxy VM.',

// ----- proxies -----
deployProxyDisabled: 'Only available to XOA users',
doYouWantForgetIt: 'Do you want to forget it?',
forgetProxyApplianceTitle: 'Forget prox{n, plural, one {y} other {ies}}',
forgetProxyApplianceMessage: 'Are you sure you want to forget {n, number} prox{n, plural, one {y} other {ies}}?',
forgetProxies: 'Forget proxy(ies)',
Expand All @@ -2481,11 +2484,14 @@ const messages = {
redeployProxy: 'Redeploy proxy',
redeployProxyAction: 'Redeploy this proxy',
redeployProxyWarning: 'This action will destroy the old proxy VM',
registerProxy: 'Register a proxy',
noProxiesAvailable: 'No proxies available',
checkProxyHealth: 'Test your proxy',
updateProxyApplianceSettings: 'Update appliance settings',
urlNotFound: 'URL not found',
proxyAuthToken: 'Authentication token',
proxyCopyUrl: 'Copy proxy URL',
proxyError: 'Proxy error',
proxyTestSuccess: 'Test passed for {name}',
proxyTestSuccessMessage: 'The proxy appears to work correctly',
proxyTestFailed: 'Test failed for {name}',
Expand Down
33 changes: 33 additions & 0 deletions packages/xo-web/src/common/xo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import invoke from '../invoke'
import Icon from '../icon'
import logError from '../log-error'
import NewAuthTokenModal from './new-auth-token-modal'
import RegisterProxyModal from './register-proxy-modal'
import renderXoItem, { renderXoItemFromId, Vm } from '../render-xo-item'
import store from 'store'
import { alert, chooseAction, confirm } from '../modal'
Expand Down Expand Up @@ -3303,6 +3304,36 @@ export const deployProxyAppliance = (license, sr, { network, proxy, ...props } =
...props,
})::tap(subscribeProxies.forceRefresh)

export const registerProxy = async () => {
const registerProxyInfo = await confirm({
body: <RegisterProxyModal />,
icon: 'connect',
title: _('registerProxy'),
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
})

const proxyId = await registerProxyApplicance(registerProxyInfo)
if (
!(await isProxyWorking(proxyId).catch(err => {
console.error(err)
return false
}))
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
) {
await confirm({
body: (
<div>
<p>{_('proxyTestFailedConnectionIssueMessage')}</p>
<p>{_('doYouWantForgetIt')}</p>
</div>
),
title: _('proxyError'),
})
await forgetProxyAppliances([proxyId])
}
}

export const registerProxyApplicance = proxyInfo =>
_call('proxy.register', proxyInfo)::tap(subscribeProxies.forceRefresh)

export const editProxyAppliance = (proxy, { vm, ...props }) =>
_call('proxy.update', {
id: resolveId(proxy),
Expand Down Expand Up @@ -3362,6 +3393,8 @@ export const checkProxyHealth = async proxy => {
)
}

export const isProxyWorking = async proxy => (await _call('proxy.checkHealth', { id: resolveId(proxy) })).success
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved

// Audit plugin ---------------------------------------------------------

const METHOD_NOT_FOUND_CODE = -32601
Expand Down
58 changes: 58 additions & 0 deletions packages/xo-web/src/common/xo/register-proxy-modal/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import _ from 'intl'
import Component from 'base-component'
import React from 'react'
import SingleLineRow from 'single-line-row'
import { Col, Container } from 'grid'
import { Input as DebounceInput } from 'debounce-input-decorator'
import Icon from 'icon'

export default class RegisterProxyModal extends Component {
state = {
authenticationToken: undefined,
name: undefined,
address: undefined,
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
vmUuid: undefined,
}
get value() {
return this.state
}

render() {
const { address, authenticationToken, name, vmUuid } = this.state
return (
<Container>
julien-f marked this conversation as resolved.
Show resolved Hide resolved
<SingleLineRow className='mt-1'>
<Col size={6}>{_('proxyAuthToken')}</Col>
<Col size={6}>
<DebounceInput
className='form-control'
onChange={this.linkState('authenticationToken')}
value={authenticationToken}
julien-f marked this conversation as resolved.
Show resolved Hide resolved
/>
</Col>
</SingleLineRow>
<SingleLineRow className='mt-1'>
<Col size={6}>{_('name')}</Col>
<Col size={6}>
<DebounceInput className='form-control' onChange={this.linkState('name')} value={name} />
</Col>
</SingleLineRow>
<SingleLineRow className='mt-1'>
<Col size={6}>{_('address')}</Col>
<Col size={6}>
<DebounceInput className='form-control' onChange={this.linkState('address')} value={address} />
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
julien-f marked this conversation as resolved.
Show resolved Hide resolved
</Col>
</SingleLineRow>
<SingleLineRow className='mt-1'>
<Col size={6}>{_('vmUuid')}</Col>
<Col size={6}>
<DebounceInput className='form-control' onChange={this.linkState('vmUuid')} value={vmUuid} />
</Col>
</SingleLineRow>
<i className='text-info'>
<Icon icon='info' /> {_('vmUuidNotMandatory')}
</i>
Rajaa-BARHTAOUI marked this conversation as resolved.
Show resolved Hide resolved
</Container>
)
}
}
14 changes: 13 additions & 1 deletion packages/xo-web/src/xo-app/proxies/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
forgetProxyAppliances,
getLicenses,
getProxyApplianceUpdaterState,
registerProxy,
subscribeProxies,
upgradeProxyAppliance,
EXPIRES_SOON_DELAY,
Expand Down Expand Up @@ -322,10 +323,21 @@ const Proxies = decorate([
handler={effects.deployProxy}
icon='proxy'
size='large'
tooltip={state.isFromSource ? _('deployProxyDisabled') : undefined}
tooltip={state.isFromSource ? _('onlyAvailableXoaUsers') : undefined}
>
{_('deployProxy')}
</ActionButton>
<ActionButton
className='ml-1'
btnStyle='success'
disabled={state.isFromSource}
handler={registerProxy}
icon='connect'
size='large'
tooltip={state.isFromSource ? _('onlyAvailableXoaUsers') : undefined}
>
{_('registerProxy')}
</ActionButton>
</div>
<NoObjects
actions={ACTIONS}
Expand Down