open-nomad/ui/mirage/factories/agent.js
Jai Bhagat 2efa6cc7e4 add agent serializer
This commit adds a serializer for the Agent. When the factory was originally
designed to have the Member properities directly on the Agent class which was
not set-up properly technically, but since we didn't really make use of the
Agent endpoint.
2021-07-06 16:42:07 -04:00

48 lines
1.2 KiB
JavaScript

import { Factory } from 'ember-cli-mirage';
import faker from 'nomad-ui/mirage/faker';
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'];
export default Factory.extend({
id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
config: {
Version: {
Version: '1.1.0',
VersionMetadata: 'ent',
VersionPrerelease: 'dev',
},
},
member: () => {
const name = generateName();
const serfPort = faker.random.number({ min: 4000, max: 4999 });
return {
Name: name,
Port: serfPort,
Status: faker.helpers.randomize(AGENT_STATUSES),
Address: generateAddress(name),
Tags: generateTags(serfPort),
};
},
});
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 });
return {
port: rpcPortCandidate === serfPort ? rpcPortCandidate + 1 : rpcPortCandidate,
dc: faker.helpers.randomize(DATACENTERS),
};
}