diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-02-12 20:55:54 +0100 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-02-23 11:44:45 +0100 |
commit | b17042b955489d8a023d09abad5436ff9b900dc3 (patch) | |
tree | 1e4392ac04a2fb1ed8d17075d504cf6594acaf16 /nokiav2/docs/sample/cbam.collectConnectionPoints.js | |
parent | d4982f7b1777e9cdae9a4cc7d0d104263889ac69 (diff) |
Updating Nokia driver
Change-Id: I950afe6acbdb359cd67a448024f006a45e8fc293
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/docs/sample/cbam.collectConnectionPoints.js')
-rw-r--r-- | nokiav2/docs/sample/cbam.collectConnectionPoints.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/nokiav2/docs/sample/cbam.collectConnectionPoints.js b/nokiav2/docs/sample/cbam.collectConnectionPoints.js new file mode 100644 index 00000000..f5cfc675 --- /dev/null +++ b/nokiav2/docs/sample/cbam.collectConnectionPoints.js @@ -0,0 +1,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) + } + }); +}; + |