github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/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  
     9  // There is also a good chance that certain resource restrictions are unbounded
    10  DISK_RESERVATIONS.push(...Array(500).fill(0));
    11  
    12  const NETWORK_MODES = ['bridge', 'host'];
    13  
    14  export const DATACENTERS = provide(
    15    15,
    16    (n, i) => `${faker.address.countryCode().toLowerCase()}${i}`
    17  );
    18  
    19  export const HOSTS = provide(100, () => {
    20    const ip = faker.random.boolean() ? faker.internet.ip() : `[${faker.internet.ipv6()}]`;
    21    return `${ip}:${faker.random.number({ min: 4000, max: 4999 })}`;
    22  });
    23  
    24  export const STORAGE_PROVIDERS = ['ebs', 'zfs', 'nfs', 'cow', 'moo'];
    25  
    26  export function generateResources(options = {}) {
    27    return {
    28      Cpu: {
    29        CpuShares: options.CPU || faker.helpers.randomize(CPU_RESERVATIONS),
    30      },
    31      Memory: {
    32        MemoryMB: options.MemoryMB || faker.helpers.randomize(MEMORY_RESERVATIONS),
    33      },
    34      Disk: {
    35        DiskMB: options.DiskMB || faker.helpers.randomize(DISK_RESERVATIONS),
    36      },
    37      Networks: generateNetworks(options.networks),
    38      Ports: generatePorts(options.networks),
    39    };
    40  }
    41  
    42  export function generateNetworks(options = {}) {
    43    return Array(faker.random.number({ min: 1, max: 3 }))
    44      .fill(null)
    45      .map(() => ({
    46        Device: `eth${faker.random.number({ max: 5 })}`,
    47        CIDR: '',
    48        IP: faker.internet.ip(),
    49        MBits: 10,
    50        Mode: faker.helpers.randomize(NETWORK_MODES),
    51        ReservedPorts: Array(
    52          faker.random.number({
    53            min: options.minPorts != null ? options.minPorts : 0,
    54            max: options.maxPorts != null ? options.maxPorts : 2,
    55          })
    56        )
    57          .fill(null)
    58          .map(() => ({
    59            Label: faker.hacker.noun(),
    60            Value: faker.random.number({ min: 5000, max: 60000 }),
    61            To: faker.random.number({ min: 5000, max: 60000 }),
    62          })),
    63        DynamicPorts: Array(
    64          faker.random.number({
    65            min: options.minPorts != null ? options.minPorts : 0,
    66            max: options.maxPorts != null ? options.maxPorts : 2,
    67          })
    68        )
    69          .fill(null)
    70          .map(() => ({
    71            Label: faker.hacker.noun(),
    72            Value: faker.random.number({ min: 5000, max: 60000 }),
    73            To: faker.random.number({ min: 5000, max: 60000 }),
    74          })),
    75      }));
    76  }
    77  
    78  export function generatePorts(options = {}) {
    79    return Array(
    80      faker.random.number({
    81        min: options.minPorts != null ? options.minPorts : 0,
    82        max: options.maxPorts != null ? options.maxPorts : 2,
    83      })
    84    )
    85      .fill(null)
    86      .map(() => ({
    87        Label: faker.hacker.noun(),
    88        Value: faker.random.number({ min: 5000, max: 60000 }),
    89        To: faker.random.number({ min: 5000, max: 60000 }),
    90        HostIP: faker.random.boolean() ? faker.internet.ip() : faker.internet.ipv6(),
    91      }));
    92  }