committed by
Julien Fontanet
parent
0c7768f5d2
commit
b7b7e81468
@@ -5,8 +5,10 @@ $forEach = require 'lodash/forEach'
|
||||
endsWith = require 'lodash/endsWith'
|
||||
startsWith = require 'lodash/startsWith'
|
||||
{coroutine: $coroutine} = require 'bluebird'
|
||||
{format} = require 'json-rpc-peer'
|
||||
{
|
||||
extractProperty,
|
||||
mapToArray,
|
||||
parseXml
|
||||
} = require '../utils'
|
||||
|
||||
@@ -260,6 +262,42 @@ stats.resolve = {
|
||||
|
||||
exports.stats = stats;
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
|
||||
handleInstallSupplementalPack = $coroutine (req, res, { hostId }) ->
|
||||
xapi = @getXapi(hostId)
|
||||
|
||||
# Timeout seems to be broken in Node 4.
|
||||
# See https://github.com/nodejs/node/issues/3319
|
||||
req.setTimeout(43200000) # 12 hours
|
||||
req.length = req.headers['content-length']
|
||||
|
||||
try
|
||||
yield xapi.installSupplementalPack(req, { hostId })
|
||||
res.end(format.response(0))
|
||||
catch e
|
||||
res.writeHead(500)
|
||||
res.end(format.error(0, new Error(e.message)))
|
||||
|
||||
return
|
||||
|
||||
installSupplementalPack = $coroutine ({host}) ->
|
||||
return {
|
||||
$sendTo: yield @registerHttpRequest(handleInstallSupplementalPack, { hostId: host.id })
|
||||
}
|
||||
|
||||
installSupplementalPack.description = 'installs supplemental pack from ISO file'
|
||||
|
||||
installSupplementalPack.params = {
|
||||
host: { type: 'string' }
|
||||
}
|
||||
|
||||
installSupplementalPack.resolve = {
|
||||
host: ['host', 'host', 'admin']
|
||||
}
|
||||
|
||||
exports.installSupplementalPack = installSupplementalPack;
|
||||
|
||||
#=====================================================================
|
||||
|
||||
Object.defineProperty(exports, '__esModule', {
|
||||
|
||||
@@ -1105,6 +1105,36 @@ export default class Xapi extends XapiBase {
|
||||
return loop()
|
||||
}
|
||||
|
||||
async installSupplementalPack (stream, { hostId }) {
|
||||
if (!stream.length) {
|
||||
throw new Error('stream must have a length')
|
||||
}
|
||||
|
||||
let sr = this.pool.$default_SR
|
||||
|
||||
if (!sr) {
|
||||
sr = find(
|
||||
mapToArray(this.getObject(hostId, 'host').$PBDs, '$SR'),
|
||||
sr => sr && sr.content_type === 'user' && sr.physical_size - sr.physical_utilisation >= stream.length
|
||||
)
|
||||
|
||||
if (!sr) {
|
||||
throw new Error('no SR available to store installation file')
|
||||
}
|
||||
}
|
||||
|
||||
const vdi = await this.createVdi(stream.length, {
|
||||
sr: sr.$ref,
|
||||
name_label: '[XO] Supplemental pack ISO',
|
||||
name_description: 'Small temporary VDI to store a supplemental pack ISO.'
|
||||
})
|
||||
await this.importVdiContent(vdi.$id, stream, { format: VDI_FORMAT_RAW })
|
||||
|
||||
await this.call('host.call_plugin', this.getObject(hostId).$ref, 'install-supp-pack', 'install', { vdi: vdi.uuid })
|
||||
|
||||
return this._deleteVdi(vdi)
|
||||
}
|
||||
|
||||
async _importVm (stream, sr, onlyMetadata = false, onVmCreation = undefined) {
|
||||
const taskRef = await this._createTask('VM import')
|
||||
const query = {
|
||||
|
||||
Reference in New Issue
Block a user