github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/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 const STORAGE_PROVIDERS = ['ebs', 'zfs', 'nfs', 'cow', 'moo']; 27 28 export function generateResources(options = {}) { 29 return { 30 CPU: faker.helpers.randomize(CPU_RESERVATIONS), 31 MemoryMB: faker.helpers.randomize(MEMORY_RESERVATIONS), 32 DiskMB: faker.helpers.randomize(DISK_RESERVATIONS), 33 IOPS: faker.helpers.randomize(IOPS_RESERVATIONS), 34 Networks: generateNetworks(options.networks), 35 }; 36 } 37 38 export function generateNetworks(options = {}) { 39 return Array(faker.random.number({ min: 1, max: 3 })) 40 .fill(null) 41 .map(() => ({ 42 Device: `eth${faker.random.number({ max: 5 })}`, 43 CIDR: '', 44 IP: faker.internet.ip(), 45 MBits: 10, 46 Mode: faker.helpers.randomize(NETWORK_MODES), 47 ReservedPorts: Array( 48 faker.random.number({ 49 min: options.minPorts != null ? options.minPorts : 0, 50 max: options.maxPorts != null ? options.maxPorts : 2, 51 }) 52 ) 53 .fill(null) 54 .map(() => ({ 55 Label: faker.hacker.noun(), 56 Value: faker.random.number({ min: 5000, max: 60000 }), 57 To: faker.random.number({ min: 5000, max: 60000 }), 58 })), 59 DynamicPorts: Array( 60 faker.random.number({ 61 min: options.minPorts != null ? options.minPorts : 0, 62 max: options.maxPorts != null ? options.maxPorts : 2, 63 }) 64 ) 65 .fill(null) 66 .map(() => ({ 67 Label: faker.hacker.noun(), 68 Value: faker.random.number({ min: 5000, max: 60000 }), 69 To: faker.random.number({ min: 5000, max: 60000 }), 70 })), 71 })); 72 }