mirror of
https://github.com/yldio/copilot.git
synced 2024-11-14 23:30:05 +02:00
feat(portal-data): insert ip address in instance record
This commit is contained in:
parent
a14672355c
commit
aa853fe4c8
@ -1,17 +1,24 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const ParamCase = require('param-case');
|
// core modules
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
|
const Util = require('util');
|
||||||
|
|
||||||
|
// 3rd party modules
|
||||||
|
const CPClient = require('cp-client');
|
||||||
const DockerClient = require('docker-compose-client');
|
const DockerClient = require('docker-compose-client');
|
||||||
const { DEPLOYMENT_GROUP, SERVICE, HASH } = require('portal-watch');
|
|
||||||
const Dockerode = require('dockerode');
|
const Dockerode = require('dockerode');
|
||||||
const Hoek = require('hoek');
|
const Hoek = require('hoek');
|
||||||
|
const ParamCase = require('param-case');
|
||||||
const Penseur = require('penseur');
|
const Penseur = require('penseur');
|
||||||
const VAsync = require('vasync');
|
const { DEPLOYMENT_GROUP, SERVICE, HASH } = require('portal-watch');
|
||||||
const uniqBy = require('lodash.uniqby');
|
const UniqBy = require('lodash.uniqby');
|
||||||
const Transform = require('./transform');
|
|
||||||
const Uuid = require('uuid/v4');
|
const Uuid = require('uuid/v4');
|
||||||
const Util = require('util');
|
const VAsync = require('vasync');
|
||||||
|
|
||||||
|
// local modules
|
||||||
|
const Transform = require('./transform');
|
||||||
|
|
||||||
|
|
||||||
const NON_IMPORTABLE_STATES = [
|
const NON_IMPORTABLE_STATES = [
|
||||||
@ -39,18 +46,18 @@ const internals = {
|
|||||||
'packages': { id: { type: 'uuid' }, primary: 'id', secondary: false, purge: false },
|
'packages': { id: { type: 'uuid' }, primary: 'id', secondary: false, purge: false },
|
||||||
'instances': { id: { type: 'uuid' }, primary: 'id', secondary: false, purge: false },
|
'instances': { id: { type: 'uuid' }, primary: 'id', secondary: false, purge: false },
|
||||||
'users': { id: { type: 'uuid' }, primary: 'id', secondary: false, purge: false }
|
'users': { id: { type: 'uuid' }, primary: 'id', secondary: false, purge: false }
|
||||||
|
},
|
||||||
|
resolveCb: (resolve, reject) => {
|
||||||
|
return (err, ...args) => {
|
||||||
|
if (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(...args);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const resolveCb = (resolve, reject) => {
|
|
||||||
return (err, ...args) => {
|
|
||||||
if (err) {
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(...args);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = class Data extends EventEmitter {
|
module.exports = class Data extends EventEmitter {
|
||||||
constructor (options) {
|
constructor (options) {
|
||||||
@ -64,6 +71,10 @@ module.exports = class Data extends EventEmitter {
|
|||||||
this._docker = new Dockerode(settings.docker);
|
this._docker = new Dockerode(settings.docker);
|
||||||
this._watcher = null;
|
this._watcher = null;
|
||||||
|
|
||||||
|
if (settings.consul && settings.consul.address) {
|
||||||
|
CPClient.config(settings.consul);
|
||||||
|
}
|
||||||
|
|
||||||
this._dockerCompose.on('error', (err) => {
|
this._dockerCompose.on('error', (err) => {
|
||||||
this.emit('error', err);
|
this.emit('error', err);
|
||||||
});
|
});
|
||||||
@ -116,21 +127,21 @@ module.exports = class Data extends EventEmitter {
|
|||||||
// Sub query/filter for deploymentGroups
|
// Sub query/filter for deploymentGroups
|
||||||
const deploymentGroups = (args) => {
|
const deploymentGroups = (args) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.getDeploymentGroups(args, resolveCb(resolve, reject));
|
this.getDeploymentGroups(args, internals.resolveCb(resolve, reject));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sub query/filter for user
|
// Sub query/filter for user
|
||||||
const user = () => {
|
const user = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.getUser({}, resolveCb(resolve, reject));
|
this.getUser({}, internals.resolveCb(resolve, reject));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sub query/filter for datacenter
|
// Sub query/filter for datacenter
|
||||||
const datacenter = () => {
|
const datacenter = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.getDatacenter({ id: portal.datacenter_id }, resolveCb(resolve, reject));
|
this.getDatacenter({ id: portal.datacenter_id }, internals.resolveCb(resolve, reject));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -255,7 +266,7 @@ module.exports = class Data extends EventEmitter {
|
|||||||
args.deploymentGroupId = deploymentGroupId;
|
args.deploymentGroupId = deploymentGroupId;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.getServices(args, resolveCb(resolve, reject));
|
this.getServices(args, internals.resolveCb(resolve, reject));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -304,7 +315,7 @@ module.exports = class Data extends EventEmitter {
|
|||||||
args.deploymentGroupId = deploymentGroup.id;
|
args.deploymentGroupId = deploymentGroup.id;
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.getServices(args, resolveCb(resolve, reject));
|
this.getServices(args, internals.resolveCb(resolve, reject));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -811,7 +822,7 @@ module.exports = class Data extends EventEmitter {
|
|||||||
remove();
|
remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
// deactivate pruned servcies
|
// deactivate pruned services
|
||||||
const pruneServices = (err, result) => {
|
const pruneServices = (err, result) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
@ -952,7 +963,7 @@ module.exports = class Data extends EventEmitter {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
query.ids = instanceIds;
|
query.ids = instanceIds;
|
||||||
|
|
||||||
this.getInstances(query, resolveCb(resolve, reject));
|
this.getInstances(query, internals.resolveCb(resolve, reject));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1223,10 +1234,23 @@ module.exports = class Data extends EventEmitter {
|
|||||||
VAsync.forEachParallel({
|
VAsync.forEachParallel({
|
||||||
func: (instance, next) => {
|
func: (instance, next) => {
|
||||||
const container = this._docker.getContainer(instance.machine_id);
|
const container = this._docker.getContainer(instance.machine_id);
|
||||||
container.start(next);
|
container.start((err) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the IPAddress for the instance
|
||||||
|
container.inspect((err, details) => {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._db.instances.update(instance.id, { ip_address: details.NetworkSettings.IPAddress }, next);
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
inputs: instances
|
inputs: instances
|
||||||
}, (err, results) => {
|
}, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
@ -1358,7 +1382,7 @@ module.exports = class Data extends EventEmitter {
|
|||||||
|
|
||||||
return cb(
|
return cb(
|
||||||
null,
|
null,
|
||||||
uniqBy(
|
UniqBy(
|
||||||
machines
|
machines
|
||||||
.filter(({ state }) => { return NON_IMPORTABLE_STATES.indexOf(state.toUpperCase()) < 0; })
|
.filter(({ state }) => { return NON_IMPORTABLE_STATES.indexOf(state.toUpperCase()) < 0; })
|
||||||
.filter(({ tags = {} }) => { return [DEPLOYMENT_GROUP, SERVICE, HASH].every((name) => { return tags[name]; }); }
|
.filter(({ tags = {} }) => { return [DEPLOYMENT_GROUP, SERVICE, HASH].every((name) => { return tags[name]; }); }
|
||||||
|
Loading…
Reference in New Issue
Block a user