swarmerode
Advanced tools
Comparing version 2.1.0 to 2.2.3-0
41
index.js
@@ -6,3 +6,3 @@ 'use strict' | ||
var exists = require('101/exists') | ||
var cache = require('./cache') | ||
var Consul = require('./consul') | ||
@@ -32,8 +32,11 @@ | ||
Swarmerode.prototype.swarmInfo = function (cb) { | ||
this.info(function (err, info) { | ||
if (err) { return cb(err) } | ||
info.parsedSystemStatus = Swarmerode._parseSwarmSystemStatus(info.SystemStatus) | ||
debug('swarm info %j', info) | ||
cb(null, info) | ||
}) | ||
var self = this | ||
cache.handleCache('info', function (evalCb) { | ||
self.info(function (err, info) { | ||
if (err) { return evalCb(err) } | ||
info.parsedSystemStatus = Swarmerode._parseSwarmSystemStatus(info.SystemStatus) | ||
debug('swarm info %j', info) | ||
evalCb(null, info) | ||
}) | ||
}, cb) | ||
} | ||
@@ -92,12 +95,16 @@ | ||
for (var i = 0; i < formatted.Nodes; i++) { | ||
formatted.ParsedNodes[systemStatus[0][0].trim()] = { | ||
Host: systemStatus.shift()[1], | ||
Status: systemStatus.shift()[1], | ||
Containers: parseInt(systemStatus.shift()[1], 10), | ||
ReservedCpus: systemStatus.shift()[1], | ||
ReservedMem: systemStatus.shift()[1], | ||
Labels: parseLabels(systemStatus.shift()[1]), | ||
Error: systemStatus.shift()[1], | ||
UpdatedAt: systemStatus.shift()[1], | ||
ServerVersion: systemStatus.shift()[1] | ||
try { | ||
formatted.ParsedNodes[systemStatus[0][0].trim()] = { | ||
Host: systemStatus.shift()[1], | ||
Status: systemStatus.shift()[1], | ||
Containers: parseInt(systemStatus.shift()[1], 10), | ||
ReservedCpus: systemStatus.shift()[1], | ||
ReservedMem: systemStatus.shift()[1], | ||
Labels: parseLabels(systemStatus.shift()[1]), | ||
Error: systemStatus.shift()[1], | ||
UpdatedAt: systemStatus.shift()[1], | ||
ServerVersion: systemStatus.shift()[1] | ||
} | ||
} catch (err) { | ||
debug('ERROR - invalid node', err.message) | ||
} | ||
@@ -104,0 +111,0 @@ } |
{ | ||
"name": "swarmerode", | ||
"version": "2.1.0", | ||
"version": "2.2.3-0", | ||
"description": "Swarm Client Extension for Dockerode", | ||
@@ -40,2 +40,3 @@ "main": "index.js", | ||
"101": "^1.2.0", | ||
"bluebird": "^3.3.5", | ||
"debug": "^2.2.0", | ||
@@ -49,6 +50,6 @@ "request": "^2.72.0" | ||
"istanbul": "^0.4.2", | ||
"mocha": "^2.3.4", | ||
"sinon": "^1.17.2", | ||
"standard": "^5.4.1" | ||
"mocha": "^2.5.1", | ||
"sinon": "^1.17.3", | ||
"standard": "^7.1.0" | ||
} | ||
} |
@@ -11,2 +11,6 @@ # swarmerode | ||
## Configuration | ||
The environment variable `SWARMERODE_CACHE_LENGTH` can be set to the number of milliseconds you'd like the docker info calls to be cached for. | ||
## Example | ||
@@ -13,0 +17,0 @@ |
@@ -6,2 +6,3 @@ 'use strict' | ||
var sinon = require('sinon') | ||
var cache = require('../cache') | ||
@@ -114,2 +115,11 @@ var exampleHosts = [ '10.0.0.1:4242', '10.0.0.2:4242', '10.0.0.3:4242' ] | ||
describe('swarmInfo', function () { | ||
beforeEach(function () { | ||
sinon.stub(cache, 'handleCache', function (key, check, cb) { | ||
check(cb) | ||
}) | ||
}) | ||
afterEach(function () { | ||
cache.handleCache.restore() | ||
}) | ||
it('should call the class info function', function (done) { | ||
@@ -132,2 +142,9 @@ sinon.spy(MockClass.prototype, 'info') | ||
}) | ||
it('should call cache with cb', function () { | ||
var handleCb = sinon.stub() | ||
instance.swarmInfo(handleCb) | ||
sinon.assert.calledOnce(cache.handleCache) | ||
sinon.assert.calledWith(cache.handleCache, 'info', sinon.match.func, handleCb) | ||
}) | ||
}) | ||
@@ -208,3 +225,40 @@ | ||
}) | ||
it('should only return correctly formated nodes', function (done) { | ||
var coolNode = { | ||
Labels: 'env=test, hd=ssd', | ||
Containers: 100, | ||
nodeName: ' cool.node', | ||
host: '10.42.42.42:4242' | ||
} | ||
var uncoolNode = { | ||
Containers: 4, | ||
nodeName: ' un.cool.node', | ||
host: '10.7.7.7:4242' | ||
} | ||
var testHosts = swarmInfoMock([coolNode, uncoolNode]) | ||
delete testHosts.SystemStatus[18] | ||
var out = Swarmerode._Swarmerode._parseSwarmSystemStatus(testHosts.SystemStatus) | ||
assert.equal(out.Role, 'primary') | ||
assert.equal(out.Strategy, 'spread') | ||
assert.equal(out.Filters, 'health, port, dependency, affinity, constraint') | ||
assert.isNumber(out.Nodes) | ||
assert.equal(out.Nodes, 2) | ||
assert.equal(out.ParsedNodes['cool.node'].Host, coolNode.host) | ||
assert.isNumber(out.ParsedNodes['cool.node'].Containers) | ||
assert.equal(out.ParsedNodes['cool.node'].Containers, 100) | ||
assert.equal(out.ParsedNodes['cool.node'].Status, 'Healthy') | ||
assert.equal(out.ParsedNodes['cool.node'].ReservedCpus, '0 / 1') | ||
assert.equal(out.ParsedNodes['cool.node'].ReservedMem, '10 GiB / 1.021 GiB') | ||
assert.equal(out.ParsedNodes['cool.node'].Error, '(none)') | ||
assert.equal(out.ParsedNodes['cool.node'].UpdatedAt, '2016-03-08T19:02:41Z') | ||
assert.equal(out.ParsedNodes['cool.node'].Labels.env, 'test') | ||
assert.equal(out.ParsedNodes['cool.node'].Labels.hd, 'ssd') | ||
assert.isUndefined(out.ParsedNodes['un.cool.node']) | ||
done() | ||
}) | ||
}) // end _parseSwarmSystemStatus | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28418
12
722
34
4
1
14
1
+ Addedbluebird@^3.3.5
+ Addedbluebird@3.7.2(transitive)