Merge pull request #135 from vatesfr/pierre-emergency-host-shutdown

emergencyHostShutdown(hostId) : suspends all the VMs running on the host
This commit is contained in:
Olivier Lambert 2015-11-20 17:30:27 +01:00
commit 6efb90c94e
3 changed files with 35 additions and 2 deletions

View File

@ -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)

View File

@ -503,7 +503,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

View File

@ -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.