Skip to content

Commit

Permalink
Vdc support
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Apr 24, 2017
1 parent e599a7f commit fb45db2
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 2 deletions.
14 changes: 14 additions & 0 deletions lib/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 28 additions & 1 deletion lib/opennebula.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
112 changes: 112 additions & 0 deletions lib/vdc.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opennebula",
"description": "OpenNebula XML-RPC API client.",
"version": "1.0.7",
"version": "1.0.8",
"author": "Pedro Dias <[email protected]>",
"maintainers": [
"apocas <[email protected]>"
Expand Down

0 comments on commit fb45db2

Please sign in to comment.