Coder Social home page Coder Social logo

ramyelkest / libvirt-node Goto Github PK

View Code? Open in Web Editor NEW
10.0 10.0 6.0 254 KB

Libvirt bindings for NodeJS

License: GNU Lesser General Public License v2.1

Python 1.16% JavaScript 97.39% Makefile 0.27% Dockerfile 1.19%
libvirt napi nodejs qemu virtualization

libvirt-node's People

Contributors

atwright147 avatar matts966 avatar ramyelkest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

libvirt-node's Issues

getUUIDString() errors

Hey,

Is getUUIDString() working correctly? When I try to use it in the same way as I would use getName(), getID() or getOSType() I get the following error:

ReferenceError: buf is not defined
    at module.exports.getUUIDString (/vagrant/node_modules/libvirt-node/generated/libvirt-domain.js:870:66)
    at domains.forEach.domain (/vagrant/src/server/models/Domains.js:50:41)
    at Array.forEach (<anonymous>)
    at Object.allCompact (/vagrant/src/server/models/Domains.js:46:17)
    at compact (/vagrant/src/server/controllers/DomainsController.js:19:45)
    at Layer.handle [as handle_request] (/vagrant/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/vagrant/node_modules/express/lib/router/index.js:317:13)
    at /vagrant/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/vagrant/node_modules/express/lib/router/index.js:335:12)
    at next (/vagrant/node_modules/express/lib/router/index.js:275:10)

It seems to require a buffer (buf) to be passed in but I cannot figure out what to pass into that.

Here is a code example:

const domains = LibvirtClient.listAllDomains(0);
const domainsWithInfo = [];

domains.forEach(domain => {
    const domainInfo = {};
    domainInfo['name'] = domain.getName();
    domainInfo['uuid'] = domain.getUUIDString();  // without this line, this loop works; with it is fails :(
    domainInfo['id'] = domain.getID();
    domainInfo['osType'] = domain.getOSType();

    domainsWithInfo.push(domainInfo);
});

return domainsWithInfo;

Cheers

Add Dockerfile to build easily and locally

Hi, I am interested in getting involved in libvirt project, and libvirt-node for GSoC project. I am currently a student of the University of Tokyo Japan.

I would like to build this project locally but manual headers installation is required. So I currentlly check the build using docker in my local environment.

Is it ok to add Dockerfile and make rule to build this poject in the docker container as PR?

validate napi_int64 mappings

Currently long, long long, unsigned long and unsigned long long are mapped to napi_int64.

Two potential problems are

  • int64 is approximate in javascript beyond 2^53
  • mapping unsigned to signed

we need to validate if either is an issue in our API

Error due to passing wrong variable to `libvirt_native.virStoragePoolListAllVolumes`

In ./generated/libvirt-storage-pool.js on line 156 (let retList = libvirt_native.virStoragePoolListAllVolumes(this.pool, flags);) the first arg is this.pool but this seems to be wrong as I get the error:

/vagrant/node_modules/libvirt-node/generated/libvirt-storage-pool.js:156
    let retList = libvirt_native.virStoragePoolListAllVolumes(this.pool, flags);
                                 ^

TypeError: Wrong argument type 0
    at module.exports.listAllVolumes (/vagrant/node_modules/libvirt-node/generated/libvirt-storage-pool.js:156:34)

This is the generated code:

  /**
   * Collect the list of storage volumes, and allocate an array to store those
   * objects.
   *
   * TODO: params / returns
   */
  listAllVolumes(flags = 0) {
    let retList = libvirt_native.virStoragePoolListAllVolumes(this.pool, flags);
    if (retList == null)
      throw new Error('virStoragePoolListAllVolumes() failed');

    return retList.map(ret => new virStorageVol(this.conn, ret));
  }

Changing this.pool to this.storagePool fixes the issue.

Adding new api to whitelist

Hi.
Im using libvirt-node in my project and i needed some api for monitoring my VMs.
i added them to whitelist as you said in DEVELOPMENT.md but when I try to regenerate the files I get the following error:

Error: Type 'virDomainPtr *' is not mapped to a napi type

