Skip to content

Commit

Permalink
Adding limited nova network management support
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielhurley committed May 31, 2014
1 parent 109c37e commit 4cefdad
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
2 changes: 2 additions & 0 deletions nova/v1.1/client.js
Expand Up @@ -7,6 +7,7 @@ var AZManager = require("./availability_zones"),
ImageManager = require('./images'),
KeypairManager = require('./keypairs'),
LimitManager = require('./limits'),
NetworkManager = require('./networks'),
QuotaManager = require('./quotas'),
SecurityGroupManager = require('./security_groups'),
SecurityGroupRuleManager = require('./security_group_rules'),
Expand All @@ -28,6 +29,7 @@ var Nova = base.Client.extend({
this.images = new ImageManager(this);
this.keypairs = new KeypairManager(this);
this.limits = new LimitManager(this);
this.networks = new NetworkManager(this);
this.quotas = new QuotaManager(this);
this.security_groups = new SecurityGroupManager(this);
this.security_group_rules = new SecurityGroupRuleManager(this);
Expand Down
39 changes: 39 additions & 0 deletions nova/v1.1/networks.js
@@ -0,0 +1,39 @@
var base = require("../../client/base"),
error = require("../../client/error");


var NetworkManager = base.Manager.extend({
namespace: "os-networks",
plural: "networks",

create: function (params, callback) {
// Nova will choke with an error trying to parse an int if MTU is sent
// but anything other than an integer or null;
if (!params.data.mtu) params.data.mtu = null;
return this._super(params, callback);
},

del: function (params, callback) {
var manager = this,
id = params.id || params.data.id;
params.url = this.urljoin(this.get_base_url(params), id);
// Always try to disassociate first; it's slightly inefficient, but it
// ensures that delete won't fail because you forgot to do the disassocation
// manually. This doesn't seem like a place where two steps are necessary.
return this.disassociate({id: id}, function (err, result, xhr) {
if (err) return manager.safe_complete(err, null, xhr, params, callback);
manager.client.del(params, callback);
});
},

disassociate: function (params, callback) {
// Unlike novaclient, this method defaults to disassociating everything.
var url = this.urljoin(this.get_base_url(params), params.id || params.data.id, "action");
params = this.prepare_params(params, url, "singular");
params.data = {disassociate: null};
return this.client.post(params, callback);
}
});


module.exports = NetworkManager;
11 changes: 11 additions & 0 deletions nova/v1.1/servers.js
Expand Up @@ -37,6 +37,17 @@ var ServerManager = base.Manager.extend({
delete params.data.scheduler_hints;
}

if (params.data.networks) {
params.data.nics = [];
if (Object.prototype.toString.call(params.data.networks) !== '[object Array]') {
params.data.networks = [params.data.networks];
}
params.data.networks.forEach(function (network) {
params.data.nics.push({"net-id": network, "v4-fixed-ip": ""});
});
delete params.data.networks;
}

// Base64 encode user data if present
if (params.data.user_data) {
// Use Buffer built-in if in Node, otherwise use btoa in the browser
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "openclient",
"version": "1.5.11",
"version": "1.5.12",
"description": "An opinionated client for RESTful APIs (particularly OpenStack's).",
"homepage": "https://github.com/gabrielhurley/js-openclient",
"keywords": ["client", "rest", "openstack"],
Expand Down

0 comments on commit 4cefdad

Please sign in to comment.