Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ azure_error
coverage.html
.coveralls.yml
pkgcloud.lcov*
node-jscoverage
node-jscoverage
examples/*
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MOCHA_CMD = MOCK=on ./node_modules/.bin/mocha
MOCHA_OPTS = --require blanket -t 4000 test/*/*/*-test.js test/*/*/*/*-test.js
MOCHA_OPENSTACK_OPTS = --require blanket -t 4000 test/openstack/*/*-test.js test/openstack/*/*/*-test.js
DEFAULT_REPORT_OPTS = --reporter spec
HTML_REPORT_OPTS = --reporter html-cov > coverage.html
COVERALLS_REPORT_OPTS = --reporter mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js
Expand All @@ -12,6 +13,10 @@ cov: test-cov-html

travis: lint test-unit test-cov-coveralls

test-openstack:
@echo "$(MOCHA_CMD) $(MOCHA_OPENSTACK_OPTS) $(REPORT_OPTS)"
@NODE_ENV=test $(MOCHA_CMD) $(MOCHA_OPENSTACK_OPTS) $(REPORT_OPTS)

test-unit:
@echo "$(MOCHA_CMD) $(MOCHA_OPTS) $(REPORT_OPTS)"
@NODE_ENV=test $(MOCHA_CMD) $(MOCHA_OPTS) $(REPORT_OPTS)
Expand Down
3 changes: 2 additions & 1 deletion lib/pkgcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ var services = [
'network',
'storage',
'rating',
'metering'
'metering',
'secret'
];

//
Expand Down
8 changes: 8 additions & 0 deletions lib/pkgcloud/core/network/lbaasHealthMonitorV2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var util = require('util'),
model = require('../base/model');

var lbaasHealthMonitorV2 = exports.lbaasHealthMonitorV2 = function (client, details) {
model.Model.call(this, client, details);
};

util.inherits(lbaasHealthMonitorV2, model.Model);
8 changes: 8 additions & 0 deletions lib/pkgcloud/core/network/lbaasListener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var util = require('util'),
model = require('../base/model');

var lbaasListener = exports.lbaasListener = function (client, details) {
model.Model.call(this, client, details);
};

util.inherits(lbaasListener, model.Model);
12 changes: 12 additions & 0 deletions lib/pkgcloud/core/network/lbaasLoadbalancer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var util = require('util'),
model = require('../base/model');

var lbaasLoadbalancer = exports.lbaasLoadbalancer = function (client, details) {
model.Model.call(this, client, details);
};

util.inherits(lbaasLoadbalancer, model.Model);

lbaasLoadbalancer.prototype.refresh = function (callback) {
this.client.getLoadbalancer(this.id, callback);
};
8 changes: 8 additions & 0 deletions lib/pkgcloud/core/network/lbaasMembersV2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var util = require('util'),
model = require('../base/model');

var lbaasMembersV2 = exports.lbaasMembersV2 = function (client, details) {
model.Model.call(this, client, details);
};

util.inherits(lbaasMembersV2, model.Model);
8 changes: 8 additions & 0 deletions lib/pkgcloud/core/network/lbaasPoolsV2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var util = require('util'),
model = require('../base/model');

var lbaasPoolsV2 = exports.lbaasPoolsV2 = function (client, details) {
model.Model.call(this, client, details);
};

util.inherits(lbaasPoolsV2, model.Model);
8 changes: 8 additions & 0 deletions lib/pkgcloud/core/secret/container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var util = require('util'),
model = require('../base/model');

var container = exports.Container = function (client, details) {
model.Model.call(this, client, details);
};

util.inherits(container, model.Model);
8 changes: 8 additions & 0 deletions lib/pkgcloud/core/secret/secret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var util = require('util'),
model = require('../base/model');

var secret = exports.Secret = function (client, details) {
model.Model.call(this, client, details);
};

util.inherits(secret, model.Model);
1 change: 1 addition & 0 deletions lib/pkgcloud/openstack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ exports.database = require('./database');
exports.rating = require('./rating');
exports.metering = require('./metering');
exports.cdn = require('./cdn');
exports.secret = require('./secret');
13 changes: 11 additions & 2 deletions lib/pkgcloud/openstack/network/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ var Client = exports.Client = function (options) {
lbaasVip: require('../lbaasVip').lbaasVip,
HealthMonitor: require('../lbaasHealthMonitor').HealthMonitor,
lbaasPools: require('../lbaasPools').lbaasPools,
lbaasMembers: require('../lbaasMembers').lbaasMembers
lbaasMembers: require('../lbaasMembers').lbaasMembers,
lbaasLoadbalancer: require('../lbaasLoadbalancer').lbaasLoadbalancer,
lbaasListeners: require('../lbaasListener').lbaasListener,
lbaasPoolsV2: require('../lbaasPoolsV2').lbaasPoolsV2,
lbaasMembersV2: require('../lbaasMembersV2').lbaasMembersV2,
healthMonitorV2: require('../lbaasHealthMonitorV2').lbaasHealthMonitorV2
};

_.extend(this, require('./networks'));
Expand All @@ -39,8 +44,12 @@ var Client = exports.Client = function (options) {
_.extend(this, require('./lbaasHealthMonitor'));
_.extend(this, require('./lbaasPools'));
_.extend(this, require('./lbaasMembers'));

_.extend(this, require('./lbaasLoadbalancer'));
_.extend(this, require('./lbaasListener'));
_.extend(this, require('./lbaasPoolsV2'));
_.extend(this, require('./lbaasHealthMonitorV2'));
this.serviceType = 'network';

};

