Various updates.

This commit is contained in:
Julien Fontanet 2013-10-04 15:29:22 +02:00
parent 424c6403e1
commit 0472c22b08
2 changed files with 22 additions and 20 deletions

View File

@ -549,19 +549,21 @@ Api.fn.xo = {
Api.fn.xapi = {
'__catchAll': function (session, req) {
var RE = /^xapi\.(pool|host|vm|network|sr|vdi|pif|vif)\.getAll$/;
var match;
if (!(match = req.method.match(RE)))
var RE = /^xapi\.(.*)\.getAll$/;
var match = req.method.match(RE);
var collection;
if (!match || !(collection = this.xo.xobjs[match[1]]))
{
throw Api.err.INVALID_METHOD;
}
var xobjs = this.xo.xobjs;
var collection = xobjs[match[1]] || xobjs[match[1].toUpperCase()];
return collection.get();
},
'getClasses': function () {
return this.xo.xclasses;
},
'vm': {
'pause': function (session, req) {
var p_id = req.params.id;

View File

@ -315,24 +315,24 @@ Xo.prototype.start = function (cfg) {
xo.computeStats();
return function loop() {
return xapi.call('event.next').then(function (event) {
event = event[0]; // @todo Handle multiple events.
return xapi.call('event.next').then(function (events) {
_.each(events, function (event) {
var collection = xobjs[xclasses_map[event.class]];
if (collection)
{
var record = event.snapshot;
record.id = event.ref;
record.pool = pool_id;
var collection = xobjs[xclasses_map[event.class]];
if (collection)
{
var record = event.snapshot;
record.id = event.ref;
record.pool = pool_id;
console.log(xapi.host, event.class, event.ref);
console.log(xapi.host, event.class, event.ref);
// @todo Handle operation types.
collection.add(event.snapshot, {'replace': true});
// @todo Handle operation types.
collection.add(event.snapshot, {'replace': true});
xo.computeStats();
}
}
});
xo.computeStats();
return loop();
}).fail(function (error) {
if ('SESSION_NOT_REGISTERED' === error[0])