Skip to content

Commit

Permalink
Merge pull request #43 from atoy40/async-refactor-update
Browse files Browse the repository at this point in the history
Added convenient method + JSON fix
  • Loading branch information
atoy40 committed Apr 15, 2015
2 parents 451a034 + 3fa89d3 commit 732ebd8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,31 @@ Promise.promisifyAll(libvirt.Secret.prototype);
Promise.promisifyAll(libvirt.StoragePool.prototype);
Promise.promisifyAll(libvirt.StorageVolume.prototype);

/*
* A helper method returning an 'all domains' promise.
*/
libvirt.Hypervisor.prototype.getAllDomains = function() {
var defined;

return this.listDefinedDomainsAsync()
.map(function(name) {
return this.lookupDomainByNameAsync(name);
}.bind(this))
.then(function(domains) {
defined = domains;
return this.listActiveDomainsAsync();
}.bind(this))
.map(function(id) {
return this.lookupDomainByIdAsync(id);
}.bind(this))
.then(function(domains) {
return domains.concat(defined);
})
}

module.exports = {
Promise: Promise,
startEventLoop: libvirt.setupEvent,
createHypervisor: function(uri, options) {
return new libvirt.Hypervisor(uri, options);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"nan": "^1.7.0",
"bindings": "^1.2.1",
"bluebird": "^2.9.24",
"bluebird": "^2.9.24"
},
"devDependencies": {
"mocha": "^2.2.1",
Expand Down

0 comments on commit 732ebd8

Please sign in to comment.