X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=src%2Femuvim%2Fcli%2Frest%2Fmonitor.py;h=858aad7c3b6ba1e10f9eb362f701703fda31dc49;hb=566779d267065c78708112623f9c60afcb01696e;hp=88db8b23edc7abb4d4d1cd6de22f911672f4cf08;hpb=79ef6aee3dc52f49d1261e40ec5f258fb4372a1e;p=osm%2Fvim-emu.git diff --git a/src/emuvim/cli/rest/monitor.py b/src/emuvim/cli/rest/monitor.py index 88db8b2..858aad7 100755 --- a/src/emuvim/cli/rest/monitor.py +++ b/src/emuvim/cli/rest/monitor.py @@ -25,11 +25,10 @@ the Horizon 2020 and 5G-PPP programmes. The authors would like to acknowledge the contributions of their colleagues of the SONATA partner consortium (www.sonata-nfv.eu). """ + from requests import get, put, delete -from tabulate import tabulate import pprint import argparse -import json from emuvim.cli import prometheus pp = pprint.PrettyPrinter(indent=4) @@ -94,6 +93,23 @@ class RestApiClient(): pp.pprint(response.json()) + def prometheus(self, args): + # This functions makes it more user-friendly to create the correct prometheus query + # is replaced by the correct uuid of the deployed vnf container + vnf_name = self._parse_vnf_name(args.get("vnf_name")) + vnf_interface = self._parse_vnf_interface(args.get("vnf_name")) + dc_label = args.get("datacenter") + query = args.get("query") + vnf_status = get("%s/restapi/compute/%s/%s" % + (args.get("endpoint"), + args.get("datacenter"), + vnf_name)).json() + uuid = vnf_status['id'] + query = query.replace('', uuid) + + response = prometheus.query_Prometheus(query) + pp.pprint(response) + def _parse_vnf_name(self, vnf_name_str): vnf_name = vnf_name_str.split(':')[0] return vnf_name