Fix release artifacts
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / docs / sample / cbam.collectConnectionPoints.js
1 var collectConnectionPoints = function(resourceModel, diff) {
2     return collectPorts(resourceModel, diff)
3 };
4
5 function collectPorts(resourceModel, diff){
6     pathToResource = {}
7     collectResources('', resourceModel, pathToResource, true);
8     transformedPorts = []
9     Object.keys(pathToResource).forEach(function (path) {
10         var port = pathToResource[path];
11         transformedPort = {}
12         transformedPort.name = port.attributes.name;
13         transformedPort.providerId = port.attributes.id;
14         transformedPort.cpId = path;
15         var managedPort = false;
16         if(port.hasOwnProperty('externalConnectionPoint')){
17             transformedPort.ecpdId = port.externalConnectionPoint;
18             managedPort = true;
19         }
20         if(port.hasOwnProperty('connectionPoint')){
21             transformedPort.cpdId = port.connectionPoint;
22             managedPort = true;
23         }
24         transformedPort.tenantId = port.attributes.tenant_id;
25         transformedPort.ipAddress = port.attributes.fixed_ips[0].ip_address;
26         transformedPort.macAddress = port.attributes.mac_address;
27         transformedPort.serverProviderId = port.attributes.device_id;
28         transformedPort.networkProviderId = port.attributes.network_id;
29         if(managedPort){
30             transformedPorts.push(transformedPort)
31         }
32     })
33     return transformedPorts;
34 };
35
36 function contains(resourceChanges, path){
37     var keys = Object.keys(resourceChanges);
38     return keys.indexOf(path) !== -1;
39 }
40
41 function collectResources(path, root, pathToResouceMap, onResources){
42     root && Object.keys(root).forEach(function(item) {
43         if(item == 'resource_type' && root[item] == 'OS::Neutron::Port'){
44             pathToResouceMap[path] = root
45         }
46         else if(typeof root[item] === "object"){
47             var newItem = onResources ? "" : item;
48             var newPath = path;
49             if('' != newItem && path != ''){
50                 newPath += ".";
51             }
52             newPath += newItem;
53             collectResources(newPath, root[item], pathToResouceMap, !onResources)
54         }
55     });
56 };
57