Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Oct 20, 2021
1 parent 07cc4c8 commit a45bd6f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/xen-api/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export class Xapi extends EventEmitter {
}

this._allowUnauthorized = opts.allowUnauthorized
this._httpProxy = opts.httpProxy
this._setUrl(url)

this._connected = new Promise(resolve => {
Expand Down Expand Up @@ -851,6 +852,7 @@ export class Xapi extends EventEmitter {
rejectUnauthorized: !this._allowUnauthorized,
},
url,
httpProxy: this._httpProxy,
})
this._url = url
}
Expand Down
7 changes: 6 additions & 1 deletion packages/xen-api/src/transports/json-rpc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import httpRequestPlus from 'http-request-plus'
import ProxyAgent from 'proxy-agent'
import { format, parse } from 'json-rpc-protocol'

import XapiError from '../_XapiError'

import UnsupportedTransport from './_UnsupportedTransport'

// https://github.com/xenserver/xenadmin/blob/0df39a9d83cd82713f32d24704852a0fd57b8a64/XenModel/XenAPI/Session.cs#L403-L433
export default ({ secureOptions, url }) => {
export default ({ secureOptions, url, httpProxy }) => {
// httpProxyUrl = 'http://172.16.210.156:3128'
if (httpProxy) {
secureOptions.agent = new ProxyAgent(httpProxy)
}
return (method, args) =>
httpRequestPlus
.post(url, {
Expand Down
8 changes: 8 additions & 0 deletions packages/xo-server/src/api/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ add.params = {
optional: true,
type: 'boolean',
},
httpProxy: {
optional: true,
type: 'string',
},
}

// -------------------------------------------------------------------
Expand Down Expand Up @@ -104,6 +108,10 @@ set.params = {
optional: true,
type: 'boolean',
},
httpProxy: {
optional: true,
type: 'string',
},
}

// -------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions packages/xo-server/src/xo-mixins/xen-servers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ export default class {
readOnly: server.readOnly,

...config.get('xapiOptions'),
httpProxy: server.httpProxy,
guessVhdSizeOnImport: config.get('guessVhdSizeOnImport'),

auth: {
Expand Down
2 changes: 2 additions & 0 deletions packages/xo-web/src/common/intl/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,8 @@ const messages = {
serverEnabled: 'Enabled',
serverDisabled: 'Disabled',
serverDisable: 'Disable server',
serverHttpProxy: ' Http proxy Url',
serverHttpProxyPlaceHolder: ' Http proxy Url',

// ----- Copy VM -----
copyVm: 'Copy VM',
Expand Down
3 changes: 2 additions & 1 deletion packages/xo-web/src/common/xo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,14 @@ export const exportConfig = () =>

// Server ------------------------------------------------------------

export const addServer = (host, username, password, label, allowUnauthorized) =>
export const addServer = (host, username, password, label, allowUnauthorized, httpProxy) =>
_call('server.add', {
allowUnauthorized,
host,
label,
password,
username,
httpProxy,
})::tap(subscribeServers.forceRefresh, () => error(_('serverError'), _('serverAddFailed')))

export const editServer = (server, props) =>
Expand Down
26 changes: 23 additions & 3 deletions packages/xo-web/src/xo-app/settings/servers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ const COLUMNS = [
itemRenderer: ({ poolId }) => poolId !== undefined && <Pool id={poolId} link />,
name: _('pool'),
},
{
itemRenderer: (server, formatMessage) => (
<Text
value={server.httpProxy || ''}
onChange={httpProxy => editServer(server, { httpProxy })}
placeholder={formatMessage(messages.serverHttpProxyPlaceHolder)}
/>
),
name: _('serverHttpProxy'),
sortCriteria: _ => _.httpProxy,
},
]
const INDIVIDUAL_ACTIONS = [
{
Expand All @@ -152,16 +163,16 @@ export default class Servers extends Component {
}

_addServer = async () => {
const { label, host, password, username, allowUnauthorized } = this.state

await addServer(host, username, password, label, allowUnauthorized)
const { label, host, password, username, allowUnauthorized, httpProxy } = this.state
await addServer(host, username, password, label, allowUnauthorized, httpProxy)

this.setState({
allowUnauthorized: false,
host: '',
label: '',
password: '',
username: '',
httpProxy: '',
})
}

Expand Down Expand Up @@ -227,6 +238,15 @@ export default class Servers extends Component {
<Toggle onChange={this.linkState('allowUnauthorized')} value={state.allowUnauthorized} />
</Tooltip>
</div>{' '}
<div className='form-group'>
<input
className='form-control'
onChange={this.linkState('httpProxy')}
placeholder={formatMessage(messages.serverHttpProxy)}
type='url'
value={state.httpProxy || ''}
/>
</div>{' '}
<ActionButton btnStyle='primary' form='form-add-server' handler={this._addServer} icon='save'>
{_('serverConnect')}
</ActionButton>
Expand Down

0 comments on commit a45bd6f

Please sign in to comment.