mirror of
https://github.com/mclueppers/xo-server.git
synced 2025-07-29 17:04:44 +02:00
add some actions in backend: clean[reboot/shutdown] and start a VM
This commit is contained in:
parent
0b9f8b8340
commit
94b88d8f8a
86
src/api.js
86
src/api.js
@ -619,7 +619,8 @@ Api.fn.xapi = {
|
|||||||
|
|
||||||
return xapi.call('VM.pause', vm.get('ref'));
|
return xapi.call('VM.pause', vm.get('ref'));
|
||||||
}).thenResolve(true);
|
}).thenResolve(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
'unpause': function (session, req) {
|
'unpause': function (session, req) {
|
||||||
var p_id = req.params.id;
|
var p_id = req.params.id;
|
||||||
if (!p_id)
|
if (!p_id)
|
||||||
@ -646,5 +647,88 @@ Api.fn.xapi = {
|
|||||||
return xapi.call('VM.unpause', vm.get('ref'));
|
return xapi.call('VM.unpause', vm.get('ref'));
|
||||||
}).thenResolve(true);
|
}).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);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user