diff --git a/@xen-orchestra/xapi/src/host.js b/@xen-orchestra/xapi/src/host.js new file mode 100644 index 000000000..3c4942318 --- /dev/null +++ b/@xen-orchestra/xapi/src/host.js @@ -0,0 +1,17 @@ +module.exports = class Host { + async restartAgent(ref) { + const agentStartTime = +(await this.getField('host', ref, 'other_config')).agent_start_time + + await this.call('host.restart_agent', ref) + + await new Promise(resolve => { + // even though the ref could change in case of pool master restart, tests show it stays the same + const stopWatch = this.watchObject(ref, host => { + if (+host.other_config.agent_start_time > agentStartTime) { + stopWatch() + resolve() + } + }) + }) + } +} diff --git a/@xen-orchestra/xapi/src/index.js b/@xen-orchestra/xapi/src/index.js index 5182a5d1c..bcd783b46 100644 --- a/@xen-orchestra/xapi/src/index.js +++ b/@xen-orchestra/xapi/src/index.js @@ -206,6 +206,7 @@ function mixin(mixins) { } mixin({ task: require('./task.js'), + host: require('./host.js'), VBD: require('./vbd.js'), VDI: require('./vdi.js'), VIF: require('./vif.js'), diff --git a/packages/xo-server/src/api/host.mjs b/packages/xo-server/src/api/host.mjs index 5afe99a36..164dffa6e 100644 --- a/packages/xo-server/src/api/host.mjs +++ b/packages/xo-server/src/api/host.mjs @@ -134,7 +134,7 @@ restart.resolve = { // ------------------------------------------------------------------- export function restartAgent({ host }) { - return this.getXapi(host).restartHostAgent(host._xapiId) + return this.getXapiObject(host).$restartAgent() } restartAgent.description = 'restart the Xen agent on the host' diff --git a/packages/xo-server/src/xapi/index.mjs b/packages/xo-server/src/xapi/index.mjs index 61d664d23..8ca811f28 100644 --- a/packages/xo-server/src/xapi/index.mjs +++ b/packages/xo-server/src/xapi/index.mjs @@ -302,10 +302,6 @@ export default class Xapi extends XapiBase { await this.callAsync('host.reboot', host.$ref) } - async restartHostAgent(hostId) { - await this.callAsync('host.restart_agent', this.getObject(hostId).$ref) - } - async setRemoteSyslogHost(hostId, syslogDestination) { const host = this.getObject(hostId) await host.set_logging({