Giter Club home page Giter Club logo

node-onapp's Introduction

node-onapp

node.js onapp module

More methods coming...

Check the examples below for usage.

##Installation:

npm install onapp

##Examples:

Note: According to OnApp API docs you need to either use your username and password or your email address + API key. API key + username won't work.

var onapp = require('onapp');

var config = {
  username: '[email protected]',
  apiKey: 'api_hash',
  serverUrl: 'http://192.168.1.1'
};

var client = onapp.createClient(config);

//Onapp version
client.getVersion(function (err, data) {
  console.log(data);
});


//Template list
//returns a array with Template objects.
client.getSystemTemplates(function (err, templates) {
  console.log(templates);
});


//Create a VM
//For more options check Onapp manual since these are directly pass to it.
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'
};

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


//Get VM details
//returns a array of VirtualMachine objects
client.getVirtualMachine('vm_id', function (err, vm) {
  if(err !== null) {
    console.log(err);
  } else {
    vm.off(function(error, data){});
    //vm.reboot(function(error, data){});
    //...
  }
});

//Get VM List
client.getVirtualMachines(function (err, vm) {
  if(err !== null) {
    console.log(err);
  } else {
    console.log(vm);
  }
});

//Creating a user, billing plan and its resources
client.createUser({'email': '[email protected]','first_name': 'XPTO','last_name': 'OTPX','login': 'xptoxpto','password': '123qwe_123qwe', 'user_group_id': '1', 'role_ids': ['1']}, function(err, user) {
  if (err) throw err;
  console.log('User created!');

  client.createBillingPlan({'label': '[email protected] plan','currency_code': 'USD','monthly_price': '0.0'}, function(err, billingplan) {
    if (err) throw err;
    console.log('Billing plan created!');

    user.billing_plan_id = billingplan.id;
    user.save(function(err, data) {
      if (err) throw err;
      console.log('User saved!');

      billingplan.addResource({resource: 'VmLimit', limits: {limit: 1, limit_free: 0}}, function(err, resource) {
        if (err) throw err;
        console.log('Resource added!');
        console.log('SUCCESS!!!');
      });
    });
  });
});

node-onapp's People

Contributors

apocas avatar dvelopment avatar

Watchers

 avatar

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.