From: Ciro Scognamiglio Date: Fri, 8 Aug 2014 15:49:10 +0000 (+0200) Subject: fixes, activity monitor module X-Git-Tag: myslice-1.0~24 X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=commitdiff_plain;h=a8b4d52df438751ce078700eab547e84075e9420 fixes, activity monitor module --- diff --git a/rest/monitor.py b/rest/monitor.py new file mode 100644 index 00000000..ad110379 --- /dev/null +++ b/rest/monitor.py @@ -0,0 +1,53 @@ +from sfa.client.sfaserverproxy import SfaServerProxy +from sfa.client.return_value import ReturnValue +from django.http import HttpResponse +from rest import error +import os,json +import ConfigParser + +def sfaGetVersion(url): + cert = os.getcwd() + "/myslice/sfa.cert" + pkey = os.getcwd() + "/myslice/sfa.pkey" + + server = SfaServerProxy(url, pkey, cert) + try: + version = server.GetVersion() + except Exception, e: + return False + + return version + +def servicesStatus(request): + Config = ConfigParser.ConfigParser() + Config.read(os.getcwd() + "/myslice/monitor.ini") + + result = {} + + services = Config.sections() + for s in services : + if Config.has_option(s, 'url') : + result[s] = {} + + if Config.has_option(s, 'name') : + result[s]['name'] = Config.get(s, 'name') + + if Config.has_option(s, 'description') : + result[s]['description'] = Config.get(s, 'description') + + if Config.has_option(s, 'type') : + result[s]['type'] = Config.get(s, 'type') + + ret = sfaGetVersion(Config.get(s, 'url')) + + if ret : + result[s]['status'] = 'ok' + + if 'interface' in ret : # registry + result[s]['version'] = ret['sfa'] + else : + result[s]['version'] = ret['geni_api'] + else : + result[s]['status'] = 'ko' + + + return HttpResponse(json.dumps(result), content_type="application/json") \ No newline at end of file