error when i register function callbacks for domain events
zhenfdfs opened this issue · 6 comments
I want my ios app receive the event of my virtual machine, so i need to monitor all the event. But I encounter an issue when I use this function registerDomainEvent .Could anyone help me? Very thanks!
[root@TEST-LC-NC-0-0-31 ~]# node event_cb.js
libvirt: Remote Driver error : adding cb to list
/root/event_cb.js:14
hyper.registerDomainEvent(event);
^
[object Error]
[root@TEST-LC-NC-0-0-31 ~]#
My code as follows:
1 var libvirt = require('libvirt');
2
3 var Hypervisor = libvirt.Hypervisor;
4 var hyper = new Hypervisor('qemu:///system');
5
6 var domain = hyper.lookupDomainById(173);
7
8 var event = { 'evtype': hyper.VIR_DOMAIN_EVENT_ID_REBOOT ,
9 'domain':domain,
10 'callback': function(hyp, dom, data) {
11 console.log('callback');
12 }
13 };
14 hyper.registerDomainEvent(event);
I use kvm for hypervisor and the version of libvirt is 1.2.0
I'm not sure I fully understand. What is the exact error you are getting?
Thanks for c4milo 's reply. Let me have a detail describle. I run a short js script. All of the js code as follow:
1 var libvirt = require('libvirt');
2
3 var Hypervisor = libvirt.Hypervisor;
4 var hyper = new Hypervisor('qemu:///system');
5
6 var domain = hyper.lookupDomainById(173);
7
8 var event = { 'evtype': hyper.VIR_DOMAIN_EVENT_ID_REBOOT ,
9 'domain':domain,
10 'callback': function(hyp, dom, data) {
11 console.log('callback');
12 }
13 };
14 hyper.registerDomainEvent(event);
After run this js script , I get an error. The error msg as follow
libvirt: Remote Driver error : adding cb to list
/root/event_cb.js:14
hyper.registerDomainEvent(event);
^
[object Error]
are you sure hyper.lookupDomainById(173);
is returning something?
First , you've to call libvirt.setupEvent() to start the event loop handling.
Then here is an example i'm using :
libvirt.setupEvent(); // self.connection is an Hypervisor instance. self.connection.registerDomainEvent({evtype: self.connection.VIR_DOMAIN_EVENT_ID_LIFECYCLE, callback: function(hv, dom, data) { console.log("[virt] state change "+ data.evtype + " " + data.detail); var id = dom.getUUID(); switch(data.evtype) { case 0: // defined break; case 1: // undef break; case 2: // started break; case 5: break; default: break; } }});
Hope it helps
Anthony.