Skip to content

Commit

Permalink
qemu reboot function added
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrounger committed Jul 17, 2020
1 parent d89a916 commit def0678
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
node_modules
nbproject
admin/i18n/flat.txt
admin/i18n/*/flat.txt
admin/i18n/*/flat.txt
iobroker.proxmox.code-workspace
package-lock.json
6 changes: 6 additions & 0 deletions lib/proxmox.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ proxmox.prototype.qemuResume = function (node,type,ID, callback) {
callback(data);
});
}
proxmox.prototype.qemuReboot = function (node,type,ID, callback) {
let data = {};
this._get(`/nodes/${node}/${type}/${ID}/status/reboot`, 'post').then(data => {
callback(data);
});
}
proxmox.prototype.nodeReboot = function (node, callback) {
let data = 'reboot';
this._get(`/nodes/${node}/status`, 'post',data).then(data => {
Expand Down
32 changes: 26 additions & 6 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ adapter.on('stateChange', function (id, state) {
setTimeout(sendRequest, 10000);
});
break;
case 'reboot':
proxmox.qemuReboot(node, type, vmid, function (data) {
adapter.log.info(data)
sendRequest();
setTimeout(sendRequest, 10000);
});
break;

default:
break;
Expand Down Expand Up @@ -263,7 +270,7 @@ function _getNodes(callback) {
proxmox.status(function (data) {

devices = data.data;
if(typeof(data.data) === 'undefined'){
if (typeof (data.data) === 'undefined') {
adapter.log.error('Can not get Proxmox nodes! please restart adapter');
return
}
Expand Down Expand Up @@ -377,7 +384,7 @@ function _setNodes(devices, callback) {
var node_vals = data.data;

//check if node is empty
if (typeof(node_vals.uptime) === 'undefined') return
if (typeof (node_vals.uptime) === 'undefined') return

adapter.setState(sid + '.uptime', node_vals.uptime, true);
// adapter.setState(sid + '.' + name, val, true)
Expand Down Expand Up @@ -456,7 +463,7 @@ function _createVM(node, callback) {
proxmox.all(function (data) {
var qemu = data.data;

if(!qemu || !Array.isArray(qemu)) return
if (!qemu || !Array.isArray(qemu)) return

for (var i = 0; i < qemu.length; i++) {

Expand All @@ -466,8 +473,8 @@ function _createVM(node, callback) {
proxmox.qemuStatus(qemu[i].node, type, qemu[i].vmid, function (data) {

var aktQemu = data.data;
if(!aktQemu) return

if (!aktQemu) return

sid = adapter.namespace + '.' + type + '_' + aktQemu.name;

Expand Down Expand Up @@ -526,6 +533,19 @@ function _createVM(node, callback) {
},
native: {}
});
adapter.setObjectNotExists(sid + '.reboot', {
type: 'state',
common: {
name: 'reboot',
type: 'boolean',
role: 'button',
read: true,
write: true,
desc: 'reboot VM'

},
native: {}
});

findState(sid, aktQemu, (states) => {
states.forEach(function (element) {
Expand All @@ -539,7 +559,7 @@ function _createVM(node, callback) {
proxmox.storageStatus(qemu[i].node, qemu[i].storage, function (data, name) {
var aktQemu = data.data;

if(!aktQemu) return
if (!aktQemu) return

sid = adapter.namespace + '.' + type + '_' + name;
adapter.log.debug("new storage: " + name);
Expand Down

0 comments on commit def0678

Please sign in to comment.