AiC and REST login
[myslice.git] / portal / univbrisview.py
1 import json
2 from manifold.core.query         import Query
3 from manifoldapi.manifoldapi        import execute_query
4
5 from unfold.page                 import Page
6
7 from plugins.lists.testbedlist   import TestbedList
8 from plugins.lists.slicelist     import SliceList
9
10 from unfold.loginrequired       import FreeAccessView
11 from unfold.loginrequired        import LoginRequiredAutoLogoutView
12
13 from ui.topmenu                  import topmenu_items_live, the_user
14 from plugins.querytable          import QueryTable
15 from plugins.univbrisfoam        import UnivbrisFoam
16 from plugins.univbrisfv          import UnivbrisFv
17 from plugins.lists.staticlist    import StaticList
18 from plugins.lists.slicelist     import SliceList
19 from plugins.messages           import Messages
20 from plugins.univbrisfvf        import UnivbrisFvf
21 from plugins.univbrisfvfo       import UnivbrisFvfo
22 from plugins.univbris           import Univbris
23 from plugins.univbristopo       import UnivbrisTopo
24
25 #This view requires login 
26 class UnivbrisView (LoginRequiredAutoLogoutView):
27 #class UnivbrisView (FreeAccessView):
28     template_name = "univbris.html"
29     
30     def get_context_data(self, **kwargs):
31         
32         page = Page(self.request)
33         metadata = page.get_metadata()
34         page.expose_js_metadata()
35     
36         resource_md = metadata.details_by_object('resource')
37         resource_fields = [column['name'] for column in resource_md['column']]
38     
39         user_md = metadata.details_by_object('user')
40         user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']]
41     
42     
43         #create new query to manifold----query is not called yet
44         #need to modify to get i2cat of resources also
45         univbrisfoam_query=Query().get('ofelia-bristol-of:resource').select('urn')
46         #print univbrisfoam_query #.select('urn')
47         #Query().get('ofelia-bristol-of:resource')
48         ##custom query to communication between univbris plugins
49         #univbris_query=Query()
50             
51         #queue the query
52         page.enqueue_query(univbrisfoam_query)
53         #page.enqueue_query(univbris_query)
54         page.expose_js_metadata()
55     
56     
57         #plugin which display a "gathering resources" message waiting for all resources to be returned by manifold
58         univbriswelcome = Univbris(
59             page  = page,
60             title = 'univbris_welcome',
61             domid = 'univbris_welcome',
62             query = univbrisfoam_query,
63         )
64         
65         #plugin which collects different openflow ports from maniford
66         univbrisfoamlist = UnivbrisFoam(
67             page  = page,
68             title = 'univbris_foam_ports_selection',
69             domid = 'univbris_foam_ports_selection',
70             query = univbrisfoam_query,
71             query_all = univbrisfoam_query,
72             sync_query= univbrisfoam_query,
73             checkboxes = False,
74             datatables_options = { 
75                 'iDisplayLength': 10,
76                 'bLengthChange' : True,
77                 'bAutoWidth'    : True,
78                 },
79         )
80     
81         #plugin which manages the different flowspaces that the user creates, and also sends flowspaces to manifold
82         univbrisfvlist = UnivbrisFv(
83             page  = page,
84             title = 'univbris_flowspace_selection',
85             domid = 'univbris_flowspace_selection',
86             query = None,
87             query_all = None,
88             sync_query= univbrisfoam_query,
89             datatables_options = { 
90                 'iDisplayLength': 5,
91                 'bLengthChange' : True,
92                 'bAutoWidth'    : True,
93                 },
94         )
95     
96         #plugin which allows the definition the match criteria on a single PACKET flowspace
97         univbrisfvform = UnivbrisFvf(
98             page  = page,
99             title = 'univbris_flowspace_form',
100             domid = 'univbris_flowspace_form',
101             query = None,
102             query_all = None,
103             datatables_options = { 
104                 'iDisplayLength': 3,
105                 'bLengthChange' : True,
106                 'bAutoWidth'    : True,
107                 },
108         )
109     
110         #plugin which allows the definition the match criteria on a single OPTICAL flowspace
111     
112         univbrisofvform = UnivbrisFvfo(
113                 page  = page,
114                 title = 'univbris_oflowspace_form',
115                 domid = 'univbris_oflowspace_form',
116                 query = None,
117                 query_all = None,
118                 datatables_options = { 
119                     'iDisplayLength': 3,
120                     'bLengthChange' : True,
121                     'bAutoWidth'    : True,
122                     },
123             )
124     
125     
126         #plugin which display the gathered topology
127         univbristopology = UnivbrisTopo(
128                 page  = page,
129                 title = 'univbris_topology',
130                 domid = 'univbris_topology',
131                 query = univbrisfoam_query,
132             )
133         
134         #render plugins in each context within a single page, but not all plugins are visible at all time.
135         context = super(UnivbrisView, self).get_context_data(**kwargs)
136         context['person']   = self.request.user
137         context['welcome'] = univbriswelcome.render(self.request)
138         context['resources'] = univbrisfoamlist.render(self.request)
139         context['flowspaces']= univbrisfvlist.render(self.request)
140         context['oflowspaces_form']= univbrisofvform.render(self.request)
141         context['flowspaces_form']= univbrisfvform.render(self.request)
142         context['topology']=univbristopology.render(self.request)
143     
144         # XXX This is repeated in all pages
145         # more general variables expected in the template
146         context['title'] = 'Book OpenFlow resources'
147         # the menu items on the top
148         context['topmenu_items'] = topmenu_items_live('univbris', page)
149         # so we can sho who is logged
150         context['username'] = the_user(self.request)
151         
152         context.update(page.prelude_env())
153         page.expose_js_metadata()
154         
155         
156         # the page header and other stuff
157         context.update(page.prelude_env())
158         
159         context['layout_1_or_2']="layout-unfold2.html" if not context['username'] else "layout-unfold1.html"
160         
161         return context