Control your cloud from node.js

There was no node.js module implementing Onapp API, so I realized that it should be a good idea to implement it for my first npm published module. 🙂

There are still a lot of methods to implement, but the basic stuff is there. When i have time i will implement more.

Module’s structure is similar to other node client implementations out there, it is very readable.

node.js community is awesome and is certainly something I’m going to be doing more often.

Check it out at: https://github.com/apocas/node-onapp

Installation, as usual, is done using npm awesomeness

npm install onapp

In order to started you need to instantiate a client.

var onapp = require('onapp');

var config = {
 username: 'username@email.com',
 apiKey: 'api_hash',
 serverUrl: 'http://192.168.1.1'
};

var client = onapp.createClient(config);

The options passed during VM creation, are exactly accordingly to Onapp API. This way you create a VM like you were using the original API.

var options = {
  memory: '1024',
  cpus: '1',
  cpu_shares: '50',
  hostname: 'tests.tests.com',
  label: 'VM from node',
  primary_disk_size: '10',
  swap_disk_size: '1',
  primary_network_id: '2',
  template_id: '6',
  hypervisor_id: 2,
  initial_root_password: '12345675',
  rate_limit: 'none'
};

client.createVirtualMachine(options, function (err, vm) {
  if(err !== null) {
    console.log(err);
  } else {
    console.log(vm);
  }
});

Powering off a VM.

client.getVirtualMachine('vm_id', function (err, vm) {
  if(err !== null) {
    console.log(err);
  } else {
    vm.off(function(error, data){});
    //vm.reboot(function(error, data){});
    //...
  }
});
Advertisements
Previous Post
Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s