2020-03-25 12:51:26 +00:00
|
|
|
import { Factory } from 'ember-cli-mirage';
|
|
|
|
import faker from 'nomad-ui/mirage/faker';
|
|
|
|
import { pickOne } from '../utils';
|
|
|
|
import { STORAGE_PROVIDERS } from '../common';
|
2022-04-07 19:51:41 +00:00
|
|
|
import { dasherize } from '@ember/string';
|
2020-03-25 12:51:26 +00:00
|
|
|
|
|
|
|
const ACCESS_MODES = ['multi-node-single-writer'];
|
|
|
|
const ATTACHMENT_MODES = ['file-system'];
|
|
|
|
|
|
|
|
export default Factory.extend({
|
2022-04-07 19:51:41 +00:00
|
|
|
id: (i) => `${dasherize(faker.hacker.noun())}-${i}`.toLowerCase(),
|
2020-03-25 12:51:26 +00:00
|
|
|
name() {
|
|
|
|
return this.id;
|
|
|
|
},
|
|
|
|
|
|
|
|
externalId: () => `vol-${faker.random.uuid().split('-')[0]}`,
|
|
|
|
|
|
|
|
// Topologies is currently unused by the UI. This should
|
|
|
|
// eventually become dynamic.
|
|
|
|
topologies: () => [{ foo: 'bar' }],
|
|
|
|
|
|
|
|
accessMode: faker.helpers.randomize(ACCESS_MODES),
|
|
|
|
attachmentMode: faker.helpers.randomize(ATTACHMENT_MODES),
|
|
|
|
|
|
|
|
schedulable: faker.random.boolean,
|
|
|
|
provider: faker.helpers.randomize(STORAGE_PROVIDERS),
|
|
|
|
version: '1.0.1',
|
|
|
|
controllerRequired: faker.random.boolean,
|
|
|
|
controllersHealthy: () => faker.random.number(10),
|
|
|
|
controllersExpected() {
|
|
|
|
return this.controllersHealthy + faker.random.number(10);
|
|
|
|
},
|
|
|
|
nodesHealthy: () => faker.random.number(10),
|
|
|
|
nodesExpected() {
|
|
|
|
return this.nodesHealthy + faker.random.number(10);
|
|
|
|
},
|
|
|
|
|
|
|
|
afterCreate(volume, server) {
|
|
|
|
if (!volume.namespaceId) {
|
2022-04-07 19:51:41 +00:00
|
|
|
const namespace = server.db.namespaces.length
|
|
|
|
? pickOne(server.db.namespaces).id
|
|
|
|
: null;
|
2020-03-25 12:51:26 +00:00
|
|
|
volume.update({
|
|
|
|
namespace,
|
|
|
|
namespaceId: namespace,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
volume.update({
|
|
|
|
namespace: volume.namespaceId,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!volume.plugin) {
|
2022-04-07 19:51:41 +00:00
|
|
|
const plugin = server.db.csiPlugins.length
|
|
|
|
? pickOne(server.db.csiPlugins)
|
|
|
|
: null;
|
2020-03-25 12:51:26 +00:00
|
|
|
volume.update({
|
|
|
|
PluginId: plugin && plugin.id,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
volume.update({
|
|
|
|
PluginId: volume.plugin.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|