Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swarmerode

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swarmerode - npm Package Compare versions

Comparing version 2.1.0 to 2.2.3-0

cache.js

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
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc