Comments (6)
This is a feature of the libvirt api, not about the node wrapper : virConnectListDomains() returns a list of ID
note : I think we have to add support for the new libvirt function virConnectListAllDomains() (even if it's not directly link to your question) it fixes race problems we can have by calling two different functions to get all domains (virConnectListDomains followed by virConnectListDefinedDomains) :
http://libvirt.org/html/libvirt-libvirt-domain.html#virConnectListAllDomains
For your problem, you can just get the list of ID as a promise, then map() ids to names.
Anthony.
from node-libvirt.
@atoy40 would I need to keep track of the names myself or is there a way of accessing them via the node wrapper?
from node-libvirt.
@aafrey the node wrapper tracking them would be exactly like you tracking them in this case. The libvirt api does not provide a method for looking up names of all domains - you would have to get all the ids, lookup each by id (to get the actual Domain
object), and call getName()
on it, this is what @atoy40 was suggesting.
Even with the added support for virConnectListAllDomains
, we still end up with Domain
objects, which then need to have getName()
called on them, it saves you one step from the suggestion above. Currently node-libvirt binding is a 1-1 mapping from C to node.js, and I don't foresee us getting creative beyond that, however, there is precedent for extending the prototype of the existing modules, for instance: https://github.com/hooklift/node-libvirt/blob/master/lib/index.js#L55.
from node-libvirt.
I got this working, thanks for the advice! If you see a better way though let me know!
var libvirt = require('libvirt');
var hyper = new libvirt.Hypervisor('qemu:///system');
var domainName = (val) => {
for (var i = 0; i < val.length; i++) {
hyper.lookupDomainById( val[i], (err, domain) => {
domain.getName( (err, name) => {
console.log(name);
});
});
}
}
var domainIds = new Promise( (resolve, reject) => {
hyper.listActiveDomains( (err, domains) => {
resolve(domains);
});
});
domainIds.then( val => { domainName(val); });
from node-libvirt.
@aafrey how about:
const libvirt = require('libvirt'),
hv = new libvirt.Hypervisor('qemu:///system');
hv.connectAsync()
.then(() => hv.listActiveDomainsAsync())
.map(id => hv.lookupDomainByIdAsync(id))
.map(domain => domain.getNameAsync())
.then(result => console.log(result));
caveat: I haven't actually tried running this, it might need minor modifications
from node-libvirt.
@mbroadst I'll give it a try, since it looks much much cleaner :)
from node-libvirt.
Related Issues (20)
- lookupDomainById returns empty object HOT 11
- Parent objects get garbage collected before children' async operations finish which can lead to a crash HOT 3
- Error information can be lost during high concurrency
- Error objects become invalid and cause a crash (test-case supplied) HOT 7
- lookupStorageVolumeByVolume is not implemented HOT 4
- tests != docs. HOT 6
- Events not firing HOT 6
- v2.0.0 promisification changes HOT 6
- Error with connection pointers HOT 4
- Domain migration with options fails with sigfault HOT 1
- lookupDomainByUUID HOT 3
- set/get secret value do not work properly HOT 4
- Domain clonage
- npm install in windows error
- Current version in npm does not have the latest fixes. HOT 6
- How to listen for all domain events from hypervisor
- Maintainers? HOT 3
- Crashes when using events
- Can't install on Centos 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-libvirt.