github.com/iqoqo/nomad@v0.11.3-0.20200911112621-d7021c74d101/ui/mirage/factories/csi-plugin.js (about) 1 import { Factory } from 'ember-cli-mirage'; 2 import faker from 'nomad-ui/mirage/faker'; 3 import { STORAGE_PROVIDERS } from '../common'; 4 5 export default Factory.extend({ 6 id: () => faker.random.uuid(), 7 8 // Topologies is currently unused by the UI. This should 9 // eventually become dynamic. 10 topologies: () => [{ foo: 'bar' }], 11 12 provider: faker.helpers.randomize(STORAGE_PROVIDERS), 13 version: '1.0.1', 14 controllerRequired: faker.random.boolean, 15 controllersHealthy: () => faker.random.number(3), 16 controllersExpected() { 17 return this.controllersHealthy + faker.random.number({ min: 1, max: 2 }); 18 }, 19 20 nodesHealthy: () => faker.random.number(3), 21 nodesExpected() { 22 return this.nodesHealthy + faker.random.number({ min: 1, max: 2 }); 23 }, 24 25 // Internal property to determine whether or not this plugin 26 // Should create one or two Jobs to represent Node and 27 // Controller plugins. 28 isMonolith: faker.random.boolean, 29 30 // When false, the plugin will not make its own volumes 31 createVolumes: true, 32 33 // When true, doesn't create any resources, state, or events for associated allocations 34 shallow: false, 35 36 afterCreate(plugin, server) { 37 let storageNodes; 38 let storageControllers; 39 40 if (plugin.isMonolith) { 41 const pluginJob = server.create('job', { type: 'service', createAllocations: false }); 42 const count = plugin.nodesExpected; 43 storageNodes = server.createList('storage-node', count, { 44 job: pluginJob, 45 shallow: plugin.shallow, 46 }); 47 storageControllers = server.createList('storage-controller', count, { 48 job: pluginJob, 49 shallow: plugin.shallow, 50 }); 51 } else { 52 const controllerJob = server.create('job', { 53 type: 'service', 54 createAllocations: false, 55 shallow: plugin.shallow, 56 }); 57 const nodeJob = server.create('job', { 58 type: 'service', 59 createAllocations: false, 60 shallow: plugin.shallow, 61 }); 62 storageNodes = server.createList('storage-node', plugin.nodesExpected, { 63 job: nodeJob, 64 shallow: plugin.shallow, 65 }); 66 storageControllers = server.createList('storage-controller', plugin.controllersExpected, { 67 job: controllerJob, 68 shallow: plugin.shallow, 69 }); 70 } 71 72 plugin.update({ 73 controllers: storageControllers, 74 nodes: storageNodes, 75 }); 76 77 if (plugin.createVolumes) { 78 server.createList('csi-volume', faker.random.number({ min: 1, max: 5 }), { 79 plugin, 80 provider: plugin.provider, 81 }); 82 } 83 }, 84 });