0d23fc1077d39380634b040b783ef4e0996441b1
[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 DescriptorModel from '../DescriptorModel'
27 import DescriptorModelFactory from '../DescriptorModelFactory'
28
29 export default class VirtualDeploymentUnit extends DescriptorModel {
30
31         static get type() {
32                 return 'vdu';
33         }
34
35         static get className() {
36                 return 'VirtualDeploymentUnit';
37         }
38
39         constructor(model, parent) {
40                 super(model, parent);
41                 this.type = 'vdu';
42                 this.uiState['qualified-type'] = 'vnfd.vdu';
43                 this.className = 'VirtualDeploymentUnit';
44         }
45
46         get key() {
47                 return this.parent.key + '/' + super.key;
48         }
49
50         get connectionPoint() {
51                 const list = this.model['internal-connection-point'] || (this.model['internal-connection-point'] = []);
52                 return list.map(d => DescriptorModelFactory.newVirtualDeploymentUnitInternalConnectionPoint(d, this));
53         }
54
55         set connectionPoint(obj) {
56                 return this.updateModelList('internal-connection-point', obj, DescriptorModelFactory.VirtualDeploymentUnitInternalConnectionPoint);
57         }
58
59         //get internalConnectionPoint() {
60         //      //https://trello.com/c/ZOyKQd3z/122-hide-lines-representing-interface-connection-point-references-both-internal-and-external-interfaces
61         //      const vduc = this;
62         //      if (this.model && this.model['internal-interface']) {
63         //              const icpMap = this.model['internal-connection-point'].reduce((r, d) => {
64         //                      r[d.id] = d;
65         //                      return r;
66         //              }, {});
67         //              return this.model['internal-interface'].reduce((result, internalIfc) => {
68         //                      const id = internalIfc['vdu-internal-connection-point-ref'];
69         //                      const keyPrefix = vduc.parent ? vduc.parent.key + '/' : '';
70         //                      if (icpMap[id]) {
71         //                              const icp = Object.assign({}, icpMap[id], {
72         //                                      key: keyPrefix + id,
73         //                                      name: internalIfc.name,
74         //                                      'virtual-interface': internalIfc['virtual-interface']
75         //                              });
76         //                              result.push(icp);
77         //                      }
78         //                      return result;
79         //              }, []);
80         //      }
81         //      return [];
82         //}
83
84         removeInternalConnectionPoint(icp) {
85                 this.parent.removeAnyConnectionsForConnector(icp);
86                 return this.removeModelListItem('connectionPoint', icp);
87         }
88
89         //get externalConnectionPoint() {
90         //      // https://trello.com/c/ZOyKQd3z/122-hide-lines-representing-interface-connection-point-references-both-internal-and-external-interfaces
91         //      //const vduc = this;
92         //      //if (vduc.model && vduc.model['external-interface']) {
93         //      //      return vduc.model['external-interface'].reduce((result, externalIfc) => {
94         //      //              const id = externalIfc['vnfd-connection-point-ref'];
95         //      //              const keyPrefix = vduc.parent ? vduc.parent.key + '/' : '';
96         //      //              result.push({id: id, key: keyPrefix + id});
97         //      //              return result;
98         //      //      }, []);
99         //      //}
100         //      return [];
101         //}
102         //
103         get connectors() {
104                 return this.connectionPoint;
105         }
106
107         //get connection() {
108         //      return this.externalConnectionPoint;
109         //}
110
111         remove() {
112                 return this.parent.removeVirtualDeploymentUnit(this);
113         }
114
115 }
116