Sapan Bhatia | 1ffb401 | 2015-01-07 01:09:02 -0500 | [diff] [blame] | 1 | from django.http import HttpResponse |
| 2 | from monitor import driver |
Sapan Bhatia | d123b52 | 2015-01-12 16:48:19 -0500 | [diff] [blame] | 3 | from core.models import * |
Sapan Bhatia | 1ffb401 | 2015-01-07 01:09:02 -0500 | [diff] [blame] | 4 | import json |
| 5 | |
| 6 | def Stats(request): |
| 7 | model = request.GET['model_name'] |
| 8 | pk = int(request.GET['pk']) |
Sapan Bhatia | c0d8a70 | 2015-01-10 04:51:57 +0000 | [diff] [blame] | 9 | meter = request.GET['meter'] |
| 10 | controller_name = request.GET['controller_name'] |
Sapan Bhatia | 1ffb401 | 2015-01-07 01:09:02 -0500 | [diff] [blame] | 11 | |
Scott Baker | 38ef1df | 2015-02-13 21:37:13 -0800 | [diff] [blame] | 12 | controller = Controller.objects.filter(name=controller_name) |
| 13 | |
| 14 | if len(controller)==0: |
Scott Baker | e2dfb10 | 2015-02-13 21:40:51 -0800 | [diff] [blame] | 15 | return HttpResponse(json.dumps({"stat_list": [], "error": "not found"})) |
Scott Baker | 38ef1df | 2015-02-13 21:37:13 -0800 | [diff] [blame] | 16 | |
| 17 | controller=controller[0] |
Sapan Bhatia | d123b52 | 2015-01-12 16:48:19 -0500 | [diff] [blame] | 18 | 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 Baker | 38ef1df | 2015-02-13 21:37:13 -0800 | [diff] [blame] | 22 | |
Sapan Bhatia | d123b52 | 2015-01-12 16:48:19 -0500 | [diff] [blame] | 23 | meters = driver.get_meter(meter, model, pk, keystone) |
Sapan Bhatia | c0d8a70 | 2015-01-10 04:51:57 +0000 | [diff] [blame] | 24 | return HttpResponse(json.dumps(meters)) |