1 from sfa.client.sfaserverproxy import SfaServerProxy
2 from sfa.client.return_value import ReturnValue
3 from django.http import HttpResponse
8 def servicesStatus(request):
9 Config = ConfigParser.ConfigParser()
10 Config.read(os.getcwd() + "/myslice/monitor.ini")
14 if not Config.has_option('monitor', 'cert') :
15 return HttpResponse(json.dumps({'error' : '-1'}), content_type="application/json")
17 cert = os.path.abspath(Config.get('monitor', 'cert'))
18 if not os.path.isfile(cert) :
19 return HttpResponse(json.dumps({'error' : '-1'}), content_type="application/json")
22 if not Config.has_option('monitor', 'pkey') :
23 return HttpResponse(json.dumps({'error' : '-2'}), content_type="application/json")
25 pkey = os.path.abspath(Config.get('monitor', 'pkey'))
26 if not os.path.isfile(pkey) :
27 return HttpResponse(json.dumps({'error' : '-2'}), content_type="application/json")
29 services = Config.sections()
35 if Config.has_option(s, 'url') :
38 if Config.has_option(s, 'name') :
39 result[s]['name'] = Config.get(s, 'name')
41 if Config.has_option(s, 'description') :
42 result[s]['description'] = Config.get(s, 'description')
44 if Config.has_option(s, 'type') :
45 result[s]['type'] = Config.get(s, 'type')
47 server = SfaServerProxy(Config.get(s, 'url'), pkey, cert)
49 version = server.GetVersion()
51 result[s]['status'] = 'ok'
53 if 'interface' in version : # registry
54 result[s]['version'] = version['sfa']
56 result[s]['version'] = version['geni_api']
59 result[s]['status'] = 'ko'
62 return HttpResponse(json.dumps(result), content_type="application/json")