diff --git a/src/api.js b/src/api.js index 9636ef3..32c6e0c 100644 --- a/src/api.js +++ b/src/api.js @@ -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); + }, }, };