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

83 lines
2.2 KiB
JavaScript

import GeneratedHostSetModel from '../generated/models/host-set';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
//import { computed } from '@ember/object';
export default class HostSetModel extends GeneratedHostSetModel {
// =attributes
/**
* Grants is read-only _most_ under normal circumstances. But grants can
* be persisted via a dedicated call to `saveGrants()`.
*/
@fragmentArray('fragment-string', {readOnly: true}) host_ids;
// TODO this is here in case we want it in the future,
// especially for the target / add host sets workflow
/**
* Returns the host catalog instance associated with this host set if
* it is already loaded into the store.
* @type {?HostCatalogModel}
*/
// @computed('host_catalog_id')
// get hostCatalog() {
// return this.store.peekRecord('host-catalog', this.host_catalog_id);
// }
// =methods
/**
* Adds hosts via the `add-hosts` method.
* See serializer and adapter for more information.
* @param {[string]} hostIDs
* @param {object} options
* @param {object} options.adapterOptions
* @return {Promise}
*/
addHosts(hostIDs, options={ adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'add-hosts',
hostIDs
};
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
});
}
/**
* 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}
*/
removeHosts(hostIDs, options={ adapterOptions: {} }) {
const defaultAdapterOptions = {
method: 'remove-hosts',
hostIDs
};
return this.save({
...options,
adapterOptions: {
...defaultAdapterOptions,
...options.adapterOptions
}
});
}
/**
* 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);
}
}