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