X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Ftools%2Fpapi%2Fvpp_papi_provider.py;h=ded3c3069e14c8c835e83a4ae4eafb3259b1741c;hp=ee0d538fba47fea4aa8d939d1c05d39cf115c7cb;hb=3c863def2096b573832499985e3a12bbccf82ea8;hpb=287ef8c6dc057220e403a1493cb23450dd8db2b2;ds=sidebyside diff --git a/resources/tools/papi/vpp_papi_provider.py b/resources/tools/papi/vpp_papi_provider.py index ee0d538fba..ded3c3069e 100755 --- a/resources/tools/papi/vpp_papi_provider.py +++ b/resources/tools/papi/vpp_papi_provider.py @@ -214,6 +214,33 @@ def process_stats(args): reply=reply, exc=repr(err))) +def process_stats_request(args): + """Process the VPP Stats requests. + + :param args: Command line arguments passed to VPP PAPI Provider. + :type args: ArgumentParser + :returns: JSON formatted string. + :rtype: str + :raises RuntimeError: If PAPI command error occurs. + """ + + try: + stats = VPPStats(args.socket) + except Exception as err: + raise RuntimeError('PAPI init failed:\n{err}'.format(err=repr(err))) + + try: + json_data = json.loads(args.data) + except ValueError as err: + raise RuntimeError('Input json string is invalid:\n{err}'. + format(err=repr(err))) + + papi_fn = getattr(stats, json_data["api_name"]) + reply = papi_fn(**json_data.get("api_args", {})) + + return json.dumps(reply) + + def main(): """Main function for the Python API provider. """ @@ -222,7 +249,8 @@ def main(): process_request = dict( request=process_json_request, dump=process_json_request, - stats=process_stats + stats=process_stats, + stats_request=process_stats_request ) parser = argparse.ArgumentParser(