blob: f0cdd74f98e251e3e16b1bbdac33d1dd080ad50a [file] [log] [blame]
Sapan Bhatia1ffb4012015-01-07 01:09:02 -05001from django.http import HttpResponse
2from monitor import driver
Sapan Bhatiad123b522015-01-12 16:48:19 -05003from core.models import *
Sapan Bhatia1ffb4012015-01-07 01:09:02 -05004import json
5
6def Stats(request):
7 model = request.GET['model_name']
8 pk = int(request.GET['pk'])
Sapan Bhatiac0d8a702015-01-10 04:51:57 +00009 meter = request.GET['meter']
10 controller_name = request.GET['controller_name']
Sapan Bhatia1ffb4012015-01-07 01:09:02 -050011
Scott Baker38ef1df2015-02-13 21:37:13 -080012 controller = Controller.objects.filter(name=controller_name)
13
14 if len(controller)==0:
Scott Bakere2dfb102015-02-13 21:40:51 -080015 return HttpResponse(json.dumps({"stat_list": [], "error": "not found"}))
Scott Baker38ef1df2015-02-13 21:37:13 -080016
17 controller=controller[0]
Sapan Bhatiad123b522015-01-12 16:48:19 -050018 keystone = {'username':controller.admin_user, 'password':controller.admin_password, 'tenant_name':controller.admin_tenant, 'auth_url':controller.auth_url, 'cacert':'/etc/ssl/certs/ca-certificates.crt'}
19
20 for k,v in keystone.items():
21 keystone['os_'+k] = v
Scott Baker38ef1df2015-02-13 21:37:13 -080022
Sapan Bhatiad123b522015-01-12 16:48:19 -050023 meters = driver.get_meter(meter, model, pk, keystone)
Sapan Bhatiac0d8a702015-01-10 04:51:57 +000024 return HttpResponse(json.dumps(meters))