2019-09-26 18:47:07 +00:00
|
|
|
import { Factory } from 'ember-cli-mirage';
|
2019-10-03 14:13:08 +00:00
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
2017-09-19 14:47:10 +00:00
|
|
|
import { provide } from '../utils';
|
|
|
|
import { DATACENTERS } from '../common';
|
|
|
|
|
|
|
|
const UUIDS = provide(100, faker.random.uuid.bind(faker.random));
|
|
|
|
const AGENT_STATUSES = ['alive', 'leaving', 'left', 'failed'];
|
2021-10-22 14:33:06 +00:00
|
|
|
const AGENT_BUILDS = ['1.1.0-beta', '1.0.2-alpha+ent', ...provide(5, faker.system.semver)];
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Factory.extend({
|
|
|
|
id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
|
|
|
|
|
2021-07-11 19:50:42 +00:00
|
|
|
name: () => generateName(),
|
|
|
|
|
2021-06-16 15:40:24 +00:00
|
|
|
config: {
|
|
|
|
Version: {
|
|
|
|
Version: '1.1.0',
|
|
|
|
VersionMetadata: 'ent',
|
|
|
|
VersionPrerelease: 'dev',
|
|
|
|
},
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
|
2021-07-11 19:50:42 +00:00
|
|
|
member() {
|
2021-06-16 15:40:24 +00:00
|
|
|
const serfPort = faker.random.number({ min: 4000, max: 4999 });
|
2017-09-19 14:47:10 +00:00
|
|
|
return {
|
2021-07-11 19:50:42 +00:00
|
|
|
Name: this.name,
|
2021-06-16 15:40:24 +00:00
|
|
|
Port: serfPort,
|
|
|
|
Status: faker.helpers.randomize(AGENT_STATUSES),
|
2021-07-11 19:50:42 +00:00
|
|
|
Address: generateAddress(this.name),
|
2021-06-16 15:40:24 +00:00
|
|
|
Tags: generateTags(serfPort),
|
2017-09-19 14:47:10 +00:00
|
|
|
};
|
|
|
|
},
|
2021-10-22 14:33:06 +00:00
|
|
|
|
|
|
|
version() {
|
|
|
|
return this.member.Tags?.build || '';
|
|
|
|
},
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|
2021-06-11 21:15:26 +00:00
|
|
|
|
2021-06-16 15:40:24 +00:00
|
|
|
function generateName() {
|
|
|
|
return `nomad@${faker.random.boolean() ? faker.internet.ip() : faker.internet.ipv6()}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateAddress(name) {
|
|
|
|
return name.split('@')[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateTags(serfPort) {
|
|
|
|
const rpcPortCandidate = faker.random.number({ min: 4000, max: 4999 });
|
2021-06-11 21:15:26 +00:00
|
|
|
return {
|
2021-06-16 15:40:24 +00:00
|
|
|
port: rpcPortCandidate === serfPort ? rpcPortCandidate + 1 : rpcPortCandidate,
|
|
|
|
dc: faker.helpers.randomize(DATACENTERS),
|
2021-10-22 14:33:06 +00:00
|
|
|
build: faker.helpers.randomize(AGENT_BUILDS),
|
2021-06-11 21:15:26 +00:00
|
|
|
};
|
|
|
|
}
|