util.inherits(Client, openstack.Client);
Expand Down
212 changes: 212 additions & 0 deletions lib/pkgcloud/openstack/network/client/lbaasHealthMonitorV2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
var urlJoin = require('url-join');

var lbaasMonitorPath = '/lbaas/healthmonitors';


// Declaring variables for helper functions defined later
var _convertMonitorsToWireFormat,
_convertMonitorsUpdateToWireFormat;


/***

list Health Monitors (Get)

***/

exports.getHealthMonitorsV2 = function (options, callback) {
var self = this;
if (typeof options === 'function') {
callback = options;
options = {};
}
var getMonitorOpts = {
path: lbaasMonitorPath,
};
this._request(getMonitorOpts, function (err, body) {
if (err) {
return callback(err);
}
else if (!body || !body.healthmonitors || !(body.healthmonitors instanceof Array)) {
return callback(new Error('Malformed API Response'));
}
return callback(err, body.healthmonitors.map(function (monitor) {
return new self.models.healthMonitorV2(self, monitor);
}));
});
};

/**

Health Monitor show

*/

exports.getHealthMonitorV2 = function (option, callback) {
var self = this,
healthMonitorId = option instanceof this.models.healthMonitorV2 ? option.id : option;
self.emit('log::trace', 'Getting details for lbaas health monitor', healthMonitorId);
this._request({
path: urlJoin(lbaasMonitorPath, healthMonitorId),
method: 'GET'
}, function (err, body) {
if (err) {
return callback(err);
}
if (!body ||!body.healthmonitor) {
return callback(new Error('Malformed API Response'));
}
return callback(err, new self.models.healthMonitorV2(self, body.healthmonitor));
});
};

/**

health monitor create
{
"healthmonitor": {
"pool_id": "74aa2010-a59f-4d35-a436-60a6da882819",
"admin_state_up": true,
"delay": "1",
"expected_codes": "200,201,202",
"http_method": "GET",
"max_retries": 5,
"timeout": 1,
"type": "HTTP",
"url_path": "/index.html"
}
}
**/
exports.createHealthMonitorV2 = function (options, callback) {
var self = this,
monitor = typeof options === 'object' ? options : { 'name' : options};

var monitor_create = _convertMonitorsToWireFormat(monitor);
var createLoadbalancerOpts = {
method: 'POST',
path: lbaasMonitorPath,
body: { 'healthmonitor' : monitor_create}
};

self.emit('log::trace', 'Creating lbaas health monitor', monitor_create);
this._request(createLoadbalancerOpts, function (err,body) {
if (err) {
return callback(err);
}
if (!body ||!body.healthmonitor) {
return callback(new Error('Malformed API Response'));
}
return callback(err, new self.models.healthMonitorV2(self, body.healthmonitor));
});
};

/**
{
"healthmonitor": {
"admin_state_up": false,
"delay": "2",
"expected_codes": "200",
"http_method": "POST",
"max_retries": 2,
"timeout": 2,
"url_path": "/page.html"
}
}
**/

exports.updateHealthMonitorV2 = function (options, callback) {
var self = this,
monitorId = options.id,
monitorUpdate = _convertMonitorsUpdateToWireFormat(options);
var updateMonitorsOpts = {
method: 'PUT',
path: urlJoin(lbaasMonitorPath, monitorId),
contentType: 'application/json',
body: { 'healthmonitor' : monitorUpdate }
};
self.emit('log::trace', 'Updating lbaas health monitor', monitorId);
this._request(updateMonitorsOpts, function (err,body) {
if (err) {
return callback(err);
}
if (!body ||!body.healthmonitor) {
return callback(new Error('Malformed API Response'));
}
return callback(err, new self.models.healthMonitorV2(self, body.healthmonitor));
});
};


/*
health delete

*/
exports.destroyHealthMonitorV2 = function (options, callback) {
var self = this,
monitorId = options instanceof this.models.healthMonitorV2 ? options.id : options;
self.emit('log::trace', 'Deleting lbaas health monitor', monitorId);
this._request({
path: urlJoin(lbaasMonitorPath, monitorId),
contentType: 'application/json',
method: 'DELETE'
}, function (err) {
return err
? callback(err)
: callback(err, monitorId);
});
};

/*
Convert message format for update
{
"healthmonitor": {
"admin_state_up": false,
"delay": "2",
"expected_codes": "200",
"http_method": "POST",
"max_retries": 2,
"timeout": 2,
"url_path": "/page.html"
}
}
*/
_convertMonitorsUpdateToWireFormat = function (details){
var wireFormat = {};
wireFormat.admin_state_up = details.admin_state_up || true;
wireFormat.delay = details.delay;
wireFormat.expected_codes = details.expected_codes;
wireFormat.http_method = details.http_method;
wireFormat.max_retries = details.max_retries;
wireFormat.timeout = details.timeout;
wireFormat.url_path = details.url_path;
return wireFormat;
};

/*
Convert message format for creation

{
"pool_id": "74aa2010-a59f-4d35-a436-60a6da882819",
"admin_state_up": true,
"delay": "1",
"expected_codes": "200,201,202",
"http_method": "GET",
"max_retries": 5,
"timeout": 1,
"type": "HTTP",
"url_path": "/index.html"
}
*/
_convertMonitorsToWireFormat = function (details){
var wireFormat = {};
wireFormat.pool_id = details.pool_id;
wireFormat.admin_state_up = details.admin_state_up || true;
wireFormat.delay = details.delay;
wireFormat.expected_codes = details.expected_codes;
wireFormat.http_method = details.http_method;
wireFormat.max_retries = details.max_retries;
wireFormat.timeout = details.timeout;
wireFormat.type = details.type;
wireFormat.url_path = details.url_path;
return wireFormat;
};
Loading