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';
|
|
|
|
|
|
|
|
// Realistically, resource reservations have a low cardinality
|
|
|
|
const CPU_RESERVATIONS = [250, 500, 1000, 2000, 2500, 4000];
|
|
|
|
const MEMORY_RESERVATIONS = [256, 512, 1024, 2048, 4096, 8192];
|
|
|
|
const DISK_RESERVATIONS = [200, 500, 1000, 2000, 5000, 10000, 100000];
|
|
|
|
|
|
|
|
// There is also a good chance that certain resource restrictions are unbounded
|
|
|
|
DISK_RESERVATIONS.push(...Array(500).fill(0));
|
|
|
|
|
2019-09-04 14:39:56 +00:00
|
|
|
const NETWORK_MODES = ['bridge', 'host'];
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
export const DATACENTERS = provide(
|
|
|
|
15,
|
|
|
|
(n, i) => `${faker.address.countryCode().toLowerCase()}${i}`
|
|
|
|
);
|
|
|
|
|
|
|
|
export const HOSTS = provide(100, () => {
|
2019-10-03 14:13:08 +00:00
|
|
|
const ip = faker.random.boolean() ? faker.internet.ip() : `[${faker.internet.ipv6()}]`;
|
2017-09-19 14:47:10 +00:00
|
|
|
return `${ip}:${faker.random.number({ min: 4000, max: 4999 })}`;
|
|
|
|
});
|
|
|
|
|
2020-03-25 12:51:26 +00:00
|
|
|
export const STORAGE_PROVIDERS = ['ebs', 'zfs', 'nfs', 'cow', 'moo'];
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
export function generateResources(options = {}) {
|
2021-04-28 20:38:14 +00:00
|
|
|
const resources = {
|
2020-10-12 22:26:54 +00:00
|
|
|
Cpu: {
|
|
|
|
CpuShares: options.CPU || faker.helpers.randomize(CPU_RESERVATIONS),
|
|
|
|
},
|
|
|
|
Memory: {
|
|
|
|
MemoryMB: options.MemoryMB || faker.helpers.randomize(MEMORY_RESERVATIONS),
|
|
|
|
},
|
|
|
|
Disk: {
|
|
|
|
DiskMB: options.DiskMB || faker.helpers.randomize(DISK_RESERVATIONS),
|
|
|
|
},
|
2017-09-19 14:47:10 +00:00
|
|
|
Networks: generateNetworks(options.networks),
|
2020-08-20 15:07:13 +00:00
|
|
|
Ports: generatePorts(options.networks),
|
2017-09-19 14:47:10 +00:00
|
|
|
};
|
2021-04-28 20:38:14 +00:00
|
|
|
|
|
|
|
if (faker.random.boolean()) {
|
|
|
|
const higherMemoryReservations = MEMORY_RESERVATIONS.filter(mb => mb > resources.Memory.MemoryMB);
|
|
|
|
resources.Memory.MemoryMaxMB = faker.helpers.randomize(higherMemoryReservations) || resources.Memory.MemoryMB + 1;
|
|
|
|
} else {
|
|
|
|
resources.Memory.MemoryMaxMB = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resources;
|
2017-09-19 14:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function generateNetworks(options = {}) {
|
|
|
|
return Array(faker.random.number({ min: 1, max: 3 }))
|
|
|
|
.fill(null)
|
|
|
|
.map(() => ({
|
|
|
|
Device: `eth${faker.random.number({ max: 5 })}`,
|
|
|
|
CIDR: '',
|
|
|
|
IP: faker.internet.ip(),
|
|
|
|
MBits: 10,
|
2019-09-26 18:47:07 +00:00
|
|
|
Mode: faker.helpers.randomize(NETWORK_MODES),
|
2017-09-19 14:47:10 +00:00
|
|
|
ReservedPorts: Array(
|
|
|
|
faker.random.number({
|
2017-10-31 04:02:40 +00:00
|
|
|
min: options.minPorts != null ? options.minPorts : 0,
|
|
|
|
max: options.maxPorts != null ? options.maxPorts : 2,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.fill(null)
|
|
|
|
.map(() => ({
|
|
|
|
Label: faker.hacker.noun(),
|
|
|
|
Value: faker.random.number({ min: 5000, max: 60000 }),
|
2019-09-04 14:39:56 +00:00
|
|
|
To: faker.random.number({ min: 5000, max: 60000 }),
|
2017-10-31 04:02:40 +00:00
|
|
|
})),
|
|
|
|
DynamicPorts: Array(
|
|
|
|
faker.random.number({
|
|
|
|
min: options.minPorts != null ? options.minPorts : 0,
|
|
|
|
max: options.maxPorts != null ? options.maxPorts : 2,
|
2017-09-19 14:47:10 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.fill(null)
|
|
|
|
.map(() => ({
|
|
|
|
Label: faker.hacker.noun(),
|
|
|
|
Value: faker.random.number({ min: 5000, max: 60000 }),
|
2019-09-04 14:39:56 +00:00
|
|
|
To: faker.random.number({ min: 5000, max: 60000 }),
|
2017-09-19 14:47:10 +00:00
|
|
|
})),
|
|
|
|
}));
|
|
|
|
}
|
2020-08-20 15:07:13 +00:00
|
|
|
|
|
|
|
export function generatePorts(options = {}) {
|
2020-08-24 16:21:53 +00:00
|
|
|
return Array(
|
|
|
|
faker.random.number({
|
|
|
|
min: options.minPorts != null ? options.minPorts : 0,
|
|
|
|
max: options.maxPorts != null ? options.maxPorts : 2,
|
|
|
|
})
|
|
|
|
)
|
2020-08-20 15:07:13 +00:00
|
|
|
.fill(null)
|
|
|
|
.map(() => ({
|
|
|
|
Label: faker.hacker.noun(),
|
|
|
|
Value: faker.random.number({ min: 5000, max: 60000 }),
|
|
|
|
To: faker.random.number({ min: 5000, max: 60000 }),
|
|
|
|
HostIP: faker.random.boolean() ? faker.internet.ip() : faker.internet.ipv6(),
|
2020-08-24 16:21:53 +00:00
|
|
|
}));
|
|
|
|
}
|