allow to patch one host only and not the whole pool

This commit is contained in:
Olivier Lambert
2015-05-02 18:14:50 +02:00
parent 5330cc5ae9
commit 6fb5fb63e7
4 changed files with 76 additions and 4 deletions

View File

@@ -47,10 +47,11 @@
"lodash.assign": "^3.0.0",
"lodash.bind": "^3.0.0",
"lodash.clone": "^3.0.1",
"lodash.difference": "^3.0.1",
"lodash.difference": "^3.2.0",
"lodash.filter": "^3.1.0",
"lodash.find": "^3.0.0",
"lodash.findindex": "^3.0.0",
"lodash.findlast": "^3.2.0",
"lodash.foreach": "^3.0.1",
"lodash.has": "^3.0.0",
"lodash.includes": "^3.1.1",

View File

@@ -1,4 +1,10 @@
{$coroutine, $wait} = require '../fibers-utils'
$request = require('bluebird').promisify(require('request'))
{parseXml} = require '../utils'
$findLast = require 'lodash.findlast'
$difference = require 'lodash.difference'
$forEach = require 'lodash.foreach'
$find = require 'lodash.find'
#=====================================================================
@@ -206,3 +212,55 @@ createNetwork.resolve = {
}
createNetwork.permission = 'admin'
exports.createNetwork = createNetwork
#---------------------------------------------------------------------
# Returns an array of missing new patches in the host
# Returns an empty array if up-to-date
# Throws an error if the host is not running the latest XS version
patchCheck = $coroutine ({host}) ->
xapi = @getXAPI host
[response, body] = $wait $request {
method: 'get'
rejectUnauthorized: false
url: 'http://updates.xensource.com/XenServer/updates.xml'
}
if response.statusCode isnt 200
throw new Error('Cannot fetch the patch list from Citrix')
json = parseXml(body)
# get the latest version of XS in the XML
latestVersion = $findLast(json.patchdata.serverversions.version, 'latest': 'true')
if host.version isnt latestVersion.value
throw new Error('Please upgrade to '+latestVersion.name)
# create the list of missing patches
missingPatchList = $difference(latestVersion.patch,host.patches)
# returns the list with patch name, description etc.
result = []
if missingPatchList
$forEach missingPatchList, (value, key) ->
currentPatch = $find(json.patchdata.patches.patch,value)
result[key] = {
uuid: currentPatch.uuid,
name_label: currentPatch['name-label'],
name_description: currentPatch['name-description'],
documentation: currentPatch['url'],
guidance: currentPatch['after-apply-guidance'],
date: currentPatch['timestamp'],
version: currentPatch['version'],
url: currentPatch['patch-url']
}
return result
patchCheck.params = {
id: { type: 'string' }
}
patchCheck.resolve = {
host: ['id', 'host'],
}
exports.patchCheck = patchCheck;

View File

@@ -38,17 +38,22 @@ set.resolve = {
exports.set = set
#---------------------------------------------------------------------
# Upload a patch and apply it
# If host is given, only apply to a host and not the whole pool
# FIXME
patch = $coroutine ({pool}) ->
patch = $coroutine ({pool, host}) ->
xapi = @getXAPI pool
host = @getObject pool.master, 'host'
taskRef = $wait xapi.call 'task.create', 'Patch upload from XO', ''
@watchTask taskRef
.then $coroutine (patchRef) ->
$debug 'Patch upload succeeded'
xapi.call 'pool_patch.pool_apply', patchRef
if not host
xapi.call 'pool_patch.pool_apply', patchRef
else
host = @getObject host
xapi.call 'pool_patch.apply', patchRef, host.ref
return
.catch (error) ->
$debug 'Patch upload failed: %j', error
@@ -57,6 +62,9 @@ patch = $coroutine ({pool}) ->
xapi.call 'task.destroy', taskRef
return
if not host
host = @getObject pool.master, 'host'
url = $wait @registerProxyRequest {
# Receive a POST but send a PUT.
method: 'put'
@@ -75,6 +83,7 @@ patch = $coroutine ({pool}) ->
patch.params = {
pool: { type: 'string' },
host: { type: 'string', optional: true },
}
patch.resolve = {

View File

@@ -434,6 +434,10 @@ module.exports = ->
if: $isVMRunning
val: -> @val.CPUs.number
}
version: -> @genval.software_version.product_version
build: -> @genval.software_version.build_number
}
#-------------------------------------------------------------------