2020-10-05 17:07:35 +00:00
|
|
|
import Route from '@ember/routing/route';
|
2020-12-08 15:47:55 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-12-16 09:18:29 +00:00
|
|
|
import { get, action } from '@ember/object';
|
2020-10-05 17:07:35 +00:00
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class TopologyRoute extends Route {
|
2020-12-08 15:47:55 +00:00
|
|
|
@service('ui-config') config;
|
2020-12-16 09:18:29 +00:00
|
|
|
@service('data-source/service') data;
|
|
|
|
@service('repository/intention') repo;
|
2020-12-08 15:47:55 +00:00
|
|
|
|
2020-12-16 09:18:29 +00:00
|
|
|
@action
|
|
|
|
async createIntention(source, destination) {
|
|
|
|
const model = this.repo.create({
|
|
|
|
Datacenter: source.Datacenter,
|
|
|
|
SourceName: source.Name,
|
|
|
|
SourceNS: source.Namespace || 'default',
|
|
|
|
DestinationName: destination.Name,
|
|
|
|
DestinationNS: destination.Namespace || 'default',
|
|
|
|
Action: 'allow',
|
|
|
|
});
|
|
|
|
await this.repo.persist(model);
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
async model() {
|
2020-10-05 17:07:35 +00:00
|
|
|
const parent = this.routeName
|
|
|
|
.split('.')
|
|
|
|
.slice(0, -1)
|
|
|
|
.join('.');
|
2020-12-16 09:18:29 +00:00
|
|
|
const model = this.modelFor(parent);
|
|
|
|
const dc = get(model, 'dc');
|
|
|
|
const nspace = get(model, 'nspace');
|
2020-12-08 15:47:55 +00:00
|
|
|
|
2020-12-16 09:18:29 +00:00
|
|
|
const item = get(model, 'items.firstObject');
|
2020-12-17 16:35:01 +00:00
|
|
|
let kind = get(item, 'Service.Kind');
|
|
|
|
if (typeof kind === 'undefined') {
|
|
|
|
kind = '';
|
2020-12-16 09:18:29 +00:00
|
|
|
}
|
2020-12-17 16:35:01 +00:00
|
|
|
const topology = await this.data.source(
|
|
|
|
uri => uri`/${nspace}/${dc.Name}/topology/${model.slug}/${kind}`
|
|
|
|
);
|
|
|
|
let hasMetricsProvider = await this.config.findByPath('metrics_provider');
|
|
|
|
hasMetricsProvider = !!hasMetricsProvider;
|
|
|
|
|
2020-12-08 15:47:55 +00:00
|
|
|
return {
|
2020-12-16 09:18:29 +00:00
|
|
|
...model,
|
2020-12-17 16:35:01 +00:00
|
|
|
topology,
|
|
|
|
hasMetricsProvider,
|
2020-12-08 15:47:55 +00:00
|
|
|
};
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setupController(controller, model) {
|
|
|
|
super.setupController(...arguments);
|
2020-10-05 17:07:35 +00:00
|
|
|
controller.setProperties(model);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|