Rift.IO OSM R1 Initial Submission
[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 model = DescriptorModelMetaFactory.createModelInstanceForType('vnfd.vdu');
56 return this.vdu = DescriptorModelFactory.newVirtualDeploymentUnit(model, this);
57 }
58
59 removeVirtualDeploymentUnit(vdu) {
60 vdu.connectors.forEach(cp => this.removeAnyConnectionsForConnector(cp));
61 return this.vdu = this.vdu.filter(d => d.id !== vdu.id);
62 }
63
64 get vld() {
65 const list = this.model['internal-vld'] || (this.model['internal-vld'] = []);
66 return list.map(d => DescriptorModelFactory.newInternalVirtualLink(d, this));
67 }
68
69 set vld(obj) {
70 this.updateModelList('internal-vld', obj, DescriptorModelFactory.InternalVirtualLink);
71 }
72
73 createVld() {
74 const model = DescriptorModelMetaFactory.createModelInstanceForType('vnfd.internal-vld');
75 return this.vld = DescriptorModelFactory.newInternalVirtualLink(model, this);
76 }
77
78 /**
79 * @deprecated use `removeInternalVirtualLink()`
80 * @param vld
81 * @returns {*}
82 */
83 removeVld(vld) {
84 return this.removeModelListItem('vld', vld);
85 }
86
87 get connectionPoint() {
88 const list = this.model['connection-point'] || (this.model['connection-point'] = []);
89 return list.map(d => DescriptorModelFactory.newVirtualNetworkFunctionConnectionPoint(d, this));
90 }
91
92 set connectionPoint(obj) {
93 return this.updateModelList('connection-point', obj, DescriptorModelFactory.VirtualNetworkFunctionConnectionPoint);
94 }
95
96 removeConnectionPoint(cp) {
97 return this.removeModelListItem('connectionPoint', cp);
98 }
99
100 get connectors() {
101 return this.connectionPoint;
102 }
103
104 remove() {
105 if (this.parent) {
106 this.parent.removeConstituentVnfd(this);
107 this.connectors.forEach(cpc => this.parent.removeAnyConnectionsForConnector(cpc));
108 }
109 }
110
111 removeAnyConnectionsForConnector(cpc) {
112 this.vld.forEach(vld => vld.removeInternalConnectionPointRefForId(cpc.id));
113 }
114
115 removeInternalVirtualLink(ivl) {
116 return this.removeModelListItem('vld', ivl);
117 }
118
119 }
120