fix(xo-server/xen-servers): pool.id → pool.$id (#3723)

Correctly unregister a Xapi connection from its pool.
This commit is contained in:
Julien Fontanet 2018-11-27 10:24:52 +01:00 committed by GitHub
commit b773f5e821
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,7 +20,7 @@ import { Servers } from '../models/server'
const log = createLogger('xo:xo-mixins:xen-servers') const log = createLogger('xo:xo-mixins:xen-servers')
export default class { export default class {
constructor (xo, { xapiOptions }) { constructor(xo, { xapiOptions }) {
this._objectConflicts = { __proto__: null } // TODO: clean when a server is disconnected. this._objectConflicts = { __proto__: null } // TODO: clean when a server is disconnected.
const serversDb = (this._servers = new Servers({ const serversDb = (this._servers = new Servers({
connection: xo._redis, connection: xo._redis,
@ -58,7 +58,7 @@ export default class {
// TODO: disconnect servers on stop. // TODO: disconnect servers on stop.
} }
async registerXenServer ({ async registerXenServer({
allowUnauthorized, allowUnauthorized,
host, host,
label, label,
@ -82,7 +82,7 @@ export default class {
return server.properties return server.properties
} }
async unregisterXenServer (id) { async unregisterXenServer(id) {
this.disconnectXenServer(id)::ignoreErrors() this.disconnectXenServer(id)::ignoreErrors()
if (!(await this._servers.remove(id))) { if (!(await this._servers.remove(id))) {
@ -90,7 +90,7 @@ export default class {
} }
} }
async updateXenServer ( async updateXenServer(
id, id,
{ {
allowUnauthorized, allowUnauthorized,
@ -150,7 +150,7 @@ export default class {
// TODO: this method will no longer be async when servers are // TODO: this method will no longer be async when servers are
// integrated to the main collection. // integrated to the main collection.
async _getXenServer (id) { async _getXenServer(id) {
const server = await this._servers.first(id) const server = await this._servers.first(id)
if (server === undefined) { if (server === undefined) {
throw noSuchObject(id, 'xenServer') throw noSuchObject(id, 'xenServer')
@ -159,7 +159,7 @@ export default class {
return server return server
} }
_onXenAdd ( _onXenAdd(
newXapiObjects, newXapiObjects,
xapiIdsToXo, xapiIdsToXo,
toRetry, toRetry,
@ -170,7 +170,7 @@ export default class {
const conflicts = this._objectConflicts const conflicts = this._objectConflicts
const objects = this._xo._objects const objects = this._xo._objects
forEach(newXapiObjects, function handleObject (xapiObject, xapiId) { forEach(newXapiObjects, function handleObject(xapiObject, xapiId) {
const { $ref } = xapiObject const { $ref } = xapiObject
const dependent = dependents[$ref] const dependent = dependents[$ref]
@ -204,7 +204,7 @@ export default class {
}) })
} }
_onXenRemove (xapiObjects, xapiIdsToXo, toRetry, conId) { _onXenRemove(xapiObjects, xapiIdsToXo, toRetry, conId) {
const conflicts = this._objectConflicts const conflicts = this._objectConflicts
const objects = this._xo._objects const objects = this._xo._objects
@ -236,7 +236,7 @@ export default class {
}) })
} }
async connectXenServer (id) { async connectXenServer(id) {
const server = (await this._getXenServer(id)).properties const server = (await this._getXenServer(id)).properties
const xapi = (this._xapis[server.id] = new Xapi({ const xapi = (this._xapis[server.id] = new Xapi({
@ -311,7 +311,7 @@ export default class {
return { return {
httpRequest: this._xo.httpRequest.bind(this), httpRequest: this._xo.httpRequest.bind(this),
install () { install() {
objects.on('add', onAddOrUpdate) objects.on('add', onAddOrUpdate)
objects.on('update', onAddOrUpdate) objects.on('update', onAddOrUpdate)
objects.on('remove', onRemove) objects.on('remove', onRemove)
@ -319,7 +319,7 @@ export default class {
onAddOrUpdate(objects.all) onAddOrUpdate(objects.all)
}, },
uninstall () { uninstall() {
objects.removeListener('add', onAddOrUpdate) objects.removeListener('add', onAddOrUpdate)
objects.removeListener('update', onAddOrUpdate) objects.removeListener('update', onAddOrUpdate)
objects.removeListener('remove', onRemove) objects.removeListener('remove', onRemove)
@ -362,7 +362,7 @@ export default class {
) )
} }
async disconnectXenServer (id) { async disconnectXenServer(id) {
const xapi = this._xapis[id] const xapi = this._xapis[id]
if (!xapi) { if (!xapi) {
throw noSuchObject(id, 'xenServer') throw noSuchObject(id, 'xenServer')
@ -371,20 +371,20 @@ export default class {
delete this._xapis[id] delete this._xapis[id]
const { pool } = xapi const { pool } = xapi
if (pool) { if (pool != null) {
delete this._xapisByPool[pool.id] delete this._xapisByPool[pool.$id]
} }
xapi.xo.uninstall() xapi.xo.uninstall()
return xapi.disconnect() return xapi.disconnect()
} }
getAllXapis () { getAllXapis() {
return this._xapis return this._xapis
} }
// Returns the XAPI connection associated to an object. // Returns the XAPI connection associated to an object.
getXapi (object, type) { getXapi(object, type) {
if (isString(object)) { if (isString(object)) {
object = this._xo.getObject(object, type) object = this._xo.getObject(object, type)
} }
@ -402,7 +402,7 @@ export default class {
return xapi return xapi
} }
async getAllXenServers () { async getAllXenServers() {
const servers = await this._servers.get() const servers = await this._servers.get()
const xapis = this._xapis const xapis = this._xapis
forEach(servers, server => { forEach(servers, server => {
@ -423,19 +423,19 @@ export default class {
return servers return servers
} }
getXapiVmStats (vmId, granularity) { getXapiVmStats(vmId, granularity) {
return this._stats.getVmStats(this.getXapi(vmId), vmId, granularity) return this._stats.getVmStats(this.getXapi(vmId), vmId, granularity)
} }
getXapiHostStats (hostId, granularity) { getXapiHostStats(hostId, granularity) {
return this._stats.getHostStats(this.getXapi(hostId), hostId, granularity) return this._stats.getHostStats(this.getXapi(hostId), hostId, granularity)
} }
getXapiSrStats (srId, granularity) { getXapiSrStats(srId, granularity) {
return this._stats.getSrStats(this.getXapi(srId), srId, granularity) return this._stats.getSrStats(this.getXapi(srId), srId, granularity)
} }
async mergeXenPools (sourceId, targetId, force = false) { async mergeXenPools(sourceId, targetId, force = false) {
const sourceXapi = this.getXapi(sourceId) const sourceXapi = this.getXapi(sourceId)
const { const {
_auth: { user, password }, _auth: { user, password },