github.com/emate/nomad@v0.8.2-wo-binpacking/ui/mirage/factories/node.js (about)

     1  import { Factory, faker, trait } from 'ember-cli-mirage';
     2  import { provide } from '../utils';
     3  import { DATACENTERS, HOSTS } from '../common';
     4  
     5  const UUIDS = provide(100, faker.random.uuid.bind(faker.random));
     6  const NODE_STATUSES = ['initializing', 'ready', 'down'];
     7  
     8  export default Factory.extend({
     9    id: i => (i / 100 >= 1 ? `${UUIDS[i]}-${i}` : UUIDS[i]),
    10    name: i => `nomad@${HOSTS[i % HOSTS.length]}`,
    11  
    12    datacenter: faker.list.random(...DATACENTERS),
    13    isDraining: faker.random.boolean,
    14    status: faker.list.random(...NODE_STATUSES),
    15    tls_enabled: faker.random.boolean,
    16  
    17    createIndex: i => i,
    18    modifyIndex: () => faker.random.number({ min: 10, max: 2000 }),
    19  
    20    httpAddr() {
    21      return this.name.split('@')[1];
    22    },
    23  
    24    forceIPv4: trait({
    25      name: i => {
    26        const ipv4Hosts = HOSTS.filter(h => !h.startsWith('['));
    27        return `nomad@${ipv4Hosts[i % ipv4Hosts.length]}`;
    28      },
    29    }),
    30  
    31    attributes() {
    32      // TODO add variability to these
    33      return {
    34        'os.version': '10.12.5',
    35        'cpu.modelname': 'Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz',
    36        'nomad.revision': 'f551dcb83e3ac144c9dbb90583b6e82d234662e9',
    37        'driver.docker.volumes.enabled': '1',
    38        'driver.docker': '1',
    39        'cpu.frequency': '2300',
    40        'memory.totalbytes': '17179869184',
    41        'driver.mock_driver': '1',
    42        'kernel.version': '16.6.0',
    43        'unique.network.ip-address': '127.0.0.1',
    44        'nomad.version': '0.5.5dev',
    45        'unique.hostname': 'bacon-mac',
    46        'cpu.arch': 'amd64',
    47        'os.name': 'darwin',
    48        'kernel.name': 'darwin',
    49        'unique.storage.volume': '/dev/disk1',
    50        'driver.docker.version': '17.03.1-ce',
    51        'cpu.totalcompute': '18400',
    52        'unique.storage.bytestotal': '249783500800',
    53        'cpu.numcores': '8',
    54        'os.signals':
    55          'SIGCONT,SIGSTOP,SIGSYS,SIGINT,SIGIOT,SIGXCPU,SIGSEGV,SIGUSR1,SIGTTIN,SIGURG,SIGUSR2,SIGABRT,SIGALRM,SIGCHLD,SIGFPE,SIGTSTP,SIGIO,SIGKILL,SIGQUIT,SIGXFSZ,SIGBUS,SIGHUP,SIGPIPE,SIGPROF,SIGTRAP,SIGTTOU,SIGILL,SIGTERM',
    56        'driver.raw_exec': '1',
    57        'unique.storage.bytesfree': '142954643456',
    58      };
    59    },
    60  
    61    withMeta: trait({
    62      meta: {
    63        just: 'some',
    64        prop: 'erties',
    65        'over.here': 100,
    66      },
    67    }),
    68  
    69    afterCreate(node, server) {
    70      // Each node has a corresponding client stats resource that's queried via node IP.
    71      // Create that record, even though it's not a relationship.
    72      server.create('client-stats', {
    73        id: node.httpAddr,
    74      });
    75    },
    76  });