Improve auto generation of list key values. (RIFT-15923)
[osm/UI.git] / skyquake / plugins / composer / src / src / libraries / model / descriptors / VirtualNetworkFunction.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 /**
19 * Created by onvelocity on 11/23/15.
20 */
21
22 'use strict';
23
24 import utils from '../../utils'
25 import DescriptorModel from '../DescriptorModel'
26 import DescriptorModelFactory from '../DescriptorModelFactory'
27 import DescriptorModelMetaFactory from '../DescriptorModelMetaFactory'
28
29 export default class VirtualNetworkFunction extends DescriptorModel {
30
31 static get type() {
32 return 'vnfd';
33 }
34
35 static get className() {
36 return 'VirtualNetworkFunction';
37 }
38
39 constructor(model, parent) {
40 super(model, parent);
41 this.type = 'vnfd';
42 this.className = 'VirtualNetworkFunction';
43 }
44
45 get vdu() {
46 const list = this.model.vdu || (this.model.vdu = []);
47 return list.map(d => DescriptorModelFactory.newVirtualDeploymentUnit(d, this));
48 }
49
50 set vdu(obj) {
51 this.updateModelList('vdu', obj, DescriptorModelFactory.VirtualDeploymentUnit);
52 }
53
54 createVdu() {
55 const property = DescriptorModelMetaFactory.getModelMetaForType('vnfd.vdu');
56 const uniqueName = DescriptorModelMetaFactory.generateItemUniqueName(this.vdu, property);
57 const model = DescriptorModelMetaFactory.createModelInstanceForType('vnfd.vdu', uniqueName);
58 return this.vdu = DescriptorModelFactory.newVirtualDeploymentUnit(model, this);
59 }
60
61 removeVirtualDeploymentUnit(vdu) {
62 vdu.connectors.forEach(cp => this.removeAnyConnectionsForConnector(cp));
63 return this.vdu = this.vdu.filter(d => d.id !== vdu.id);
64 }
65
66 get vld() {
67 const list = this.model['internal-vld'] || (this.model['internal-vld'] = []);
68 return list.map(d => DescriptorModelFactory.newInternalVirtualLink(d, this));
69 }
70
71 set vld(obj) {
72 this.updateModelList('internal-vld', obj, DescriptorModelFactory.InternalVirtualLink);
73 }
74
75 createVld() {
76 const property = DescriptorModelMetaFactory.getModelMetaForType('vnfd.internal-vld');
77 const uniqueName = DescriptorModelMetaFactory.generateItemUniqueName(this['internal-vld'], property);
78 const model = DescriptorModelMetaFactory.createModelInstanceForType('vnfd.internal-vld', uniqueName);
79 return this.vld = DescriptorModelFactory.newInternalVirtualLink(model, this);
80 }
81
82 /**
83 * @deprecated use `removeInternalVirtualLink()`
84 * @param vld
85 * @returns {*}
86 */
87 removeVld(vld) {
88 return this.removeModelListItem('vld', vld);
89 }
90
91 get connectionPoint() {
92 const list = this.model['connection-point'] || (this.model['connection-point'] = []);
93 return list.map(d => DescriptorModelFactory.newVirtualNetworkFunctionConnectionPoint(d, this));
94 }
95
96 set connectionPoint(obj) {
97 return this.updateModelList('connection-point', obj, DescriptorModelFactory.VirtualNetworkFunctionConnectionPoint);
98 }
99
100 removeConnectionPoint(cp) {
101 return this.removeModelListItem('connectionPoint', cp);
102 }
103
104 get connectors() {
105 return this.connectionPoint;
106 }
107
108 remove() {
109 if (this.parent) {
110 this.parent.removeConstituentVnfd(this);
111 this.connectors.forEach(cpc => this.parent.removeAnyConnectionsForConnector(cpc));
112 }
113 }
114
115 removeAnyConnectionsForConnector(cpc) {
116 this.vld.forEach(vld => vld.removeInternalConnectionPointRefForId(cpc.id));
117 }
118
119 removeInternalVirtualLink(ivl) {
120 return this.removeModelListItem('vld', ivl);
121 }
122
123 }
124