1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
var collectConnectionPoints = function(resourceModel, diff) {
return collectPorts(resourceModel, diff)
};
function collectPorts(resourceModel, diff){
pathToResource = {}
collectResources('', resourceModel, pathToResource, true);
transformedPorts = []
Object.keys(pathToResource).forEach(function (path) {
var port = pathToResource[path];
transformedPort = {}
transformedPort.name = port.attributes.name;
transformedPort.providerId = port.attributes.id;
transformedPort.cpId = path;
var managedPort = false;
if(port.hasOwnProperty('externalConnectionPoint')){
transformedPort.ecpdId = port.externalConnectionPoint;
managedPort = true;
}
if(port.hasOwnProperty('connectionPoint')){
transformedPort.cpdId = port.connectionPoint;
managedPort = true;
}
transformedPort.tenantId = port.attributes.tenant_id;
transformedPort.ipAddress = port.attributes.fixed_ips[0].ip_address;
transformedPort.macAddress = port.attributes.mac_address;
transformedPort.serverProviderId = port.attributes.device_id;
transformedPort.networkProviderId = port.attributes.network_id;
transformedPort.changeType = 'untouched';
var added = contains(diff.add, path);
var removed = contains(diff.remove, path);
if(added && removed){
transformedPort.changeType = "MODIFIED";
}
else{
if(removed){
transformedPort.changeType = "REMOVED";
}
if(added){
transformedPort.changeType = "ADDED";
}
}
if('untouched' != transformedPort.changeType && managedPort){
transformedPorts.push(transformedPort)
}
})
return transformedPorts;
};
function contains(resourceChanges, path){
var keys = Object.keys(resourceChanges);
return keys.indexOf(path) !== -1;
}
function collectResources(path, root, pathToResouceMap, onResources){
root && Object.keys(root).forEach(function(item) {
if(item == 'resource_type' && root[item] == 'OS::Neutron::Port'){
pathToResouceMap[path] = root
}
else if(typeof root[item] === "object"){
var newItem = onResources ? "" : item;
var newPath = path;
if('' != newItem && path != ''){
newPath += ".";
}
newPath += newItem;
collectResources(newPath, root[item], pathToResouceMap, !onResources)
}
});
};
|