Files
threshold-ui/addons/api/addon/models/host-set.js
T

140 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-08-13 17:05:09 -04:00
import GeneratedHostSetModel from '../generated/models/host-set';
2020-08-19 18:38:18 -04:00
import { fragmentArray } from 'ember-data-model-fragments/attributes';
2020-08-13 17:05:09 -04:00
2020-08-19 18:38:18 -04:00
export default class HostSetModel extends GeneratedHostSetModel {
// =attributes
2022-01-26 07:56:36 -08:00
/**
* Returns if the host-set is static or not.
* @type {boolean}
*/
get isStatic() {
return this.type === 'static';
}
/**
* Returns if the host-set is plugin or not.
* @type {boolean}
*/
get isPlugin() {
return this.type === 'plugin';
}
/**
* Returns if a host-set plugin is AWS or not
* @type {boolean}
*/
get isAWS() {
return this.compositeType === 'aws';
}
/**
* Return if a host-set plugin is Azure or not.
*/
get isAzure() {
return this.compositeType === 'azure';
}
/**
* If a host-set is a plugin return its name,
* otherwise returns the host-set type
* @type {string}
*/
get compositeType() {
return this.plugin ? this.plugin.name : this.type;
}
/**
* Sets type, if type is different than static, set plugin name to type
*/
set compositeType(type) {
if (type === 'static') {
this.type = 'static';
} else {
this.type = 'plugin';
this.plugin = { name: type };
}
}
2020-08-19 18:38:18 -04:00
/**
* Host IDs are read-only under normal circumstances. But these can
* be persisted via a dedicated call to `addHosts()`.
2020-08-19 18:38:18 -04:00
*/
2020-09-12 11:20:38 -04:00
@fragmentArray('fragment-string', {
readOnly: true,
2020-09-16 14:29:02 -04:00
emptyArrayIfMissing: true,
})
host_ids;
2020-08-19 18:38:18 -04:00
2022-02-01 11:14:43 -08:00
// Not sure if re-use this fragment.
@fragmentArray('fragment-string', {
emptyArrayIfMissing: true, // Not sure if should be true.
})
preferred_endpoints;
2020-08-19 18:38:18 -04:00
// =methods
/**
* Adds hosts via the `add-hosts` method.
2020-08-19 18:38:18 -04:00
* See serializer and adapter for more information.
* @param {[string]} hostIDs
2020-08-20 12:04:54 -04:00
* @param {object} options
* @param {object} options.adapterOptions
2020-08-19 18:38:18 -04:00
* @return {Promise}
*/
2020-09-16 14:29:02 -04:00
addHosts(hostIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-hosts',
2020-09-16 14:29:02 -04:00
hostIDs,
};
return this.save({
...options,
2020-08-19 18:38:18 -04:00
adapterOptions: {
...defaultAdapterOptions,
2020-09-16 14:29:02 -04:00
...options.adapterOptions,
},
});
}
/**
* Add a single host via the `add-hosts` method.
* @param {string} hostID
* @param {object} options
* @return {Promise}
*/
addHost(hostID, options) {
return this.addHosts([hostID], options);
}
/**
* Delete hosts via the `remove-hosts` method.
* See serializer and adapter for more information.
* @param {[string]} hostIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
2020-09-16 14:29:02 -04:00
removeHosts(hostIDs, options = { adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'remove-hosts',
2020-09-16 14:29:02 -04:00
hostIDs,
2020-08-20 12:04:54 -04:00
};
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
2020-09-16 14:29:02 -04:00
...options.adapterOptions,
},
2020-08-19 18:38:18 -04:00
});
}
/**
* Delete a single host via the `remove-hosts` method.
* @param {string} hostID
* @param {object} options
* @return {Promise}
*/
removeHost(hostID, options) {
return this.removeHosts([hostID], options);
}
2020-08-19 18:38:18 -04:00
}