From fb45db27df875d942fc322cfba0f64c9f9d6e6bd Mon Sep 17 00:00:00 2001 From: Pedro Dias Date: Mon, 24 Apr 2017 16:10:01 +0100 Subject: [PATCH] Vdc support --- lib/group.js | 14 ++++++ lib/opennebula.js | 29 +++++++++++- lib/vdc.js | 112 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 155 insertions(+), 2 deletions(-) create mode 100644 lib/vdc.js diff --git a/lib/group.js b/lib/group.js index 038e365..91c41c6 100644 --- a/lib/group.js +++ b/lib/group.js @@ -31,6 +31,20 @@ Group.prototype.quota = function(template, callback) { }); }; +Group.prototype.addAdmin = function(group, user, callback) { + this.modem.call('group.addadmin', [this.id, group, user], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Group.prototype.delAdmin = function(group, user, callback) { + this.modem.call('group.deladmin', [this.id, group, user], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + Group.prototype.addProvider = function(group, zone, cluster, callback) { this.modem.call('group.addprovider', [this.id, group, zone, cluster], function(err, data) { if(err) return callback(err); diff --git a/lib/opennebula.js b/lib/opennebula.js index 5078d48..c863187 100644 --- a/lib/opennebula.js +++ b/lib/opennebula.js @@ -9,7 +9,8 @@ var Modem = require('./modem'), Datastore = require('./datastore'), Image = require('./image'), Zone = require('./zone'), - Document = require('./document'); + Document = require('./document'), + Vdc = require('./vdc'); var OpenNebula = function(auth, hostname) { this.auth = auth; @@ -60,6 +61,32 @@ OpenNebula.prototype.getVMs = function(callback, userFilter, startID, endID, sta }); }; +//VDC +OpenNebula.prototype.getVdc = function(id) { + return new Vdc(this.modem, id); +}; + +OpenNebula.prototype.createVdc = function(template, cluster, callback) { + this.modem.call('vdc.allocate', [template, cluster || -1], function(err, data) { + if(err) return callback(err); + callback(null, new Vdc(this.modem, data)); + }); +}; + +OpenNebula.prototype.getVdcs = function(callback) { + this.modem.call('vdcpool.info', [], function(err, data) { + if (err) return callback(err); + + if (Array.isArray(data.VDC_POOL)) { + callback(null, data.VDC_POOL); + } else if(Array.isArray(data.VDC_POOL.HOST)) { + callback(null, data.VDC_POOL.HOST); + } else { + callback(null, [data.VDC_POOL.HOST]); + } + }); +}; + //HOST OpenNebula.prototype.getHost = function(id) { return new Host(this.modem, id); diff --git a/lib/vdc.js b/lib/vdc.js new file mode 100644 index 0000000..5d9120d --- /dev/null +++ b/lib/vdc.js @@ -0,0 +1,112 @@ +var Vdc = function(modem, id) { + this.modem = modem; + this.id = id; +}; + +Vdc.prototype.allocate = function(template, cluster, callback) { + this.modem.call('vdc.allocate', [template, cluster], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.delete = function(callback) { + this.modem.call('vdc.delete', [this.id], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.rename = function(name, callback) { + this.modem.call('vdc.rename', [this.id, name], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.update = function(template, merge, callback) { + this.modem.call('vdc.update', [this.id, template, merge], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.info = function(callback) { + this.modem.call('vdc.info', [this.id], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.addGroup = function(groupid, callback) { + this.modem.call('vdc.addgroup', [this.id, groupid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.delGroup = function(groupid, callback) { + this.modem.call('vdc.delgroup', [this.id, groupid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.addCluster = function(zoneid, clusterid, callback) { + this.modem.call('vdc.addcluster', [this.id, zoneid, clusterid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.delCluster = function(zoneid, clusterid, callback) { + this.modem.call('vdc.delcluster', [this.id, zoneid, clusterid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.addHost = function(zoneid, hostid, callback) { + this.modem.call('vdc.delcluster', [this.id, zoneid, clusterid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.delHost = function(zoneid, hostid, callback) { + this.modem.call('vdc.delhost', [this.id, zoneid, clusterid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.addDatastore = function(zoneid, datastoreid, callback) { + this.modem.call('vdc.adddatastore', [this.id, zoneid, datastoreid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.delDatastore = function(zoneid, datastoreid, callback) { + this.modem.call('vdc.deldatastore', [this.id, zoneid, datastoreid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.addVnet = function(zoneid, venetid, callback) { + this.modem.call('vdc.addvnet', [this.id, zoneid, venetid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + +Vdc.prototype.delVnet = function(zoneid, venetid, callback) { + this.modem.call('vdc.delvnet', [this.id, zoneid, venetid], function(err, data) { + if(err) return callback(err); + callback(null, data); + }); +}; + + +module.exports = Vdc; diff --git a/package.json b/package.json index 51e27f3..f2bde82 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "opennebula", "description": "OpenNebula XML-RPC API client.", - "version": "1.0.7", + "version": "1.0.8", "author": "Pedro Dias ", "maintainers": [ "apocas "