X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=inline;f=skyquake%2Fplugins%2Flaunchpad%2Fapi%2Fepa_aggregator.js;fp=skyquake%2Fplugins%2Flaunchpad%2Fapi%2Fepa_aggregator.js;h=5577226f79d14e47a4f65323db2d26208e2ef57b;hb=e29efc315df33d546237e270470916e26df391d6;hp=0000000000000000000000000000000000000000;hpb=9c5e457509ba5a1822c316635c6308874e61b4b9;p=osm%2FUI.git diff --git a/skyquake/plugins/launchpad/api/epa_aggregator.js b/skyquake/plugins/launchpad/api/epa_aggregator.js new file mode 100644 index 000000000..5577226f7 --- /dev/null +++ b/skyquake/plugins/launchpad/api/epa_aggregator.js @@ -0,0 +1,155 @@ +/* + * + * Copyright 2016 RIFT.IO Inc + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +var EpaSchema = { + "vswitch-epa": { + "objType": "container", + "ovs-offload": { + "objType": "leaf" + }, + "ovs-acceleration": { + "objType": "leaf" + } + }, + "hypervisor-epa": { + "objType": "container", + "type": { + "objType": "leaf" + }, + "version": { + "objType": "leaf" + } + }, + "host-epa": { + "objType": "container", + "cpu-model": { + "objType": "leaf" + }, + "cpu-arch": { + "objType": "leaf" + }, + "cpu-vendor": { + "objType": "leaf" + }, + "cpu-socket-count": { + "objType": "leaf" + }, + "cpu-core-count": { + "objType": "leaf" + }, + "cpu-feature": { + "objType": "leaf-list" + } + }, + "guest-epa": { + "objType": "container", + "mempage-size": { + "objType": "leaf" + }, + "trusted-execution": { + "objType": "leaf" + }, + "cpu-pinning-policy": { + "objType": "leaf" + }, + "cpu-thread-pinning-policy": { + "objType": "leaf" + }, + "pcie-device": { + "objType": "list" + }, + "numa-node-policy": { + "objType": "container", + "node": { + "objType": "list" + } + } + } +} + +module.exports = function aggregateEPA(vdur, data) { + var data = data || {}; + var schema = EpaSchema; + var findLeaf = function(obj, schema, data) { + for (k in obj) { + var epaSchema = schema[k]; + //if key exists in schema + if (epaSchema) { + if (!data[k]) { + data[k] = {}; + } + switch (epaSchema.objType) { + case 'container': + findLeaf(obj[k], epaSchema, data[k]); + break; + case 'leaf': + aggregateValue(obj[k].toString(), data[k]); + break; + case 'leaf-list': + aggregateLeafListValue(obj[k], data[k]); + break; + case 'list': + aggregateListValue(k, obj[k], data[k]); + break; + case 'choice': + aggregateChoiceValue(obj[k], data[k]); + break; + } + } + } + return data; + } + try { + vdur.map(function(vm) { + findLeaf(vm, schema, data) + }) + } + catch(e) { + + } + + return data; + + function aggregateChoiceValue(obj, data) { + for (k in obj) { + aggregateValue(k, data) + } + } + + function aggregateValue(value, data) { + value = value.toString(); + if (!data[value]) data[value] = {}; + var total = data[value]; + total.total = (!total.total) ? 1 : total.total + 1; + } + + function aggregateListValue(k, value, data) { + if (value.length > 0) { + aggregateValue(k, data); + } + } + + function aggregateLeafListValue(obj, data) { + if (obj.constructor.name == "Array") { + obj.map(function(p) { + aggregateValue(p, data); + }) + } else { + console.log("Oops, something went wrong here. An object was passed that wasn't an Array. Are you sure it was leaf-list?") + } + } +}