Fix: conflict in rest api
[myslice.git] / rest / get.py
1 from manifold.core.query            import Query, AnalyzedQuery
2
3 from django.views.generic.base      import TemplateView
4
5 from unfold.loginrequired           import LoginRequiredView
6 from django.http                    import HttpResponse
7
8 from manifold.core.query            import Query, AnalyzedQuery
9 from manifoldapi.manifoldapi        import execute_query
10
11 import json
12
13 def platform(request, platform_name):
14     
15     platform_query  = Query().get('local:platform').filter_by('disabled', '==', '0').select('platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type')
16     response = execute_query(request,platform_query)
17     
18     response_data = {}
19     response_data['columns'] = [ 'platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type' ]
20     response_data['labels'] = [ 'Platform', 'Name', 'Url', 'Description','Gateway Type' ]
21     response_data['data'] = []
22     for r in response :
23         response_data['data'].append([ r['platform'], r['platform_longname'], r['platform_url'], r['platform_description'], r['gateway_type'] ])
24         
25     return HttpResponse(json.dumps(response_data), content_type="application/json")
26
27 def slice(request, slice_name):
28     
29     platform_query  = Query().get('local:platform').filter_by('disabled', '==', '0').select('platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type')
30     response = execute_query(request,platform_query)
31     
32
33     
34     response_data = {}
35     response_data['columns'] = [ 'platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type' ]
36     response_data['labels'] = [ 'Platform', 'Name', 'Url', 'Description','Gateway Type' ]
37     response_data['data'] = []
38     for r in response :
39         response_data['data'].append([ r['platform'], r['platform_longname'], r['platform_url'], r['platform_description'], r['gateway_type'] ])
40         
41     return HttpResponse(json.dumps(response_data), content_type="application/json")
42
43 #         slicename = 'ple.upmc.myslicedemo'
44 #         main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
45 #         main_query.select(
46 #                 'slice_hrn',
47 #                 'resource.hrn', 'resource.urn', 
48 #                 'resource.hostname', 'resource.type', 
49 #                 'resource.network_hrn',
50 #                 'lease.urn',
51 #                 'user.user_hrn',
52 #                 #'application.measurement_point.counter'
53 #         )
54 #          
55 #         res = execute_query(self.request,main_query)
56 #        
57 #         print res
58 #         
59 #         return render(request, self.template_name, {"resources": res[0]['resource']})
60     
61
62 #     def get (self, request, name='default'):
63 #         return HttpResponse()