48 lines
1.1 KiB
JavaScript
Executable File
48 lines
1.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
process.env.DEBUG = '*'
|
|
|
|
const defer = require('golike-defer').default
|
|
const pump = require('pump')
|
|
const { CancelToken, fromCallback } = require('promise-toolbox')
|
|
|
|
const { createClient } = require('../')
|
|
|
|
const { createOutputStream, resolveRef } = require('./utils')
|
|
|
|
defer(async ($defer, args) => {
|
|
if (args.length < 2) {
|
|
return console.log('Usage: export-vm <XS URL> <VM identifier> [<XVA file>]')
|
|
}
|
|
|
|
const xapi = createClient({
|
|
allowUnauthorized: true,
|
|
url: args[0],
|
|
watchEvents: false
|
|
})
|
|
|
|
await xapi.connect()
|
|
$defer(() => xapi.disconnect())
|
|
|
|
const { cancel, token } = CancelToken.source()
|
|
process.on('SIGINT', cancel)
|
|
|
|
// https://xapi-project.github.io/xen-api/importexport.html
|
|
const exportStream = await xapi.getResource(token, '/export/', {
|
|
query: {
|
|
ref: await resolveRef(xapi, 'VM', args[1]),
|
|
use_compression: 'true'
|
|
}
|
|
})
|
|
|
|
console.warn('Export task:', exportStream.headers['task-id'])
|
|
|
|
await fromCallback(cb => pump(
|
|
exportStream,
|
|
createOutputStream(args[2]),
|
|
cb
|
|
))
|
|
})(process.argv.slice(2)).catch(
|
|
console.error.bind(console, 'error')
|
|
)
|