Merge branch 'main' into feat-typed-host

This commit is contained in:
Dharini Jeeva authored and GitHub committed 2022-02-11 15:56:47 -08:00
commit 13903fe8b9
2 files changed
+37 -4

No files matched your search

+36
View File
@@ -1,5 +1,32 @@
import factory from '../generated/factories/host';
import permissions from '../helpers/permissions';
import { internet, datatype } from 'faker';
/**
* Returns an array of strings with IP addresses.
* @returns {array}
*/
const returnIpAddressesArray = () => {
const addressesAmount = Math.floor(Math.random() * 6) + 1;
let result = [];
for (let i = 0; i < addressesAmount; ++i) {
result.push(internet.ip());
}
return result;
};
/**
* Returns an array of strings with DNS names.
* @param {string} hostType
*/
const returnDnsNames = () => {
const dnsNamesAmount = Math.floor(Math.random() * 6) + 1;
let result = [];
for (let i = 0; i < dnsNamesAmount; i++) {
result.push(internet.domainName());
}
return result;
};
export default factory.extend({
id: (i) => `host-id-${i}`,
@@ -18,4 +45,13 @@ export default factory.extend({
return this.hostCatalog.plugin;
}
},
attributes() {
return {
address: internet.ipv6(),
ip_addresses: returnIpAddressesArray(),
external_id: datatype.uuid(),
// Only aws plugins have dns_names
dns_names: this.plugin?.name === 'aws' ? returnDnsNames() : undefined,
};
},
});
@@ -1,5 +1,5 @@
import { Factory } from 'ember-cli-mirage';
import { random, date, internet, datatype } from 'faker';
import { random, date, datatype } from 'faker';
/**
* GeneratedHostModelFactory
@@ -11,7 +11,4 @@ export default Factory.extend({
created_time: () => date.recent(),
updated_time: () => date.recent(),
version: () => datatype.number(),
attributes: () => {
return { address: internet.ipv6() };
},
});