We removed httpPort with the assumption that docker allocated IPs and kept them as long as the container is around. This turned out to be not true because the IP changes on even container restart. So we now allocate IPs statically. The iprange makes sure we don't overlap with addons and other CI app or JupyterHub apps. https://github.com/moby/moby/issues/6743 https://github.com/moby/moby/pull/19001
36 lines
770 B
JavaScript
36 lines
770 B
JavaScript
'use strict';
|
|
|
|
exports = module.exports = {
|
|
ipFromInt,
|
|
intFromIp
|
|
};
|
|
|
|
const assert = require('assert');
|
|
|
|
function intFromIp(address) {
|
|
assert.strictEqual(typeof address, 'string');
|
|
|
|
const parts = address.split('.');
|
|
|
|
if (parts.length !== 4) return null;
|
|
|
|
return (parseInt(parts[0], 10) << (8*3)) & 0xFF000000 |
|
|
(parseInt(parts[1], 10) << (8*2)) & 0x00FF0000 |
|
|
(parseInt(parts[2], 10) << (8*1)) & 0x0000FF00 |
|
|
(parseInt(parts[3], 10) << (8*0)) & 0x000000FF;
|
|
}
|
|
|
|
function ipFromInt(input) {
|
|
assert.strictEqual(typeof input, 'number');
|
|
|
|
let output = [];
|
|
|
|
for (let i = 3; i >= 0; --i) {
|
|
const octet = (input >> (i*8)) & 0x000000FF;
|
|
output.push(octet);
|
|
}
|
|
|
|
return output.join('.');
|
|
}
|
|
|