I see that you mentioned this error in whitelist.js.
Is there anyway to fix it?
I would be thankful if you consider helping me .
@RamyElkest

free returned char *

Some api calls like virDomainGetHostname require the user to free the returned string.

  • confirm all API functions returning char * (not const char) require user to free
  • Add rule to free

Strings (essentially pointers) as arguments can be nullable

For instance virDomainGetMetadata takes a uri string which is conditionally nullable

This should apply to virConnectOpen as well

This will probably apply to all pointer types

This means in our type check we should check for napi_null/napi_undefined as well as the type

Error messages

@RamyElkest a new issue I am having now, is that Libvirt is spitting out lovely useful messages into the terminal but I cannot seem to get them in JS.

Terminal output after an error:

libvirt: Domain Config error : operation failed: domain 'created_from_post' already exists with uuid d6bd24d8-ff09-426d-ae23-e8c3cdb696e6
Error: virDomainDefineXML() failed
    at module.exports.defineXML (/vagrant/node_modules/libvirt-node/generated/libvirt-connect.js:708:28)
    at Object.create (/vagrant/src/server/models/Domains.js:67:38)
    at create (/vagrant/src/server/controllers/DomainsController.js:34:21)
    at Layer.handle [as handle_request] (/vagrant/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/vagrant/node_modules/express/lib/router/index.js:317:13)
    at /vagrant/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/vagrant/node_modules/express/lib/router/index.js:335:12)
    at next (/vagrant/node_modules/express/lib/router/index.js:275:10)
    at nocache (/vagrant/node_modules/nocache/index.js:8:5)
    at Layer.handle [as handle_request] (/vagrant/node_modules/express/lib/router/layer.js:95:5)

I can only get: virDomainDefineXML() failed, but Domain Config error : operation failed: domain 'created_from_post' already exists with uuid d6bd24d8-ff09-426d-ae23-e8c3cdb696e6 would be way more useful to me :)

Is there something I am doing wrong, or could you make a change to expose these messages?

More info

This is where I am using it: https://gitlab.com/atwright147/kvm-controller/commit/d3667b39bdb7457020d01358923949d8464b33c2

Sending a payload like:

{
	"xmlString": "<domain type='kvm'><name>created_from_post</name><memory unit='MB'>512</memory><vcpu>1</vcpu><os><type arch='i686'>hvm</type></os><clock sync='localtime'/><devices><disk type='file' device='disk'><source file='/var/lib/libvirt/images/demo2.img'/><target dev='hda'/></disk><disk type='file' device='cdrom'><source file='/home/vagrant/Downloads/Core-current.iso'/><target dev='hdc'/><readonly/></disk><interface type='network'><source network='default'/></interface><graphics type='vnc' port='-1'/></devices></domain>"
}

Experimenting with Express and Libvirt-node keeps crashing

Hey,

I am very excited about this project and have been experimenting. I built a project in Express.js to use take advantage of libvirt-node.

I have successfully got it going, but only for one request. After that one request it crashes with the following error:

node: ../generated/libvirt-connect.c:943: libvirt_virConnectListAllDomains: Assertion `status == napi_ok' failed.

Do you have any idea what might be wrong?

This is the current Express App code: https://gitlab.com/atwright147/kvm-controller

Create minimal manual bindings

Connect

  • virConnectOpen
  • virConnectClose
  • virConnectGetURI
  • virConnectRegisterCloseCallback registers callback

Domain

  • virDomainGetID
  • virDomainCreateXML
  • virDomainGetVcpusFlags
  • virDomainLookupByName

Node

  • virNodeGetInfo info passed through arguments
  • virNodeGetFreeMemory

Interface

  • virInterfaceLookupByName
  • virInterfaceIsActive

DomainSnapshot

  • virDomainSnapshotCreateXML
  • virDomainSnapshotGetParent

NodeDevice

  • virNodeDeviceCreateXML
  • virNodeDeviceGetName

Network

  • virNetworkCreateXML
  • virNetworkGetConnect

Storage

  • virStorageVolCreateXML

  • virStorageVolGetKey

  • virStoragePoolCreateXML

  • virStoragePoolGetUUID

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.