From ad4439ed5573759e1476dce47977e889d25e432c Mon Sep 17 00:00:00 2001 From: Pierre Date: Thu, 19 Nov 2015 17:03:12 +0100 Subject: [PATCH] emergencyHostShutdown(hostId) : suspends all the VMs running on the host and then shuts the host down --- src/api/host.coffee | 17 +++++++++++++++++ src/api/vm.coffee | 2 +- src/xapi.js | 18 +++++++++++++++++- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/api/host.coffee b/src/api/host.coffee index f0da629c6..b9a525f56 100644 --- a/src/api/host.coffee +++ b/src/api/host.coffee @@ -256,6 +256,23 @@ exports.installAllPatches = installAllPatches #--------------------------------------------------------------------- +emergencyShutdownHost = ({host}) -> + return @getXAPI(host).emergencyShutdownHost(host._xapiId) + +emergencyShutdownHost.description = 'suspend all VMs and shutdown host' + +emergencyShutdownHost.params = { + host: { type: 'string' } +} + +emergencyShutdownHost.resolve = { + host: ['host', 'host', 'administrate'] +} + +exports.emergencyShutdownHost = emergencyShutdownHost + +#--------------------------------------------------------------------- + stats = ({host, granularity}) -> return @getXapiHostStats(host, granularity) diff --git a/src/api/vm.coffee b/src/api/vm.coffee index 6d65dd360..7279b61b6 100644 --- a/src/api/vm.coffee +++ b/src/api/vm.coffee @@ -501,7 +501,7 @@ rollingSnapshot.resolve = { vm: ['id', 'VM', 'administrate'] } -rollingSnapshot.description = 'Snaphots a VM with a tagged name, and removes the oldest snapshot with the same tag according to depth' +rollingSnapshot.description = 'Snapshots a VM with a tagged name, and removes the oldest snapshot with the same tag according to depth' exports.rollingSnapshot = rollingSnapshot diff --git a/src/xapi.js b/src/xapi.js index 11d630346..d8d048f9b 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -23,7 +23,8 @@ import { mapToArray, noop, parseXml, - pFinally + pFinally, + pSettle } from './utils' import {JsonRpcError} from './api-errors' @@ -560,6 +561,21 @@ export default class Xapi extends XapiBase { } } + async emergencyShutdownHost (hostId) { + const host = this.getObject(hostId) + const vms = host.$resident_VMs + debug(`Emergency shutdown: ${host.name_label}`) + await pSettle( + mapToArray(vms, vm => { + if (!vm.is_control_domain) { + return this.call('VM.suspend', vm.$ref) + } + }) + ) + await this.call('host.disable', host.$ref) + await this.call('host.shutdown', host.$ref) + } + // ================================================================= // Disable the host and evacuate all its VMs.