mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 17:05:43 +03:00
Fixes #14617 Dynamic Node Metadata allows Nomad users, and their jobs, to update Node metadata through an API. Currently Node metadata is only reloaded when a Client agent is restarted. Includes new UI for editing metadata as well. --------- Co-authored-by: Phil Renaud <phil.renaud@hashicorp.com>
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
import { set } from '@ember/object';
|
|
import { get, computed } from '@ember/object';
|
|
import { attr } from '@ember-data/model';
|
|
import Fragment from 'ember-data-model-fragments/fragment';
|
|
import flat from 'flat';
|
|
|
|
const { unflatten } = flat;
|
|
|
|
export default class StructuredAttributes extends Fragment {
|
|
@attr() raw;
|
|
|
|
recomputeRawProperties(incoming) {
|
|
set(this, 'raw', incoming);
|
|
}
|
|
|
|
@computed('raw')
|
|
get structured() {
|
|
const original = this.raw;
|
|
|
|
if (!original) {
|
|
return undefined;
|
|
}
|
|
|
|
// `unflatten` doesn't sort keys before unflattening, so manual preprocessing is necessary.
|
|
const attrs = Object.keys(original)
|
|
.sort()
|
|
.reduce((obj, key) => {
|
|
obj[key] = original[key];
|
|
return obj;
|
|
}, {});
|
|
return unflatten(attrs, { overwrite: true });
|
|
}
|
|
|
|
unknownProperty(key) {
|
|
// Returns the exact value in index 0 and the subtree in index 1
|
|
//
|
|
// ex: nodeAttrs.get('driver.docker')
|
|
// [ "1", { version: "17.05.0-ce", volumes: { enabled: "1" } } ]
|
|
if (this.structured) {
|
|
return get(this.structured, key);
|
|
}
|
|
}
|
|
}
|