add some actions in backend: clean[reboot/shutdown] and start a VM

This commit is contained in:
Olivier Lambert 2013-08-02 16:02:07 +02:00
parent 0b9f8b8340
commit 94b88d8f8a

View File

@ -619,7 +619,8 @@ Api.fn.xapi = {
return xapi.call('VM.pause', vm.get('ref'));
}).thenResolve(true);
},
},
'unpause': function (session, req) {
var p_id = req.params.id;
if (!p_id)
@ -646,5 +647,88 @@ Api.fn.xapi = {
return xapi.call('VM.unpause', vm.get('ref'));
}).thenResolve(true);
},
'clean_reboot': function (session, req) {
var p_id = req.params.id;
if (!p_id)
{
throw Api.err.INVALID_PARAMS;
}
var xo = this.xo;
var vm;
return this.checkPermission(session, 'write').then(function () {
return xo.vms.first(p_id);
}).then(function (tmp) {
vm = tmp;
if (!vm)
{
throw Api.err.NO_SUCH_OBJECT;
}
return xo.pools.first(vm.get('pool_uuid'));
}).then(function (pool) {
var xapi = xo.connections[pool.get('uuid')];
return xapi.call('VM.clean_reboot', vm.get('ref'));
}).thenResolve(true);
},
'clean_shutdown': function (session, req) {
var p_id = req.params.id;
if (!p_id)
{
throw Api.err.INVALID_PARAMS;
}
var xo = this.xo;
var vm;
return this.checkPermission(session, 'write').then(function () {
return xo.vms.first(p_id);
}).then(function (tmp) {
vm = tmp;
if (!vm)
{
throw Api.err.NO_SUCH_OBJECT;
}
return xo.pools.first(vm.get('pool_uuid'));
}).then(function (pool) {
var xapi = xo.connections[pool.get('uuid')];
return xapi.call('VM.clean_shutdown', vm.get('ref'));
}).thenResolve(true);
},
// we choose to start with default additional parameters:
// false (don't start paused) and false (don't skip pre-boot checks)
'start': function (session, req) {
var p_id = req.params.id;
if (!p_id)
{
throw Api.err.INVALID_PARAMS;
}
var xo = this.xo;
var vm;
return this.checkPermission(session, 'write').then(function () {
return xo.vms.first(p_id);
}).then(function (tmp) {
vm = tmp;
if (!vm)
{
throw Api.err.NO_SUCH_OBJECT;
}
return xo.pools.first(vm.get('pool_uuid'));
}).then(function (pool) {
var xapi = xo.connections[pool.get('uuid')];
return xapi.call('VM.start', vm.get('ref'), false, false);
}).thenResolve(true);
},
},
};