chore: use decorateWith instead of defer decorator syntax
`golike-defer` built-in decorator syntax will be removed in future versions.
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
"rimraf": "^3.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/decorate-with": "^0.0.1",
|
||||
"@xen-orchestra/log": "^0.2.0",
|
||||
"core-js": "^3.6.4",
|
||||
"golike-defer": "^0.5.1",
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'core-js/features/symbol/async-iterator'
|
||||
import assert from 'assert'
|
||||
import hash from 'object-hash'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { defer } from 'golike-defer'
|
||||
|
||||
const log = createLogger('xo:audit-core')
|
||||
@@ -65,7 +66,7 @@ export class AuditCore {
|
||||
this._storage = storage
|
||||
}
|
||||
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async add($defer, subject, event, data) {
|
||||
const time = Date.now()
|
||||
$defer(await this._storage.acquireLock())
|
||||
@@ -150,7 +151,7 @@ export class AuditCore {
|
||||
}
|
||||
}
|
||||
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async deleteRangeAndRewrite($defer, newest, oldest) {
|
||||
assert.notStrictEqual(newest, undefined)
|
||||
assert.notStrictEqual(oldest, undefined)
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
"prepublishOnly": "yarn run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/decorate-with": "^0.0.1",
|
||||
"@xen-orchestra/async-map": "^0.1.2",
|
||||
"@xen-orchestra/log": "^0.2.0",
|
||||
"d3-time-format": "^3.0.0",
|
||||
|
||||
@@ -7,6 +7,7 @@ const pCatch = require('promise-toolbox/catch')
|
||||
const pRetry = require('promise-toolbox/retry')
|
||||
const { asyncMap } = require('@xen-orchestra/async-map')
|
||||
const { createLogger } = require('@xen-orchestra/log')
|
||||
const { decorateWith } = require('@vates/decorate-with')
|
||||
const { defer } = require('golike-defer')
|
||||
const { incorrectState } = require('xo-common/api-errors')
|
||||
const { Ref } = require('xen-api')
|
||||
@@ -139,7 +140,7 @@ module.exports = class Vm {
|
||||
}
|
||||
}
|
||||
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async create(
|
||||
$defer,
|
||||
{
|
||||
@@ -355,7 +356,7 @@ module.exports = class Vm {
|
||||
])
|
||||
}
|
||||
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async export($defer, vmRef, { cancelToken = CancelToken.none, compress = false, useSnapshot } = {}) {
|
||||
const vm = await this.getRecord('VM', vmRef)
|
||||
const taskRef = await this.task_create('VM export', vm.name_label)
|
||||
@@ -448,7 +449,7 @@ module.exports = class Vm {
|
||||
}
|
||||
}
|
||||
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async snapshot($defer, vmRef, { cancelToken = CancelToken.none, name_label } = {}) {
|
||||
const vm = await this.getRecord('VM', vmRef)
|
||||
// cannot unplug VBDs on Running, Paused and Suspended VMs
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"@babel/plugin-proposal-decorators": "^7.4.0",
|
||||
"@babel/preset-env": "^7.1.6",
|
||||
"@iarna/toml": "^2.2.1",
|
||||
"@vates/decorate-with": "^0.0.1",
|
||||
"@vates/parse-duration": "^0.1.0",
|
||||
"app-conf": "^0.9.0",
|
||||
"babel-plugin-lodash": "^3.2.11",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/* eslint-env jest */
|
||||
import Xo from 'xo-lib'
|
||||
import XoCollection from 'xo-collection'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { defaultsDeep, find, forOwn, iteratee, pick } from 'lodash'
|
||||
import { defer } from 'golike-defer'
|
||||
import { fromEvent } from 'promise-toolbox'
|
||||
@@ -68,7 +69,7 @@ class XoConnection extends Xo {
|
||||
return this.waitObject(id)
|
||||
}
|
||||
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async connect($defer, credentials = pick(config.xoConnection, 'email', 'password')) {
|
||||
await this.open()
|
||||
$defer.onFailure(() => this.close())
|
||||
|
||||
@@ -12,6 +12,7 @@ import { asyncMap } from '@xen-orchestra/async-map'
|
||||
import { vmdkToVhd } from 'xo-vmdk-to-vhd'
|
||||
import { cancelable, defer, fromEvents, ignoreErrors, pCatch, pRetry } from 'promise-toolbox'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { defer as deferrable } from 'golike-defer'
|
||||
import { parseDuration } from '@vates/parse-duration'
|
||||
import { PassThrough } from 'stream'
|
||||
@@ -292,7 +293,7 @@ export default class Xapi extends XapiBase {
|
||||
// - Citrix XenServer ® 7.0 Administrator's Guide ch. 5.4
|
||||
// - https://github.com/xcp-ng/xenadmin/blob/60dd70fc36faa0ec91654ec97e24b7af36acff9f/XenModel/Actions/Host/EditMultipathAction.cs
|
||||
// - https://github.com/serencorbett1/xenadmin/blob/1c3fb0c1112e4e316423afc6a028066001d3dea1/XenModel/XenAPI-Extensions/SR.cs
|
||||
@deferrable.onError(log.warn)
|
||||
@decorateWith(deferrable.onError(log.warn))
|
||||
async setHostMultipathing($defer, hostId, multipathing) {
|
||||
const host = this.getObject(hostId)
|
||||
|
||||
@@ -587,7 +588,7 @@ export default class Xapi extends XapiBase {
|
||||
// Create a snapshot (if necessary) of the VM and returns a delta export
|
||||
// object.
|
||||
@cancelable
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async exportDeltaVm(
|
||||
$defer,
|
||||
$cancelToken,
|
||||
@@ -726,7 +727,7 @@ export default class Xapi extends XapiBase {
|
||||
)
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async importDeltaVm(
|
||||
$defer,
|
||||
delta,
|
||||
@@ -1039,7 +1040,7 @@ export default class Xapi extends XapiBase {
|
||||
})
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async installSupplementalPack($defer, stream, { hostId }) {
|
||||
if (!stream.length) {
|
||||
throw new Error('stream must have a length')
|
||||
@@ -1056,7 +1057,7 @@ export default class Xapi extends XapiBase {
|
||||
await this._callInstallationPlugin(this.getObject(hostId).$ref, vdi.uuid)
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async installSupplementalPackOnAllHosts($defer, stream) {
|
||||
if (!stream.length) {
|
||||
throw new Error('stream must have a length')
|
||||
@@ -1147,7 +1148,7 @@ export default class Xapi extends XapiBase {
|
||||
return vmRef
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async _importOvaVm($defer, stream, { descriptionLabel, disks, memory, nameLabel, networks, nCpus, tables }, sr) {
|
||||
// 1. Create VM.
|
||||
const vm = await this._getOrWaitObject(
|
||||
@@ -1842,7 +1843,7 @@ export default class Xapi extends XapiBase {
|
||||
)
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async createNetwork($defer, { name, description = 'Created with Xen Orchestra', pifId, mtu, vlan }) {
|
||||
const networkRef = await this.call('network.create', {
|
||||
name_label: name,
|
||||
@@ -1893,7 +1894,7 @@ export default class Xapi extends XapiBase {
|
||||
)
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async createBondedNetwork($defer, { bondMode, pifIds: masterPifIds, ...params }) {
|
||||
const network = await this.createNetwork(params)
|
||||
$defer.onFailure(() => this.deleteNetwork(network))
|
||||
@@ -2001,7 +2002,7 @@ export default class Xapi extends XapiBase {
|
||||
}
|
||||
|
||||
// Generic Config Drive
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async createCloudInitConfigDrive($defer, vmId, srId, userConfig, networkConfig) {
|
||||
const vm = this.getObject(vmId)
|
||||
const sr = this.getObject(srId)
|
||||
@@ -2048,7 +2049,7 @@ export default class Xapi extends XapiBase {
|
||||
await this.createVbd({ vdi, vm })
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async createTemporaryVdiOnSr($defer, stream, sr, name_label, name_description) {
|
||||
const vdi = await this.createVdi({
|
||||
name_description,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { defer } from 'golike-defer'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { filter, forEach, groupBy } from 'lodash'
|
||||
@@ -113,7 +114,7 @@ export default {
|
||||
},
|
||||
|
||||
// This function helps to reattach a forgotten NFS/iSCSI/HBA SR
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async reattachSr($defer, { uuid, nameLabel, nameDescription, type, deviceConfig }) {
|
||||
const srRef = await this.call('SR.introduce', uuid, nameLabel, nameDescription, type, 'user', true, {})
|
||||
$defer.onFailure(() => this.forgetSr(srRef))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { defer as deferrable } from 'golike-defer'
|
||||
import { find, gte, includes, isEmpty, lte, map as mapToArray, mapValues, noop } from 'lodash'
|
||||
import { cancelable, ignoreErrors, pCatch } from 'promise-toolbox'
|
||||
@@ -36,7 +37,7 @@ export default {
|
||||
},
|
||||
|
||||
// TODO: clean up on error.
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async createVm(
|
||||
$defer,
|
||||
templateId,
|
||||
|
||||
@@ -348,7 +348,7 @@ export default class {
|
||||
|
||||
// -----------------------------------------------------------------
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async deltaCopyVm($defer, srcVm, targetSr, force = false, retention = 1) {
|
||||
const transferStart = Date.now()
|
||||
const srcXapi = this._app.getXapi(srcVm)
|
||||
@@ -576,7 +576,7 @@ export default class {
|
||||
}
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async rollingDeltaVmBackup($defer, { vm, remoteId, tag, retention }) {
|
||||
const transferStart = Date.now()
|
||||
const handler = await this._app.getRemoteHandler(remoteId)
|
||||
@@ -780,7 +780,7 @@ export default class {
|
||||
return this._backupVm(vm, handler, file, { compress })
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async _backupVm($defer, vm, handler, file, { compress }) {
|
||||
const targetStream = await handler.createOutputStream(file)
|
||||
$defer.onFailure.call(handler, 'unlink', file)
|
||||
@@ -975,7 +975,7 @@ export default class {
|
||||
)
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async scanDiskBackup($defer, remoteId, vhdPath) {
|
||||
const device = await this._mountVhd(remoteId, vhdPath)
|
||||
$defer(device.unmount)
|
||||
@@ -985,7 +985,7 @@ export default class {
|
||||
}
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async scanFilesInDiskBackup($defer, remoteId, vhdPath, partitionId, path) {
|
||||
const partition = await this._mountPartition(remoteId, vhdPath, partitionId)
|
||||
$defer(partition.unmount)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import asyncMapSettled from '@xen-orchestra/async-map/legacy'
|
||||
import emitAsync from '@xen-orchestra/emit-async'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
|
||||
import { CancelToken, ignoreErrors } from 'promise-toolbox'
|
||||
import { defer } from 'golike-defer'
|
||||
@@ -178,7 +179,7 @@ export default class Jobs {
|
||||
return Promise.all(promises)
|
||||
}
|
||||
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async _runJob($defer, job, schedule, data_) {
|
||||
const logger = this._logger
|
||||
const { id, type } = job
|
||||
|
||||
@@ -8,6 +8,7 @@ import split2 from 'split2'
|
||||
import synchronized from 'decorator-synchronized'
|
||||
import { compileTemplate } from '@xen-orchestra/template'
|
||||
import { createLogger } from '@xen-orchestra/log'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { defer } from 'golike-defer'
|
||||
import { format, parse } from 'json-rpc-peer'
|
||||
import { incorrectState, noSuchObject } from 'xo-common/api-errors'
|
||||
@@ -191,7 +192,7 @@ export default class Proxy {
|
||||
return this.callProxyMethod(id, 'appliance.updater.getState')
|
||||
}
|
||||
|
||||
@defer
|
||||
@decorateWith(defer)
|
||||
async _createProxyVm($defer, srId, licenseId, { httpProxy, networkId, networkConfiguration }) {
|
||||
const app = this._app
|
||||
const xoProxyConf = app.config.get('xo-proxy')
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import asyncMapSettled from '@xen-orchestra/async-map/legacy'
|
||||
import synchronized from 'decorator-synchronized'
|
||||
import { decorateWith } from '@vates/decorate-with'
|
||||
import { defer as deferrable } from 'golike-defer'
|
||||
import { difference, every, forEach, isObject, keyBy, map as mapToArray, remove, some } from 'lodash'
|
||||
import { noSuchObject, notEnoughResources, unauthorized } from 'xo-common/api-errors'
|
||||
@@ -155,7 +156,7 @@ export default class {
|
||||
throw noSuchObject(id, 'resourceSet')
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async updateResourceSet(
|
||||
$defer,
|
||||
id,
|
||||
@@ -374,7 +375,7 @@ export default class {
|
||||
await Promise.all(mapToArray(sets, set => this._save(set)))
|
||||
}
|
||||
|
||||
@deferrable
|
||||
@decorateWith(deferrable)
|
||||
async setVmResourceSet($defer, vmId, resourceSetId, force = false) {
|
||||
const xapi = this._app.getXapi(vmId)
|
||||
const previousResourceSetId = xapi.xo.getData(vmId, 'resourceSet')
|
||||
|
||||
Reference in New Issue
Block a user