github.com/manicqin/nomad@v0.9.5/ui/mirage/common.js (about) 1 import faker from 'nomad-ui/mirage/faker'; 2 import { provide } from './utils'; 3 4 // Realistically, resource reservations have a low cardinality 5 const CPU_RESERVATIONS = [250, 500, 1000, 2000, 2500, 4000]; 6 const MEMORY_RESERVATIONS = [256, 512, 1024, 2048, 4096, 8192]; 7 const DISK_RESERVATIONS = [200, 500, 1000, 2000, 5000, 10000, 100000]; 8 const IOPS_RESERVATIONS = [100000, 250000, 500000, 1000000, 10000000, 20000000]; 9 10 // There is also a good chance that certain resource restrictions are unbounded 11 IOPS_RESERVATIONS.push(...Array(1000).fill(0)); 12 DISK_RESERVATIONS.push(...Array(500).fill(0)); 13 14 const NETWORK_MODES = ['bridge', 'host']; 15 16 export const DATACENTERS = provide( 17 15, 18 (n, i) => `${faker.address.countryCode().toLowerCase()}${i}` 19 ); 20 21 export const HOSTS = provide(100, () => { 22 const ip = faker.random.boolean() ? faker.internet.ip() : `[${faker.internet.ipv6()}]`; 23 return `${ip}:${faker.random.number({ min: 4000, max: 4999 })}`; 24 }); 25 26 export function generateResources(options = {}) { 27 return { 28 CPU: faker.helpers.randomize(CPU_RESERVATIONS), 29 MemoryMB: faker.helpers.randomize(MEMORY_RESERVATIONS), 30 DiskMB: faker.helpers.randomize(DISK_RESERVATIONS), 31 IOPS: faker.helpers.randomize(IOPS_RESERVATIONS), 32 Networks: generateNetworks(options.networks), 33 }; 34 } 35 36 export function generateNetworks(options = {}) { 37 return Array(faker.random.number({ min: 1, max: 3 })) 38 .fill(null) 39 .map(() => ({ 40 Device: `eth${faker.random.number({ max: 5 })}`, 41 CIDR: '', 42 IP: faker.internet.ip(), 43 MBits: 10, 44 Mode: faker.helpers.randomize(NETWORK_MODES), 45 ReservedPorts: Array( 46 faker.random.number({ 47 min: options.minPorts != null ? options.minPorts : 0, 48 max: options.maxPorts != null ? options.maxPorts : 2, 49 }) 50 ) 51 .fill(null) 52 .map(() => ({ 53 Label: faker.hacker.noun(), 54 Value: faker.random.number({ min: 5000, max: 60000 }), 55 To: faker.random.number({ min: 5000, max: 60000 }), 56 })), 57 DynamicPorts: Array( 58 faker.random.number({ 59 min: options.minPorts != null ? options.minPorts : 0, 60 max: options.maxPorts != null ? options.maxPorts : 2, 61 }) 62 ) 63 .fill(null) 64 .map(() => ({ 65 Label: faker.hacker.noun(), 66 Value: faker.random.number({ min: 5000, max: 60000 }), 67 To: faker.random.number({ min: 5000, max: 60000 }), 68 })), 69 })); 70 }