chore(xen-api): convert to ESM (#7181)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { Xapi } from './index.mjs'
|
||||
import CLI from 'xen-api/dist/cli.js'
|
||||
import { main } from 'xen-api/cli-lib.mjs'
|
||||
|
||||
CLI.default(opts => new Xapi(opts)).catch(console.error.bind(console, 'FATAL'))
|
||||
import { Xapi } from './index.mjs'
|
||||
|
||||
main(opts => new Xapi(opts)).catch(console.error.bind(console, 'FATAL'))
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
- @xen-orchestra/backups patch
|
||||
- @xen-orchestra/cr-seed-cli major
|
||||
- @xen-orchestra/vmware-explorer patch
|
||||
- xen-api major
|
||||
- xo-server patch
|
||||
- xo-server-netbox minor
|
||||
- xo-vmdk-to-vhd patch
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = require('../../@xen-orchestra/babel-config')(require('./package.json'))
|
||||
@@ -1 +0,0 @@
|
||||
../../scripts/babel-eslintrc.js
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Cancel } from 'promise-toolbox'
|
||||
|
||||
import XapiError from './_XapiError'
|
||||
import XapiError from './_XapiError.mjs'
|
||||
|
||||
export default task => {
|
||||
const { status } = task
|
||||
@@ -1,8 +1,6 @@
|
||||
'use strict'
|
||||
import t from 'tap'
|
||||
|
||||
const t = require('tap')
|
||||
|
||||
const parseUrl = require('./dist/_parseUrl.js').default
|
||||
import parseUrl from './_parseUrl.mjs'
|
||||
|
||||
const data = {
|
||||
'xcp.company.lan': {
|
||||
@@ -1,4 +1,4 @@
|
||||
import mapValues from 'lodash/mapValues'
|
||||
import mapValues from 'lodash/mapValues.js'
|
||||
|
||||
export default function replaceSensitiveValues(value, replacement) {
|
||||
function helper(value, name) {
|
||||
15
packages/xen-api/src/cli.js → packages/xen-api/cli-lib.mjs
Executable file → Normal file
15
packages/xen-api/src/cli.js → packages/xen-api/cli-lib.mjs
Executable file → Normal file
@@ -1,9 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/* eslint-disable no-console */
|
||||
import blocked from 'blocked'
|
||||
import createDebug from 'debug'
|
||||
import filter from 'lodash/filter'
|
||||
import find from 'lodash/find'
|
||||
import filter from 'lodash/filter.js'
|
||||
import find from 'lodash/find.js'
|
||||
import L from 'lodash'
|
||||
import minimist from 'minimist'
|
||||
import pw from 'pw'
|
||||
@@ -42,7 +41,7 @@ function getAllBoundDescriptors(object) {
|
||||
|
||||
const usage = 'Usage: xen-api <url> [<user> [<password>]]'
|
||||
|
||||
async function main(createClient) {
|
||||
export async function main(createClient) {
|
||||
const opts = minimist(process.argv.slice(2), {
|
||||
string: ['proxy', 'session-id', 'transport'],
|
||||
boolean: ['allow-unauthorized', 'help', 'read-only', 'verbose'],
|
||||
@@ -128,8 +127,4 @@ async function main(createClient) {
|
||||
await xapi.disconnect()
|
||||
} catch (error) {}
|
||||
}
|
||||
export default main
|
||||
|
||||
if (module.parent === null) {
|
||||
main(require('./').createClient).catch(console.error.bind(console, 'FATAL'))
|
||||
}
|
||||
/* eslint-enable no-console */
|
||||
6
packages/xen-api/cli.mjs
Executable file
6
packages/xen-api/cli.mjs
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { createClient } from './index.mjs'
|
||||
import { main } from './cli-lib.mjs'
|
||||
|
||||
main(createClient).catch(console.error.bind(console, 'FATAL'))
|
||||
3
packages/xen-api/examples/env.mjs
Normal file
3
packages/xen-api/examples/env.mjs
Normal file
@@ -0,0 +1,3 @@
|
||||
if (process.env.DEBUG === undefined) {
|
||||
process.env.DEBUG = 'xen-api'
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
process.env.DEBUG = 'xen-api'
|
||||
import './env.mjs'
|
||||
|
||||
const createProgress = require('progress-stream')
|
||||
const createTop = require('process-top')
|
||||
const defer = require('golike-defer').default
|
||||
const getopts = require('getopts')
|
||||
const { CancelToken } = require('promise-toolbox')
|
||||
import createProgress from 'progress-stream'
|
||||
import createTop from 'process-top'
|
||||
import getopts from 'getopts'
|
||||
import { defer } from 'golike-defer'
|
||||
import { CancelToken } from 'promise-toolbox'
|
||||
|
||||
const { createClient } = require('../')
|
||||
import { createClient } from '../index.mjs'
|
||||
|
||||
const { createOutputStream, formatProgress, pipeline, resolveRecord, throttle } = require('./utils')
|
||||
import { createOutputStream, formatProgress, pipeline, resolveRecord, throttle } from './utils.mjs'
|
||||
|
||||
defer(async ($defer, rawArgs) => {
|
||||
const {
|
||||
@@ -1,15 +1,15 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
process.env.DEBUG = '*'
|
||||
import './env.mjs'
|
||||
|
||||
const createProgress = require('progress-stream')
|
||||
const defer = require('golike-defer').default
|
||||
const getopts = require('getopts')
|
||||
const { CancelToken } = require('promise-toolbox')
|
||||
import createProgress from 'progress-stream'
|
||||
import getopts from 'getopts'
|
||||
import { defer } from 'golike-defer'
|
||||
import { CancelToken } from 'promise-toolbox'
|
||||
|
||||
const { createClient } = require('../')
|
||||
import { createClient } from '../index.mjs'
|
||||
|
||||
const { createOutputStream, formatProgress, pipeline, resolveRecord } = require('./utils')
|
||||
import { createOutputStream, formatProgress, pipeline, resolveRecord } from './utils.mjs'
|
||||
|
||||
defer(async ($defer, rawArgs) => {
|
||||
const {
|
||||
@@ -1,15 +1,15 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
process.env.DEBUG = '*'
|
||||
import './env.mjs'
|
||||
|
||||
const defer = require('golike-defer').default
|
||||
const getopts = require('getopts')
|
||||
const { CancelToken } = require('promise-toolbox')
|
||||
const { createVhdStreamWithLength } = require('vhd-lib')
|
||||
import getopts from 'getopts'
|
||||
import { defer } from 'golike-defer'
|
||||
import { CancelToken } from 'promise-toolbox'
|
||||
import { createVhdStreamWithLength } from 'vhd-lib'
|
||||
|
||||
const { createClient } = require('../')
|
||||
import { createClient } from '../index.mjs'
|
||||
|
||||
const { createInputStream, resolveRef } = require('./utils')
|
||||
import { createInputStream, resolveRef } from './utils.mjs'
|
||||
|
||||
defer(async ($defer, argv) => {
|
||||
const opts = getopts(argv, { boolean: ['events', 'raw', 'remove-length'], string: ['sr', 'vdi'] })
|
||||
@@ -1,13 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
process.env.DEBUG = '*'
|
||||
import './env.mjs'
|
||||
|
||||
const defer = require('golike-defer').default
|
||||
const { CancelToken } = require('promise-toolbox')
|
||||
import { defer } from 'golike-defer'
|
||||
import { CancelToken } from 'promise-toolbox'
|
||||
|
||||
const { createClient } = require('../')
|
||||
import { createClient } from '../index.mjs'
|
||||
|
||||
const { createInputStream, resolveRef } = require('./utils')
|
||||
import { createInputStream, resolveRef } from './utils.mjs'
|
||||
|
||||
defer(async ($defer, args) => {
|
||||
if (args.length < 1) {
|
||||
@@ -1,15 +1,16 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
require('source-map-support').install()
|
||||
import 'source-map-support/register.js'
|
||||
|
||||
const { forEach, size } = require('lodash')
|
||||
import forEach from 'lodash/forEach.js'
|
||||
import size from 'lodash/size.js'
|
||||
|
||||
const { createClient } = require('../')
|
||||
import { createClient } from '../index.mjs'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
return console.log('Usage: log-events <XS URL>')
|
||||
throw new Error('Usage: log-events <XS URL>')
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
2667
packages/xen-api/examples/package-lock.json
generated
2667
packages/xen-api/examples/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -3,10 +3,12 @@
|
||||
"getopts": "^2.2.3",
|
||||
"golike-defer": "^0.5.1",
|
||||
"human-format": "^0.11.0",
|
||||
"process-top": "^1.0.0",
|
||||
"lodash": "^4.17.21",
|
||||
"process-top": "^1.2.0",
|
||||
"progress-stream": "^2.0.0",
|
||||
"promise-toolbox": "^0.19.2",
|
||||
"readable-stream": "^3.1.1",
|
||||
"readable-stream": "^4.4.2",
|
||||
"source-map-support": "^0.5.21",
|
||||
"throttle": "^1.0.3",
|
||||
"vhd-lib": "^4.6.1"
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
'use strict'
|
||||
import { createReadStream, createWriteStream, statSync } from 'fs'
|
||||
import { fromCallback } from 'promise-toolbox'
|
||||
import { PassThrough, pipeline as Pipeline } from 'readable-stream'
|
||||
import humanFormat from 'human-format'
|
||||
import Throttle from 'throttle'
|
||||
|
||||
const { createReadStream, createWriteStream, statSync } = require('fs')
|
||||
const { fromCallback } = require('promise-toolbox')
|
||||
const { PassThrough, pipeline } = require('readable-stream')
|
||||
const humanFormat = require('human-format')
|
||||
const Throttle = require('throttle')
|
||||
import Ref from '../_Ref.mjs'
|
||||
|
||||
const Ref = require('../dist/_Ref').default
|
||||
|
||||
exports.createInputStream = path => {
|
||||
export const createInputStream = path => {
|
||||
if (path === undefined || path === '-') {
|
||||
return process.stdin
|
||||
}
|
||||
@@ -20,7 +18,7 @@ exports.createInputStream = path => {
|
||||
return stream
|
||||
}
|
||||
|
||||
exports.createOutputStream = path => {
|
||||
export const createOutputStream = path => {
|
||||
if (path !== undefined && path !== '-') {
|
||||
return createWriteStream(path)
|
||||
}
|
||||
@@ -34,8 +32,8 @@ exports.createOutputStream = path => {
|
||||
const formatSizeOpts = { scale: 'binary', unit: 'B' }
|
||||
const formatSize = bytes => humanFormat(bytes, formatSizeOpts)
|
||||
|
||||
exports.formatProgress = p =>
|
||||
[
|
||||
export const formatProgress = p => {
|
||||
return [
|
||||
formatSize(p.transferred),
|
||||
' / ',
|
||||
formatSize(p.length),
|
||||
@@ -47,12 +45,13 @@ exports.formatProgress = p =>
|
||||
formatSize(p.speed),
|
||||
'/s',
|
||||
].join('')
|
||||
}
|
||||
|
||||
exports.pipeline = (...streams) => {
|
||||
export const pipeline = (...streams) => {
|
||||
return fromCallback(cb => {
|
||||
streams = streams.filter(_ => _ != null)
|
||||
streams.push(cb)
|
||||
pipeline.apply(undefined, streams)
|
||||
Pipeline.apply(undefined, streams)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -68,9 +67,9 @@ const resolveRef = (xapi, type, refOrUuidOrNameLabel) =>
|
||||
})
|
||||
)
|
||||
|
||||
exports.resolveRecord = async (xapi, type, refOrUuidOrNameLabel) =>
|
||||
export const resolveRecord = async (xapi, type, refOrUuidOrNameLabel) =>
|
||||
xapi.getRecord(type, await resolveRef(xapi, type, refOrUuidOrNameLabel))
|
||||
|
||||
exports.resolveRef = resolveRef
|
||||
export { resolveRef }
|
||||
|
||||
exports.throttle = opts => (opts != null ? new Throttle(opts) : undefined)
|
||||
export const throttle = opts => (opts != null ? new Throttle(opts) : undefined)
|
||||
@@ -3,25 +3,26 @@ import dns from 'dns'
|
||||
import kindOf from 'kindof'
|
||||
import ms from 'ms'
|
||||
import httpRequest from 'http-request-plus'
|
||||
import map from 'lodash/map'
|
||||
import noop from 'lodash/noop'
|
||||
import map from 'lodash/map.js'
|
||||
import noop from 'lodash/noop.js'
|
||||
import ProxyAgent from 'proxy-agent'
|
||||
import { coalesceCalls } from '@vates/coalesce-calls'
|
||||
import { Collection } from 'xo-collection'
|
||||
import { EventEmitter } from 'events'
|
||||
import { Index } from 'xo-collection/index'
|
||||
import { Index } from 'xo-collection/index.js'
|
||||
import { cancelable, defer, fromCallback, ignoreErrors, pDelay, pRetry, pTimeout } from 'promise-toolbox'
|
||||
import { limitConcurrency } from 'limit-concurrency-decorator'
|
||||
import { decorateClass } from '@vates/decorate-with'
|
||||
|
||||
import debug from './_debug'
|
||||
import getTaskResult from './_getTaskResult'
|
||||
import isGetAllRecordsMethod from './_isGetAllRecordsMethod'
|
||||
import isReadOnlyCall from './_isReadOnlyCall'
|
||||
import makeCallSetting from './_makeCallSetting'
|
||||
import parseUrl from './_parseUrl'
|
||||
import Ref from './_Ref'
|
||||
import replaceSensitiveValues from './_replaceSensitiveValues'
|
||||
import transports from './transports'
|
||||
import debug from './_debug.mjs'
|
||||
import getTaskResult from './_getTaskResult.mjs'
|
||||
import isGetAllRecordsMethod from './_isGetAllRecordsMethod.mjs'
|
||||
import isReadOnlyCall from './_isReadOnlyCall.mjs'
|
||||
import makeCallSetting from './_makeCallSetting.mjs'
|
||||
import parseUrl from './_parseUrl.mjs'
|
||||
import Ref from './_Ref.mjs'
|
||||
import replaceSensitiveValues from './_replaceSensitiveValues.mjs'
|
||||
import transports from './transports/index.mjs'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@@ -286,7 +287,6 @@ export class Xapi extends EventEmitter {
|
||||
: this._sessionCall(method, args)
|
||||
}
|
||||
|
||||
@cancelable
|
||||
async callAsync($cancelToken, method, ...args) {
|
||||
if (this._readOnly && !isReadOnlyCall(method, args)) {
|
||||
throw new Error(`cannot call ${method}() in read only mode`)
|
||||
@@ -379,7 +379,6 @@ export class Xapi extends EventEmitter {
|
||||
// HTTP requests
|
||||
// ===========================================================================
|
||||
|
||||
@cancelable
|
||||
async getResource($cancelToken, pathname, { host, query, task } = {}) {
|
||||
const taskRef = await this._autoTask(task, `Xapi#getResource ${pathname}`)
|
||||
|
||||
@@ -439,7 +438,6 @@ export class Xapi extends EventEmitter {
|
||||
return response
|
||||
}
|
||||
|
||||
@cancelable
|
||||
async putResource($cancelToken, body, pathname, { host, query, task } = {}) {
|
||||
if (this._readOnly) {
|
||||
throw new Error('cannot put resource in read only mode')
|
||||
@@ -1375,6 +1373,12 @@ export class Xapi extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
decorateClass(Xapi, {
|
||||
callAsync: cancelable,
|
||||
getResource: cancelable,
|
||||
putResource: cancelable,
|
||||
})
|
||||
|
||||
// ===================================================================
|
||||
|
||||
// The default value is a factory function.
|
||||
@@ -23,15 +23,16 @@
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"preferGlobal": false,
|
||||
"main": "dist/",
|
||||
"main": "./index.mjs",
|
||||
"bin": {
|
||||
"xen-api": "dist/cli.js"
|
||||
"xen-api": "./cli.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=14"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vates/coalesce-calls": "^0.1.0",
|
||||
"@vates/decorate-with": "^2.0.0",
|
||||
"bind-property-descriptor": "^2.0.0",
|
||||
"blocked": "^1.2.1",
|
||||
"debug": "^4.0.1",
|
||||
@@ -51,21 +52,10 @@
|
||||
"xo-collection": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/plugin-proposal-decorators": "^7.0.0",
|
||||
"@babel/preset-env": "^7.8.0",
|
||||
"cross-env": "^7.0.2",
|
||||
"rimraf": "^5.0.1",
|
||||
"tap": "^16.1.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
|
||||
"dev": "cross-env NODE_ENV=development babel --watch --source-maps --out-dir=dist/ src/",
|
||||
"plot": "gnuplot -p memory-test.gnu",
|
||||
"prebuild": "rimraf dist/",
|
||||
"predev": "yarn run prebuild",
|
||||
"prepublishOnly": "yarn run build",
|
||||
"postversion": "npm publish",
|
||||
"test": "tap"
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import auto from './auto.js'
|
||||
import jsonRpc from './json-rpc.js'
|
||||
import xmlRpc from './xml-rpc.js'
|
||||
|
||||
export default {
|
||||
__proto__: null,
|
||||
|
||||
auto,
|
||||
'json-rpc': jsonRpc,
|
||||
'xml-rpc': xmlRpc,
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import jsonRpc from './json-rpc'
|
||||
import UnsupportedTransport from './_UnsupportedTransport'
|
||||
import xmlRpc from './xml-rpc'
|
||||
import jsonRpc from './json-rpc.mjs'
|
||||
import UnsupportedTransport from './_UnsupportedTransport.mjs'
|
||||
import xmlRpc from './xml-rpc.mjs'
|
||||
|
||||
const factories = [jsonRpc, xmlRpc]
|
||||
const { length } = factories
|
||||
11
packages/xen-api/transports/index.mjs
Normal file
11
packages/xen-api/transports/index.mjs
Normal file
@@ -0,0 +1,11 @@
|
||||
import auto from './auto.mjs'
|
||||
import jsonRpc from './json-rpc.mjs'
|
||||
import xmlRpc from './xml-rpc.mjs'
|
||||
|
||||
export default {
|
||||
__proto__: null,
|
||||
|
||||
auto,
|
||||
'json-rpc': jsonRpc,
|
||||
'xml-rpc': xmlRpc,
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import httpRequestPlus from 'http-request-plus'
|
||||
import { format, parse } from 'json-rpc-protocol'
|
||||
|
||||
import XapiError from '../_XapiError'
|
||||
import XapiError from '../_XapiError.mjs'
|
||||
|
||||
import UnsupportedTransport from './_UnsupportedTransport'
|
||||
import UnsupportedTransport from './_UnsupportedTransport.mjs'
|
||||
|
||||
// https://github.com/xenserver/xenadmin/blob/0df39a9d83cd82713f32d24704852a0fd57b8a64/XenModel/XenAPI/Session.cs#L403-L433
|
||||
export default ({ secureOptions, url, agent }) => {
|
||||
@@ -1,9 +1,9 @@
|
||||
import { createClient, createSecureClient } from 'xmlrpc'
|
||||
import xmlrpc from 'xmlrpc'
|
||||
import { promisify } from 'promise-toolbox'
|
||||
|
||||
import XapiError from '../_XapiError'
|
||||
import XapiError from '../_XapiError.mjs'
|
||||
|
||||
import prepareXmlRpcParams from './_prepareXmlRpcParams'
|
||||
import prepareXmlRpcParams from './_prepareXmlRpcParams.mjs'
|
||||
|
||||
const logError = error => {
|
||||
if (error.res) {
|
||||
@@ -32,7 +32,7 @@ const parseResult = result => {
|
||||
|
||||
export default ({ secureOptions, url: { hostnameRaw, pathname, port, protocol }, agent }) => {
|
||||
const secure = protocol === 'https:'
|
||||
const client = (secure ? createSecureClient : createClient)({
|
||||
const client = (secure ? xmlrpc.createSecureClient : xmlrpc.createClient)({
|
||||
...(secure ? secureOptions : undefined),
|
||||
agent,
|
||||
host: hostnameRaw,
|
||||
Reference in New Issue
Block a user