def get(self, request, authority_hrn=None, state=None): env = self.default_env() if request.user.is_authenticated(): env['person'] = self.request.user if authority_hrn is None: # CACHE PB with fields page = Page(request) metadata = page.get_metadata() user_md = metadata.details_by_object('user') user_fields = [column['name'] for column in user_md['column']] # REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2 user_query = Query().get('myslice:user').select( user_fields).filter_by('user_hrn', '==', '$user_hrn') #user_query = Query().get('myslice:user').select('user_hrn','parent_authority').filter_by('user_hrn','==','$user_hrn') user_details = execute_query(self.request, user_query) try: env['user_details'] = user_details[0] except Exception, e: # If the Query fails, check in local DB try: user_local_query = Query().get('local:user').select( 'config').filter_by('email', '==', str(env['person'])) user_local_details = execute_query( self.request, user_local_query) user_local = user_local_details[0] user_local_config = user_local['config'] user_local_config = json.loads(user_local_config) user_local_authority = user_local_config.get( 'authority') if 'user_details' not in env or 'parent_authority' not in env[ 'user_details'] or env['user_details'][ 'parent_authority'] is None: env['user_details'] = { 'parent_authority': user_local_authority } except Exception, e: env['error'] = "Please check your Credentials"
def get (self, request, slicename='ple.inria.f14'): page=Page(request) page.expose_js_metadata() metadata = page.get_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename) main_query.select( 'slice_hrn', #'resource.hrn', 'resource.hostname', 'resource.type', 'resource.network_hrn', 'lease.urn', 'user.user_hrn', #'application.measurement_point.counter' ) # for internal use in the querygrid plugin; # needs to be a unique column present for each returned record main_query_init_key = 'hostname' query_resource_all = Query.get('resource').select(resource_fields) aq = AnalyzedQuery(main_query, metadata=metadata) page.enqueue_query(main_query, analyzed_query=aq) page.enqueue_query(query_resource_all) sq_resource = aq.subquery('resource') resources_as_list = QueryGrid( page = page, domid = 'resources-list', title = 'List view', # this is the query at the core of the slice list query = sq_resource, query_all = query_resource_all, # safer to use 'hrn' as the internal unique key for this plugin init_key = main_query_init_key, checkboxes = True, datatables_options = { 'iDisplayLength': 25, 'bLengthChange' : True, 'bAutoWidth' : True, }, ) # variables that will get passed to the view-unfold1.html template template_env = {} # define 'unfold_main' to the template engine - the main contents template_env [ 'unfold_main' ] = resources_as_list.render(request) # more general variables expected in the template template_env [ 'title' ] = 'simple %(slicename)s'%locals() # the menu items on the top template_env [ 'topmenu_items' ] = topmenu_items_live('Slice', page) # so we can sho who is logged template_env [ 'username' ] = the_user (request) # the prelude object in page contains a summary of the requirements() for all plugins # define {js,css}_{files,chunks} prelude_env = page.prelude_env() template_env.update(prelude_env) result=render_to_response ('view-unfold1.html',template_env, context_instance=RequestContext(request)) return result
def get_context_data(self, **kwargs): page = Page(self.request) page.add_js_files(["js/common.functions.js"]) for key, value in kwargs.iteritems(): logger.debug("{} = {}".format(key, value)) if key == "platformname": platformname = value network_query = Query().get('local:platform')\ .filter_by('platform', '==', platformname)\ .select('platform','platform_longname','gateway_type') page.enqueue_query(network_query) # ListResources of the platform metadata = page.get_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] resources = platformname + ':resource' query_resource_all = Query.get(resources).select(resource_fields) page.enqueue_query(query_resource_all) query_resource_default_fields = Query.get(resources).select( 'hrn', 'hostname', 'type', 'country') page.enqueue_query(query_resource_default_fields) page.expose_js_metadata() networklist = QueryTable( page=page, title='List', domid='checkboxes', # this is the query at the core of the slice list query=network_query, query_all=network_query, checkboxes=False, datatables_options={ 'iDisplayLength': 25, 'bLengthChange': True, }, ) # networklist = SimpleList( # title = None, # page = page, # key = 'platform', # query = network_query, # ) # # -------------------------------------------------------------------------- # RESOURCES # for internal use in the querytable plugin; # needs to be a unique column present for each returned record main_query_init_key = 'hrn' # the resources part is made of a Tabs (Geographic, List), resources_as_gmap = GoogleMap( page=page, title='Geographic view', domid='resources-map', # tab's sons preferably turn this off togglable=False, query=query_resource_default_fields, query_all=query_resource_all, # this key is the one issued by google googlemap_api_key=ConfigEngine().googlemap_api_key(), # the key to use at init-time init_key=main_query_init_key, checkboxes=False, # center on Paris latitude=49., longitude=9, zoom=4, ) resources_as_3dmap = SensLabMap( page=page, title='3D Map', domid='senslabmap', query=query_resource_default_fields, query_all=query_resource_all, ) resources_as_list = QueryTable( page=page, domid='resources-list', title='List view', # this is the query at the core of the slice list query=query_resource_default_fields, query_all=query_resource_all, init_key=main_query_init_key, checkboxes=False, datatables_options={ 'iDisplayLength': 25, 'bLengthChange': True, 'bAutoWidth': True, }, ) resources_sons = [ resources_as_gmap, resources_as_3dmap, resources_as_list, ] resources_area = Tabs( page=page, domid="resources", togglable=True, title="Resources", outline_complete=True, sons=resources_sons, active_domid='resources-map', persistent_active=True, ) context = super(PlatformView, self).get_context_data(**kwargs) context['person'] = self.request.user context['networks'] = networklist.render(self.request) context['resources'] = resources_area.render(self.request) # XXX This is repeated in all pages # more general variables expected in the template context['title'] = 'Platforms connected to MySlice' # the menu items on the top context['topmenu_items'] = topmenu_items_live('Platforms', page) # so we can sho who is logged context['username'] = the_user(self.request) context['theme'] = self.theme context.update(page.prelude_env()) return context
def get_context_data(self, **kwargs): page = Page(self.request) metadata = page.get_metadata() page.expose_js_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] user_md = metadata.details_by_object('user') user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']] #create new query to manifold----query is not called yet #need to modify to get i2cat of resources also univbrisfoam_query=Query().get('ofelia-bristol-of:resource').select('urn') #print univbrisfoam_query #.select('urn') #Query().get('ofelia-bristol-of:resource') ##custom query to communication between univbris plugins #univbris_query=Query() #queue the query page.enqueue_query(univbrisfoam_query) #page.enqueue_query(univbris_query) page.expose_js_metadata() #plugin which display a "gathering resources" message waiting for all resources to be returned by manifold univbriswelcome = Univbris( page = page, title = 'univbris_welcome', domid = 'univbris_welcome', query = univbrisfoam_query, ) #plugin which collects different openflow ports from maniford univbrisfoamlist = UnivbrisFoam( page = page, title = 'univbris_foam_ports_selection', domid = 'univbris_foam_ports_selection', query = univbrisfoam_query, query_all = univbrisfoam_query, sync_query= univbrisfoam_query, checkboxes = False, datatables_options = { 'iDisplayLength': 10, 'bLengthChange' : True, 'bAutoWidth' : True, }, ) #plugin which manages the different flowspaces that the user creates, and also sends flowspaces to manifold univbrisfvlist = UnivbrisFv( page = page, title = 'univbris_flowspace_selection', domid = 'univbris_flowspace_selection', query = None, query_all = None, sync_query= univbrisfoam_query, datatables_options = { 'iDisplayLength': 5, 'bLengthChange' : True, 'bAutoWidth' : True, }, ) #plugin which allows the definition the match criteria on a single PACKET flowspace univbrisfvform = UnivbrisFvf( page = page, title = 'univbris_flowspace_form', domid = 'univbris_flowspace_form', query = None, query_all = None, datatables_options = { 'iDisplayLength': 3, 'bLengthChange' : True, 'bAutoWidth' : True, }, ) #plugin which allows the definition the match criteria on a single OPTICAL flowspace univbrisofvform = UnivbrisFvfo( page = page, title = 'univbris_oflowspace_form', domid = 'univbris_oflowspace_form', query = None, query_all = None, datatables_options = { 'iDisplayLength': 3, 'bLengthChange' : True, 'bAutoWidth' : True, }, ) #plugin which display the gathered topology univbristopology = UnivbrisTopo( page = page, title = 'univbris_topology', domid = 'univbris_topology', query = univbrisfoam_query, ) #render plugins in each context within a single page, but not all plugins are visible at all time. context = super(UnivbrisView, self).get_context_data(**kwargs) context['person'] = self.request.user context['welcome'] = univbriswelcome.render(self.request) context['resources'] = univbrisfoamlist.render(self.request) context['flowspaces']= univbrisfvlist.render(self.request) context['oflowspaces_form']= univbrisofvform.render(self.request) context['flowspaces_form']= univbrisfvform.render(self.request) context['topology']=univbristopology.render(self.request) # XXX This is repeated in all pages # more general variables expected in the template context['title'] = 'Book OpenFlow resources' # the menu items on the top context['topmenu_items'] = topmenu_items_live('univbris', page) # so we can sho who is logged context['username'] = the_user(self.request) context.update(page.prelude_env()) page.expose_js_metadata() # the page header and other stuff context.update(page.prelude_env()) context['layout_1_or_2']="layout-unfold2.html" if not context['username'] else "layout-unfold1.html" return context
def get_context_data(self, **kwargs): page = Page(self.request) page.add_js_files ( [ "js/common.functions.js" ] ) for key, value in kwargs.iteritems(): print "%s = %s" % (key, value) if key == "platformname": platformname=value network_query = Query().get('local:platform')\ .filter_by('platform', '==', platformname)\ .select('platform','platform_longname','gateway_type') page.enqueue_query(network_query) # ListResources of the platform metadata = page.get_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] resources = platformname + ':resource' query_resource_all = Query.get(resources).select(resource_fields) page.enqueue_query(query_resource_all) query_resource_default_fields = Query.get(resources).select('hrn','hostname', 'type','country') page.enqueue_query(query_resource_default_fields) page.expose_js_metadata() networklist = QueryTable( page = page, title = 'List', domid = 'checkboxes', # this is the query at the core of the slice list query = network_query, query_all = network_query, checkboxes = False, datatables_options = { 'iDisplayLength' : 25, 'bLengthChange' : True, }, ) # networklist = SimpleList( # title = None, # page = page, # key = 'platform', # query = network_query, # ) # # -------------------------------------------------------------------------- # RESOURCES # for internal use in the querytable plugin; # needs to be a unique column present for each returned record main_query_init_key = 'hrn' # the resources part is made of a Tabs (Geographic, List), resources_as_gmap = GoogleMap( page = page, title = 'Geographic view', domid = 'resources-map', # tab's sons preferably turn this off togglable = False, query = query_resource_default_fields, query_all = query_resource_all, # this key is the one issued by google googlemap_api_key = ConfigEngine().googlemap_api_key(), # the key to use at init-time init_key = main_query_init_key, checkboxes = False, # center on Paris latitude = 49., longitude = 9, zoom = 4, ) resources_as_3dmap = SensLabMap( page = page, title = '3D Map', domid = 'senslabmap', query = query_resource_default_fields, query_all = query_resource_all, ) resources_as_list = QueryTable( page = page, domid = 'resources-list', title = 'List view', # this is the query at the core of the slice list query = query_resource_default_fields, query_all = query_resource_all, init_key = main_query_init_key, checkboxes = False, datatables_options = { 'iDisplayLength': 25, 'bLengthChange' : True, 'bAutoWidth' : True, }, ) resources_sons = [ resources_as_gmap, resources_as_3dmap, resources_as_list, ] resources_area = Tabs ( page=page, domid="resources", togglable=True, title="Resources", outline_complete=True, sons= resources_sons, active_domid = 'resources-map', persistent_active=True, ) context = super(PlatformView, self).get_context_data(**kwargs) context['person'] = self.request.user context['networks'] = networklist.render(self.request) context['resources'] = resources_area.render(self.request) # XXX This is repeated in all pages # more general variables expected in the template context['title'] = 'Platforms connected to MySlice' # the menu items on the top context['topmenu_items'] = topmenu_items_live('Platforms', page) # so we can sho who is logged context['username'] = the_user(self.request) context.update(page.prelude_env()) return context
def get (self,request, slicename=tmp_default_slice): page = Page(request) page.add_css_files ('css/slice-view.css') page.add_js_files ( [ "js/common.functions.js" ] ) page.add_js_chunks ('$(function() { messages.debug("sliceview: jQuery version " + $.fn.jquery); });') page.add_js_chunks ('$(function() { messages.debug("sliceview: users turned %s"); });'%("on" if do_query_users else "off")) page.add_js_chunks ('$(function() { messages.debug("sliceview: leases turned %s"); });'%("on" if do_query_leases else "off")) page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(ConfigEngine().manifold_url())) metadata = page.get_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] user_md = metadata.details_by_object('user') user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']] # TODO The query to run is embedded in the URL main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename) main_query.select( 'slice_hrn', #'resource.hrn', 'resource.urn', 'resource.hostname', 'resource.type', 'resource.network_hrn', 'lease.urn', 'user.user_hrn', #'application.measurement_point.counter' ) # for internal use in the querytable plugin; # needs to be a unique column present for each returned record main_query_init_key = 'hostname' query_resource_all = Query.get('resource').select(resource_fields) aq = AnalyzedQuery(main_query, metadata=metadata) page.enqueue_query(main_query, analyzed_query=aq) page.enqueue_query(query_resource_all) if do_query_users: # Required: the user must have an authority in its user.config # XXX Temporary solution user_query = Query().get('local:user').select('config','email') user_details = execute_query(self.request, user_query) # not always found in user_details... config={} # for user_detail in user_details: # #email = user_detail['email'] # if user_detail['config']: # config = json.loads(user_detail['config']) # user_detail['authority'] = config.get('authority',"Unknown Authority") # # if user_detail['authority'] is not None: # sub_authority = user_detail['authority'].split('.') # root_authority = sub_authority[0] # query_user_all = Query.get(root_authority+':user').select(user_fields) # # # XXX TODO this filter doesn't work - to be improved in Manifold # #.filter_by('authority.authority_hrn', '=', user_detail['authority']) # # page.enqueue_query(query_user_all) # else: # print "authority of the user is not in local:user db" query_user_all = Query.get('user').select(user_fields) # query_user_all = None # ... and for the relations # XXX Let's hardcode resources for now sq_resource = aq.subquery('resource') sq_user = aq.subquery('user') sq_lease = aq.subquery('lease') sq_measurement = aq.subquery('measurement') # Prepare the display according to all metadata # (some parts will be pending, others can be triggered by users). # # For example slice measurements will not be requested by default... # Create the base layout (Stack)... main_stack = Stack ( page=page, title="Slice %s"%slicename, sons=[], ) # ... responsible for the slice properties... # a nice header main_stack.insert ( Raw (page=page, togglable=False, toggled=True, html="<h2 class='well well-lg'> Slice %s</h2>"%slicename) ) # -------------------------------------------------------------------------- # QueryUpdater (Pending Operations) main_stack.insert(QueryUpdater( page = page, title = 'Pending operations', query = main_query, togglable = True, # start turned off, it will open up itself when stuff comes in toggled = False, domid = 'pending', outline_complete = True, )) # -------------------------------------------------------------------------- # Filter Resources # turn off for now -- see above filter_query_editor = QueryEditor( page = page, query = sq_resource, query_all = query_resource_all, title = "Select Columns", domid = 'select-columns', ) filter_active_filters = ActiveFilters( page = page, query = sq_resource, title = "Active Filters", ) filters_area = Stack( page = page, title = 'Filter Resources', domid = 'filters', sons = [filter_query_editor, filter_active_filters], togglable = True, toggled = 'persistent', outline_complete = True, ) main_stack.insert (filters_area) # -------------------------------------------------------------------------- # RESOURCES # the resources part is made of a Tabs (Geographic, List), resources_as_gmap = GoogleMap( page = page, title = 'Geographic view', domid = 'resources-map', # tab's sons preferably turn this off togglable = False, query = sq_resource, query_all = query_resource_all, # this key is the one issued by google googlemap_api_key = ConfigEngine().googlemap_api_key(), # the key to use at init-time init_key = main_query_init_key, checkboxes = True, # center on Paris latitude = 49., longitude = 9, zoom = 4, ) resources_as_3dmap = SensLabMap( page = page, title = '3D Map', domid = 'senslabmap', query = sq_resource, query_all = query_resource_all, ) resources_as_list = QueryTable( page = page, domid = 'resources-list', title = 'List view', # this is the query at the core of the slice list query = sq_resource, query_all = query_resource_all, init_key = main_query_init_key, checkboxes = True, datatables_options = { 'iDisplayLength': 25, 'bLengthChange' : True, 'bAutoWidth' : True, }, ) if insert_grid: resources_as_grid = QueryGrid( page = page, domid = 'resources-grid', title = 'Grid view', # this is the query at the core of the slice list query = sq_resource, query_all = query_resource_all, init_key = main_query_init_key, checkboxes = True, ) #if do_query_leases: # resources_as_scheduler = Scheduler( # page = page, # title = 'Scheduler', # domid = 'scheduler', # query = sq_resource, # query_all_resources = query_resource_all, # query_lease = sq_lease, # ) resources_as_scheduler2 = Scheduler2( page = page, domid = 'scheduler', title = 'Scheduler', # this is the query at the core of the slice list query = sq_resource, query_all_resources = query_resource_all, query_lease = sq_lease, ) # with the new 'Filter' stuff on top, no need for anything but the querytable resources_as_list_area = resources_as_list resources_sons = [ resources_as_gmap, resources_as_3dmap, resources_as_scheduler2, resources_as_list_area, ] if do_query_leases else [ resources_as_gmap, resources_as_3dmap, resources_as_list_area, resources_as_scheduler2, ] if insert_grid: resources_sons.append(resources_as_grid) resources_area = Tabs ( page=page, domid="resources", togglable=True, title="Resources", outline_complete=True, sons= resources_sons, active_domid = 'scheduler', persistent_active=True, ) main_stack.insert (resources_area) # -------------------------------------------------------------------------- # USERS if do_query_users and query_user_all is not None: tab_users = Tabs( page = page, domid = 'users', outline_complete = True, togglable = True, title = 'Users', active_domid = 'users-list', ) main_stack.insert(tab_users) tab_users.insert(QueryTable( page = page, title = 'Users List', domid = 'users-list', # tab's sons preferably turn this off togglable = False, # this is the query at the core of the slice list query = sq_user, query_all = query_user_all, checkboxes = True, datatables_options = { 'iDisplayLength' : 25, 'bLengthChange' : True, 'bAutoWidth' : True, }, )) # DEMO # -------------------------------------------------------------------------- # MEASUREMENTS measurements_stats_cpu = SliceStat( title = "CPU Usage", domid = 'resources-stats-cpu', page = page, stats = 'slice', key = 'hrn', query = 'none', slicename = slicename, o = 'cpu' ) measurements_stats_mem = SliceStat( title = "Memory Usage", domid = 'resources-stats-mem', page = page, stats = 'slice', key = 'hrn', query = 'none', slicename = slicename, o = 'mem' ) measurements_stats_asb = SliceStat( title = "Traffic Sent", domid = 'resources-stats-asb', page = page, stats = 'slice', key = 'hrn', query = 'none', slicename = slicename, o = 'asb' ) measurements_stats_arb = SliceStat( title = "Traffic Received", domid = 'resources-stats-arb', page = page, stats = 'slice', key = 'hrn', query = 'none', slicename = slicename, o = 'arb' ) tab_measurements = Tabs ( page=page, domid = "measurements", togglable = True, toggled = 'persistent', title = "Measurements", outline_complete=True, sons = [ measurements_stats_cpu, measurements_stats_mem, measurements_stats_asb, measurements_stats_arb ], active_domid = 'resources-stats-cpu', persistent_active = True, ) main_stack.insert (tab_measurements) # tab_measurements = Tabs ( # page = page, # active_domid = 'measurements-list', # outline_complete = True, # togglable = True, # title = 'Measurements', # domid = 'measurements', # ) # main_stack.insert(tab_measurements) # # tab_measurements.insert(QueryTable( # page = page, # title = 'Measurements', # domid = 'measurements-list', # # tab's sons preferably turn this off # togglable = False, # # this is the query at the core of the slice list # query = sq_measurement, # # do NOT set checkboxes to False # # this table being otherwise empty, it just does not fly with dataTables # checkboxes = True, # datatables_options = { # 'iDisplayLength' : 25, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, # )) # # # -------------------------------------------------------------------------- # # MESSAGES (we use transient=False for now) if insert_messages: main_stack.insert(Messages( page = page, title = "Runtime messages for slice %s"%slicename, domid = "msgs-pre", levels = "ALL", # plain messages are probably less nice for production but more reliable for development for now transient = False, # these make sense only in non-transient mode.. togglable = True, toggled = 'persistent', outline_complete = True, )) # variables that will get passed to the view-unfold1.html template template_env = {} # define 'unfold_main' to the template engine - the main contents template_env [ 'unfold_main' ] = main_stack.render(request) # more general variables expected in the template template_env [ 'title' ] = '%(slicename)s'%locals() # the menu items on the top template_env [ 'topmenu_items' ] = topmenu_items_live('Slice', page) # so we can sho who is logged template_env [ 'username' ] = the_user (request) # don't forget to run the requests page.expose_js_metadata() # the prelude object in page contains a summary of the requirements() for all plugins # define {js,css}_{files,chunks} template_env.update(page.prelude_env()) return render_to_response ('view-unfold1.html',template_env, context_instance=RequestContext(request))
def get(self, request, slicename=tmp_default_slice): page = Page(request) page.add_css_files('css/slice-view.css') page.add_js_files(["js/common.functions.js"]) page.add_js_chunks( '$(function() { messages.debug("sliceview: jQuery version " + $.fn.jquery); });' ) page.add_js_chunks( '$(function() { messages.debug("sliceview: users turned %s"); });' % ("on" if do_query_users else "off")) page.add_js_chunks( '$(function() { messages.debug("sliceview: leases turned %s"); });' % ("on" if do_query_leases else "off")) page.add_js_chunks( '$(function() { messages.debug("manifold URL %s"); });' % (ConfigEngine().manifold_url())) metadata = page.get_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] user_md = metadata.details_by_object('user') user_fields = ['user_hrn' ] # [column['name'] for column in user_md['column']] # TODO The query to run is embedded in the URL main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename) main_query.select( 'slice_hrn', #'resource.hrn', 'resource.urn', 'resource.hostname', 'resource.type', 'resource.network_hrn', 'lease.urn', 'user.user_hrn', #'application.measurement_point.counter' ) # for internal use in the querytable plugin; # needs to be a unique column present for each returned record main_query_init_key = 'hostname' query_resource_all = Query.get('resource').select(resource_fields) aq = AnalyzedQuery(main_query, metadata=metadata) page.enqueue_query(main_query, analyzed_query=aq) page.enqueue_query(query_resource_all) if do_query_users: # Required: the user must have an authority in its user.config # XXX Temporary solution user_query = Query().get('local:user').select('config', 'email') user_details = execute_query(self.request, user_query) # not always found in user_details... config = {} # for user_detail in user_details: # #email = user_detail['email'] # if user_detail['config']: # config = json.loads(user_detail['config']) # user_detail['authority'] = config.get('authority',"Unknown Authority") # # if user_detail['authority'] is not None: # sub_authority = user_detail['authority'].split('.') # root_authority = sub_authority[0] # query_user_all = Query.get(root_authority+':user').select(user_fields) # # # XXX TODO this filter doesn't work - to be improved in Manifold # #.filter_by('authority.authority_hrn', '=', user_detail['authority']) # # page.enqueue_query(query_user_all) # else: # print "authority of the user is not in local:user db" query_user_all = Query.get('user').select(user_fields) # query_user_all = None # ... and for the relations # XXX Let's hardcode resources for now sq_resource = aq.subquery('resource') sq_user = aq.subquery('user') sq_lease = aq.subquery('lease') sq_measurement = aq.subquery('measurement') # Prepare the display according to all metadata # (some parts will be pending, others can be triggered by users). # # For example slice measurements will not be requested by default... # Create the base layout (Stack)... main_stack = Stack( page=page, title="Slice %s" % slicename, sons=[], ) # ... responsible for the slice properties... # a nice header main_stack.insert( Raw(page=page, togglable=False, toggled=True, html="<h2 class='well well-lg'> Slice %s</h2>" % slicename)) # -------------------------------------------------------------------------- #DEPRECATED| # QueryUpdater (Pending Operations) #DEPRECATED| #DEPRECATED| main_stack.insert(QueryUpdater( #DEPRECATED| page = page, #DEPRECATED| title = 'Pending operations', #DEPRECATED| query = main_query, #DEPRECATED| togglable = True, #DEPRECATED| # start turned off, it will open up itself when stuff comes in #DEPRECATED| toggled = False, #DEPRECATED| domid = 'pending', #DEPRECATED| outline_complete = True, #DEPRECATED| )) # -------------------------------------------------------------------------- # Filter Resources # turn off for now -- see above filter_query_editor = QueryEditor( page=page, query=sq_resource, query_all=query_resource_all, title="Select Columns", domid='select-columns', ) filter_active_filters = ActiveFilters( page=page, query=sq_resource, title="Active Filters", ) filters_area = Stack( page=page, title='Filter Resources', domid='filters', sons=[filter_query_editor, filter_active_filters], togglable=True, toggled='persistent', outline_complete=True, ) main_stack.insert(filters_area) # -------------------------------------------------------------------------- # RESOURCES # the resources part is made of a Tabs (Geographic, List), resources_as_gmap = GoogleMap( page=page, title='Geographic view', domid='resources-map', # tab's sons preferably turn this off togglable=False, query=sq_resource, query_all=query_resource_all, # this key is the one issued by google googlemap_api_key=ConfigEngine().googlemap_api_key(), # the key to use at init-time init_key=main_query_init_key, checkboxes=True, # center on Paris latitude=49., longitude=9, zoom=4, ) resources_as_3dmap = SensLabMap( page=page, title='3D Map', domid='senslabmap', query=sq_resource, query_all=query_resource_all, ) resources_as_list = QueryTable( page=page, domid='resources-list', title='List view', # this is the query at the core of the slice list query=sq_resource, query_all=query_resource_all, init_key=main_query_init_key, checkboxes=True, datatables_options={ 'iDisplayLength': 25, 'bLengthChange': True, 'bAutoWidth': True, }, ) if insert_grid: resources_as_grid = QueryGrid( page=page, domid='resources-grid', title='Grid view', # this is the query at the core of the slice list query=sq_resource, query_all=query_resource_all, init_key=main_query_init_key, checkboxes=True, ) if do_query_leases: resources_as_scheduler = Scheduler( page=page, title='Scheduler', domid='scheduler', query=sq_resource, query_all_resources=query_resource_all, query_lease=sq_lease, ) # with the new 'Filter' stuff on top, no need for anything but the querytable resources_as_list_area = resources_as_list resources_sons = [ resources_as_gmap, resources_as_3dmap, resources_as_scheduler, resources_as_list_area, ] if do_query_leases else [ resources_as_gmap, resources_as_3dmap, resources_as_list_area, ] if insert_grid: resources_sons.append(resources_as_grid) resources_area = Tabs( page=page, domid="resources", togglable=True, title="Resources", outline_complete=True, sons=resources_sons, active_domid='resources-map', persistent_active=True, ) main_stack.insert(resources_area) # -------------------------------------------------------------------------- # USERS if do_query_users and query_user_all is not None: tab_users = Tabs( page=page, domid='users', outline_complete=True, togglable=True, title='Users', active_domid='users-list', ) main_stack.insert(tab_users) tab_users.insert( QueryTable( page=page, title='Users List', domid='users-list', # tab's sons preferably turn this off togglable=False, # this is the query at the core of the slice list query=sq_user, query_all=query_user_all, checkboxes=True, datatables_options={ 'iDisplayLength': 25, 'bLengthChange': True, 'bAutoWidth': True, }, )) # DEMO # -------------------------------------------------------------------------- # MEASUREMENTS measurements_stats_cpu = SliceStat(title="CPU Usage", domid='resources-stats-cpu', page=page, stats='slice', key='hrn', query='none', slicename=slicename, o='cpu') measurements_stats_mem = SliceStat(title="Memory Usage", domid='resources-stats-mem', page=page, stats='slice', key='hrn', query='none', slicename=slicename, o='mem') measurements_stats_asb = SliceStat(title="Traffic Sent", domid='resources-stats-asb', page=page, stats='slice', key='hrn', query='none', slicename=slicename, o='asb') measurements_stats_arb = SliceStat(title="Traffic Received", domid='resources-stats-arb', page=page, stats='slice', key='hrn', query='none', slicename=slicename, o='arb') tab_measurements = Tabs( page=page, domid="measurements", togglable=True, toggled='persistent', title="Measurements", outline_complete=True, sons=[ measurements_stats_cpu, measurements_stats_mem, measurements_stats_asb, measurements_stats_arb ], active_domid='resources-stats-cpu', persistent_active=True, ) main_stack.insert(tab_measurements) # tab_measurements = Tabs ( # page = page, # active_domid = 'measurements-list', # outline_complete = True, # togglable = True, # title = 'Measurements', # domid = 'measurements', # ) # main_stack.insert(tab_measurements) # # tab_measurements.insert(QueryTable( # page = page, # title = 'Measurements', # domid = 'measurements-list', # # tab's sons preferably turn this off # togglable = False, # # this is the query at the core of the slice list # query = sq_measurement, # # do NOT set checkboxes to False # # this table being otherwise empty, it just does not fly with dataTables # checkboxes = True, # datatables_options = { # 'iDisplayLength' : 25, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, # )) # # # -------------------------------------------------------------------------- # # MESSAGES (we use transient=False for now) if insert_messages: main_stack.insert( Messages( page=page, title="Runtime messages for slice %s" % slicename, domid="msgs-pre", levels="ALL", # plain messages are probably less nice for production but more reliable for development for now transient=False, # these make sense only in non-transient mode.. togglable=True, toggled='persistent', outline_complete=True, )) # variables that will get passed to the view-unfold1.html template template_env = {} # define 'unfold_main' to the template engine - the main contents template_env['unfold_main'] = main_stack.render(request) # more general variables expected in the template template_env['title'] = '%(slicename)s' % locals() # the menu items on the top template_env['topmenu_items'] = topmenu_items_live('Slice', page) # so we can sho who is logged template_env['username'] = the_user(request) template_env['theme'] = self.theme # don't forget to run the requests page.expose_js_metadata() # the prelude object in page contains a summary of the requirements() for all plugins # define {js,css}_{files,chunks} template_env.update(page.prelude_env()) return render_to_response('view-unfold1.html', template_env, context_instance=RequestContext(request))
def get(self, request, slicename): if request.GET.get('message'): msg = "Slice successfully updated" else: msg = None page = Page(request) metadata = page.get_metadata() page.expose_js_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] user_md = metadata.details_by_object('user') user_fields = ['user_hrn' ] # [column['name'] for column in user_md['column']] query_resource_all = Query.get('resource').select(resource_fields) #page.enqueue_query(query_resource_all) # leases query #lease_md = metadata.details_by_object('lease') #lease_fields = [column['name'] for column in lease_md['column']] #query_lease_all = Query.get('lease').select(lease_fields) #page.enqueue_query(query_lease_all) slice_md = metadata.details_by_object('slice') slice_fields = [column['name'] for column in slice_md['column']] logger.debug("SLICE RES VIEW fields = {}".format(slice_fields)) # TODO The query to run is embedded in the URL # Example: select slice_hrn, resource.urn, lease.resource, lease.start_time, lease.end_time from slice where slice_hrn == "ple.upmc.myslicedemo" main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename) main_query.select(slice_fields) # Columns shown by default in Query_table plugin page.expose_js_var( "QUERYTABLE_MAP", "{'Resource name': 'hostname', 'Type': 'type', 'Facility': 'facility_name','Testbed': 'testbed_name', 'Available':'available'}" ) # Columns checked by default in Columns_selector plugin query_default_fields = [ 'hostname', 'type', 'facility_name', 'testbed_name', 'available' ] QUERYTABLE_MAP = { 'hostname': 'Resource name', 'type': 'Type', 'facility_name': 'Facility', 'testbed_name': 'Testbed', 'available': 'Available', } # # SLICE # 'slice_hrn', # # - The record key is needed otherwise the storage of records # # bugs ! # 'slice_urn', # # RESOURCES # 'resource', # 'lease', # 'resource.urn', # 'resource.hostname', 'resource.type', # # - The facility_name and testbed_name are required for the # # testbeds plugin to properly work. # 'resource.facility_name', # 'resource.testbed_name', # # LEASES # 'lease.resource', # 'lease.start_time', # 'lease.end_time', # # - The lease_id is important for NITOS identify already existing # # leases # 'lease.lease_id', # # FLOWSPACE # #'flowspace', # # VMS # #'vms', # #'user.user_hrn', # #'application.measurement_point.counter' #) # for internal use in the querytable plugin; # needs to be a unique column present for each returned record main_query_init_key = 'urn' aq = AnalyzedQuery(main_query, metadata=metadata) page.enqueue_query(main_query, analyzed_query=aq) sq_resource = aq.subquery('resource') sq_lease = aq.subquery('lease') #sq_flowspace = aq.subquery('flowspace') #sq_vms = aq.subquery('vms') # -------------------------------------------------------------------------- # ALL RESOURCES LIST # resources as a list using datatable plugin list_resources = QueryTable( page=page, domid='resources-list', title='List view', query=sq_resource, query_all=query_resource_all, mapping=QUERYTABLE_MAP, default_fields=query_default_fields, init_key="urn", checkboxes=True, datatables_options={ 'iDisplayLength': 25, 'bLengthChange': True, 'bAutoWidth': True, }, ) # -------------------------------------------------------------------------- # RESERVED RESOURCES LIST # resources as a list using datatable plugin list_reserved_resources = SimpleList( title=None, page=page, key='urn', query=sq_resource, ) list_reserved_leases = SimpleList( title=None, page=page, key='resource', query=sq_lease, ) # list_reserved_resources = QueryTable( # page = page, # domid = 'resources-reserved-list', # title = 'List view', # query = sq_resource, # query_all = sq_resource, # init_key = "urn", # checkboxes = True, # datatables_options = { # 'iDisplayLength': 25, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, # ) # -------------------------------------------------------------------------- # COLUMNS EDITOR # list of fields to be applied on the query # this will add/remove columns in QueryTable plugin filter_column_editor = ColumnsEditor( page=page, query=sq_resource, query_all=query_resource_all, default_fields=query_default_fields, title="Select Columns", domid='select-columns', ) # -------------------------------------------------------------------------- # RESOURCES MAP # the resources part is made of a Tabs (Geographic, List), map_resources = GoogleMap( page=page, title='Geographic view', domid='resources-map', # tab's sons preferably turn this off togglable=False, query=sq_resource, # this key is the one issued by google googlemap_api_key=ConfigEngine().googlemap_api_key(), # the key to use at init-time init_key=main_query_init_key, checkboxes=True, # To center around Europe : 53,9 / 3 latitude=53., longitude=9., zoom=3, ) # -------------------------------------------------------------------------- # LEASES Nitos Scheduler # Display the leases reservation timeslots of the resources resources_as_scheduler2 = Scheduler2( page=page, domid='scheduler', title='Scheduler', # this is the query at the core of the slice list query=sq_resource, query_lease=sq_lease, ) # -------------------------------------------------------------------------- # LEASES Asap Scheduler # Select an end_time for all unconfigured resources # start_time is as soon as possible #resources_as_asap = AsapPlugin( # page = page, # domid = 'asap', # title = 'Asap', # # this is the query at the core of the slice list # query = sq_resource, # query_lease = sq_lease, #) # -------------------------------------------------------------------------- # QueryUpdater (Pending Operations) # pending_resources = QueryUpdaterPlugin( # page = page, # title = 'Pending operations', # query = main_query, # togglable = False, # # start turned off, it will open up itself when stuff comes in # toggled = False, # domid = 'pending', # outline_complete = True, # username = request.user, # ) # -------------------------------------------------------------------------- # NETWORKS # testbeds as a list of filters network_md = metadata.details_by_object('network') network_fields = [column['name'] for column in network_md['column']] #query_networks = Query.get('network').select(network_fields) #page.enqueue_query(query_networks) filter_testbeds = TestbedsPlugin( page=page, domid='testbeds-filter', title='Filter by testbeds', query=sq_resource, #query_networks = query_networks, #init_key = "network_hrn", #checkboxes = True, #datatables_options = { # 'iDisplayLength': 25, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, ) filter_status = FilterStatusPlugin( page=page, domid="filter-status", query=sq_resource, query_lease=sq_lease, ) apply = ApplyPlugin( page=page, domid="apply", query=main_query, username=request.user, ) # -------------------------------------------------------------------------- # Ofelia OpenFlow Plugin # Bristol plugin # plugin which display a "gathering resources" message # waiting for all resources to be returned by manifold # univbriswelcome = Univbris( # page = page, # title = 'univbris_welcome', # domid = 'univbris_welcome', # query = query_resource_all, # ) # univbrisfoamlist = UnivbrisFoam( # page = page, # title = 'univbris_foam_ports_selection', # domid = 'univbris_foam_ports_selection', # query = query_resource_all, # query_all = query_resource_all, # checkboxes = False, # datatables_options = { # 'iDisplayLength': 10, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, # ) # #plugin which manages the different flowspaces that the user creates, and also sends flowspaces to manifold # univbrisfvlist = UnivbrisFv( # page = page, # title = 'univbris_flowspace_selection', # domid = 'univbris_flowspace_selection', # query = sq_flowspace, # query_all = query_resource_all, # datatables_options = { # 'iDisplayLength': 5, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, # ) # #plugin which allows the definition of a single flowspace # univbrisfvform = UnivbrisFvf( # page = page, # title = 'univbris_flowspace_form', # domid = 'univbris_flowspace_form', # query = query_resource_all, # query_all = None, # datatables_options = { # 'iDisplayLength': 3, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, # ) # #plugin which allows the definition the match criteria on a single OPTICAL flowspace # univbrisofvform = UnivbrisFvfo( # page = page, # title = 'univbris_oflowspace_form', # domid = 'univbris_oflowspace_form', # query = None, # query_all = None, # datatables_options = { # 'iDisplayLength': 3, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, # ) # #plugin which display the gathered topology # univbristopology = UnivbrisTopo( # page = page, # title = 'univbris_topology', # domid = 'univbris_topology', # query = query_resource_all, # ) # # -------------------------------------------------------------------------- # # Ofelia VTAM Plugin # # Bristol Plugin # #plugin which display a table where an experimenter will add VMs to according to his needs # # responsible to send the data to Manifold # univbrisvtamplugin = UnivbrisVtamPlugin( # page = page, # title = 'univbris_vtam', # domid = 'univbris_vtam', # query = sq_vms, # #query = sq_resource, # ) # #plugin which display a form where an experimenter will specify # # in which testbed and which physical server to setup the VM # univbrisvtamform = UnivbrisVtamForm( # page = page, # title = 'univbris_vtam_form', # domid = 'univbris_vtam_form', # query = query_resource_all, # query_all = None, # datatables_options = { # 'iDisplayLength': 3, # 'bLengthChange' : True, # 'bAutoWidth' : True, # }, # ) # -------------------------------------------------------------------------- # SLA View and accept dialog sla_dialog = SlaDialog( page=page, title='sla dialog', query=main_query, #togglable = False, # start turned off, it will open up itself when stuff comes in #toggled = True, domid='sla_dialog', #outline_complete = True, username=request.user, ) template_env = {} template_env['request'] = self.request template_env['list_resources'] = list_resources.render(self.request) template_env[ 'list_reserved_resources'] = list_reserved_resources.render( self.request) template_env['list_reserved_leases'] = list_reserved_leases.render( self.request) template_env['columns_editor'] = filter_column_editor.render( self.request) template_env['filter_testbeds'] = filter_testbeds.render(self.request) template_env['filter_status'] = filter_status.render(self.request) template_env['apply'] = apply.render(self.request) template_env['map_resources'] = map_resources.render(self.request) template_env['scheduler'] = resources_as_scheduler2.render( self.request) #template_env['asap'] = resources_as_asap.render(self.request) # Bristol plugin # template_env['welcome'] = univbriswelcome.render(self.request) # template_env['resources'] = univbrisfoamlist.render(self.request) # template_env['flowspaces'] = univbrisfvlist.render(self.request) # template_env['oflowspaces_form'] = univbrisofvform.render(self.request) # template_env['flowspaces_form'] = univbrisfvform.render(self.request) # template_env['topology'] = univbristopology.render(self.request) # template_env['vms_list'] = univbrisvtamplugin.render(self.request) # template_env['vm_form'] = univbrisvtamform.render(self.request) # template_env['pending_resources'] = pending_resources.render(self.request) template_env['sla_dialog'] = sla_dialog.render(self.request) template_env["theme"] = self.theme template_env["username"] = request.user template_env["slice"] = slicename template_env["section"] = "resources" template_env["msg"] = msg template_env.update(page.prelude_env()) return render_to_response(self.template, template_env, context_instance=RequestContext(request))
def get(self, request, slicename='ple.inria.f14'): page = Page(request) page.expose_js_metadata() metadata = page.get_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename) main_query.select( 'slice_hrn', #'resource.hrn', 'resource.hostname', 'resource.type', 'resource.network_hrn', 'lease.urn', 'user.user_hrn', #'application.measurement_point.counter' ) # for internal use in the querygrid plugin; # needs to be a unique column present for each returned record main_query_init_key = 'hostname' query_resource_all = Query.get('resource').select(resource_fields) aq = AnalyzedQuery(main_query, metadata=metadata) page.enqueue_query(main_query, analyzed_query=aq) page.enqueue_query(query_resource_all) sq_resource = aq.subquery('resource') resources_as_list = QueryGrid( page=page, domid='resources-list', title='List view', # this is the query at the core of the slice list query=sq_resource, query_all=query_resource_all, # safer to use 'hrn' as the internal unique key for this plugin init_key=main_query_init_key, checkboxes=True, datatables_options={ 'iDisplayLength': 25, 'bLengthChange': True, 'bAutoWidth': True, }, ) # variables that will get passed to the view-unfold1.html template template_env = {} # define 'unfold_main' to the template engine - the main contents template_env['unfold_main'] = resources_as_list.render(request) # more general variables expected in the template template_env['title'] = 'simple %(slicename)s' % locals() # the menu items on the top template_env['topmenu_items'] = topmenu_items_live('Slice', page) # so we can sho who is logged template_env['username'] = the_user(request) # the prelude object in page contains a summary of the requirements() for all plugins # define {js,css}_{files,chunks} prelude_env = page.prelude_env() template_env.update(prelude_env) result = render_to_response('view-unfold1.html', template_env, context_instance=RequestContext(request)) return result
def get (self,request, slicename=tmp_default_slice): page = Page(request) page.add_css_files ('css/slice-view.css') page.add_js_files ( [ "js/common.functions.js" ] ) page.add_js_chunks ('$(function() { messages.debug("sliceview: jQuery version " + $.fn.jquery); });') page.add_js_chunks ('$(function() { messages.debug("sliceview: users turned %s"); });'%("on" if do_query_users else "off")) page.add_js_chunks ('$(function() { messages.debug("sliceview: leases turned %s"); });'%("on" if do_query_leases else "off")) page.add_js_chunks ('$(function() { messages.debug("manifold URL %s"); });'%(ConfigEngine().manifold_url())) metadata = page.get_metadata() resource_md = metadata.details_by_object('resource') resource_fields = [column['name'] for column in resource_md['column']] user_md = metadata.details_by_object('user') user_fields = ['user_hrn'] # [column['name'] for column in user_md['column']] # TODO The query to run is embedded in the URL main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename) main_query.select( 'slice_hrn', #'resource.hrn', 'resource.urn', 'resource.hostname', 'resource.type', 'resource.network_hrn', 'lease.urn', 'user.user_hrn', #'application.measurement_point.counter' ) # for internal use in the querytable plugin; # needs to be a unique column present for each returned record main_query_init_key = 'hostname' query_resource_all = Query.get('resource').select(resource_fields) aq = AnalyzedQuery(main_query, metadata=metadata) page.enqueue_query(main_query, analyzed_query=aq) page.enqueue_query(query_resource_all) if do_query_users: # Required: the user must have an authority in its user.config # XXX Temporary solution user_query = Query().get('local:user').select('config','email') user_details = execute_query(self.request, user_query) # not always found in user_details... config={} # for user_detail in user_details: # #email = user_detail['email'] # if user_detail['config']: # config = json.loads(user_detail['config']) # user_detail['authority'] = config.get('authority',"Unknown Authority") # # if user_detail['authority'] is not None: # sub_authority = user_detail['authority'].split('.') # root_authority = sub_authority[0] # query_user_all = Query.get(root_authority+':user').select(user_fields) # # # XXX TODO this filter doesn't work - to be improved in Manifold # #.filter_by('authority.authority_hrn', '=', user_detail['authority']) # # page.enqueue_query(query_user_all) # else: # print "authority of the user is not in local:user db" query_user_all = Query.get('user').select(user_fields) # query_user_all = None # ... and for the relations # XXX Let's hardcode resources for now sq_resource = aq.subquery('resource') sq_user = aq.subquery('user') sq_lease = aq.subquery('lease') sq_measurement = aq.subquery('measurement') # Prepare the display according to all metadata # (some parts will be pending, others can be triggered by users). # # For example slice measurements will not be requested by default... # Create the base layout (Stack)... main_stack = Stack ( page=page, title="Slice %s"%slicename, sons=[], ) # ... responsible for the slice properties... # a nice header main_stack.insert ( Raw (page=page, togglable=False, toggled=True, html="<h2 class='well well-lg'> Slice %s</h2>"%slicename) ) # -------------------------------------------------------------------------- # QueryUpdater (Pending Operations) main_stack.insert(QueryUpdater( page = page, title = 'Pending operations', query = main_query, togglable = True, # start turned off, it will open up itself when stuff comes in toggled = False, domid = 'pending', outline_complete = True, )) # -------------------------------------------------------------------------- # Filter Resources # turn off for now -- see above filter_query_editor = QueryEditor( page = page, query = sq_resource, query_all = query_resource_all, title = "Select Columns", domid = 'select-columns', ) filter_active_filters = ActiveFilters( page = page, query = sq_resource, title = "Active Filters", ) filters_area = Stack( page = page, title = 'Filter Resources', domid = 'filters', sons = [filter_query_editor, filter_active_filters], togglable = True, toggled = 'persistent', outline_complete = True, ) main_stack.insert (filters_area) # -------------------------------------------------------------------------- # RESOURCES # the resources part is made of a Tabs (Geographic, List), resources_as_gmap = GoogleMap( page = page, title = 'Geographic view', domid = 'resources-map', # tab's sons preferably turn this off togglable = False, query = sq_resource, query_all = query_resource_all, # this key is the one issued by google googlemap_api_key = ConfigEngine().googlemap_api_key(), # the key to use at init-time init_key = main_query_init_key, checkboxes = True, # center on Paris latitude = 49., longitude = 9, zoom = 4, ) resources_as_3dmap = SensLabMap( page = page, title = '3D Map', domid = 'senslabmap', query = sq_resource, query_all = query_resource_all, ) resources_as_list = QueryTable( page = page, domid = 'resources-list', title = 'List view', # this is the query at the core of the slice list query = sq_resource, query_all = query_resource_all, init_key = main_query_init_key, checkboxes = True, datatables_options = { 'iDisplayLength': 25, 'bLengthChange' : True, 'bAutoWidth' : True, }, ) if insert_grid: resources_as_grid = QueryGrid( page = page, domid = 'resources-grid', title = 'Grid view', # this is the query at the core of the slice list query = sq_resource, query_all = query_resource_all, init_key = main_query_init_key, checkboxes = True, ) #if do_query_leases: # resources_as_scheduler = Scheduler( # page = page, # title = 'Scheduler', # domid = 'scheduler', # query = sq_resource, # query_all_resources = query_resource_all, # query_lease = sq_lease, # ) resources_as_scheduler2 = Scheduler2( page = page, domid = 'scheduler', title = 'Scheduler', # this is the query at the core of the slice list query = sq_resource, query_all_resources = query_resource_all, query_lease = sq_lease, )
def get_context_data(self, **kwargs): self.template_name = self.template page = Page(self.request) metadata = page.get_metadata() page.expose_js_metadata() page.add_js_files ( [ "js/jquery.validate.js", "js/my_account.register.js", "js/my_account.edit_profile.js","js/jquery-ui.js" ] ) page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css" ] ) # Execute a Query to delegate credentials if necessary #sfa_user_query = Query().get('myslice:user').select('user_hrn').filter_by('user_hrn','==','$user_hrn') #sfa_user_result = execute_query(self.request, sfa_user_query) user_query = Query().get('local:user').select('config','email','status') user_details = execute_query(self.request, user_query) # not always found in user_details... config={} for user_detail in user_details: # different significations of user_status if user_detail['status'] == 0: user_status = 'Disabled' elif user_detail['status'] == 1: user_status = 'Validation Pending' elif user_detail['status'] == 2: user_status = 'Enabled' else: user_status = 'N/A' #email = user_detail['email'] if user_detail['config']: config = json.loads(user_detail['config']) platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled') account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') platform_details = execute_query(self.request, platform_query) account_details = execute_query(self.request, account_query) # initial assignment needed for users having account.config = {} platform_name = '' account_type = '' account_usr_hrn = '' account_pub_key = '' account_priv_key = '' account_reference = '' my_users = '' my_slices = '' my_auths = '' ref_acc_list = '' principal_acc_list = '' user_status_list = [] platform_name_list = [] platform_name_secondary_list = [] platform_access_list = [] platform_no_access_list = [] total_platform_list = [] account_type_list = [] account_type_secondary_list = [] account_reference_list = [] delegation_type_list = [] user_cred_exp_list = [] slice_list = [] auth_list = [] slice_cred_exp_list = [] auth_cred_exp_list = [] usr_hrn_list = [] pub_key_list = [] for platform_detail in platform_details: if 'sfa' in platform_detail['gateway_type']: total_platform = platform_detail['platform'] total_platform_list.append(total_platform) for account_detail in account_details: if platform_detail['platform_id'] == account_detail['platform_id']: platform_name = platform_detail['platform'] if 'config' in account_detail and account_detail['config'] is not '': account_config = json.loads(account_detail['config']) account_usr_hrn = account_config.get('user_hrn','N/A') account_pub_key = account_config.get('user_public_key','N/A') account_reference = account_config.get ('reference_platform','N/A') # credentials of myslice platform if 'myslice' in platform_detail['platform']: acc_user_cred = account_config.get('delegated_user_credential','N/A') acc_slice_cred = account_config.get('delegated_slice_credentials','N/A') acc_auth_cred = account_config.get('delegated_authority_credentials','N/A') if 'N/A' not in acc_user_cred: exp_date = re.search('<expires>(.*)</expires>', acc_user_cred) if exp_date: user_exp_date = exp_date.group(1) user_cred_exp_list.append(user_exp_date) my_users = [{'cred_exp': t[0]} for t in zip(user_cred_exp_list)] if 'N/A' not in acc_slice_cred: for key, value in acc_slice_cred.iteritems(): slice_list.append(key) # get cred_exp date exp_date = re.search('<expires>(.*)</expires>', value) if exp_date: exp_date = exp_date.group(1) slice_cred_exp_list.append(exp_date) my_slices = [{'slice_name': t[0], 'cred_exp': t[1]} for t in zip(slice_list, slice_cred_exp_list)] if 'N/A' not in acc_auth_cred: for key, value in acc_auth_cred.iteritems(): auth_list.append(key) #get cred_exp date exp_date = re.search('<expires>(.*)</expires>', value) if exp_date: exp_date = exp_date.group(1) auth_cred_exp_list.append(exp_date) my_auths = [{'auth_name': t[0], 'cred_exp': t[1]} for t in zip(auth_list, auth_cred_exp_list)] # for reference accounts if 'reference' in account_detail['auth_type']: account_type = 'Reference' delegation = 'N/A' platform_name_secondary_list.append(platform_name) account_type_secondary_list.append(account_type) account_reference_list.append(account_reference) ref_acc_list = [{'platform_name': t[0], 'account_type': t[1], 'account_reference': t[2]} for t in zip(platform_name_secondary_list, account_type_secondary_list, account_reference_list)] elif 'managed' in account_detail['auth_type']: account_type = 'Principal' delegation = 'Automatic' else: account_type = 'Principal' delegation = 'Manual' # for principal (auth_type=user/managed) accounts if 'reference' not in account_detail['auth_type']: platform_name_list.append(platform_name) account_type_list.append(account_type) delegation_type_list.append(delegation) usr_hrn_list.append(account_usr_hrn) pub_key_list.append(account_pub_key) user_status_list.append(user_status) # combining 5 lists into 1 [to render in the template] principal_acc_list = [ {'platform_name' : pn, 'account_type' : at, 'delegation_type' : dt, 'usr_hrn' : uh, 'usr_pubkey' : up, 'user_status' : us,} for pn, at, dt, uh, up, us in zip(platform_name_list, account_type_list, delegation_type_list, usr_hrn_list, pub_key_list, user_status_list) ] # to hide private key row if it doesn't exist if 'myslice' in platform_detail['platform']: account_config = json.loads(account_detail['config']) account_priv_key = account_config.get('user_private_key','N/A') if 'sfa' in platform_detail['gateway_type']: platform_access = platform_detail['platform'] platform_access_list.append(platform_access) # Removing the platform which already has access for platform in platform_access_list: total_platform_list.remove(platform) # we could use zip. this one is used if columns have unequal rows platform_list = [{'platform_no_access': t[0]} for t in itertools.izip_longest(total_platform_list)] # check if the user has creds or not if acc_user_cred == {} or acc_user_cred == 'N/A': user_cred = 'no_creds' else: exp_date = get_expiration(acc_user_cred, 'timestamp') if exp_date < time.time(): user_cred = 'creds_expired' else: user_cred = 'has_creds' context = super(AccountView, self).get_context_data(**kwargs) context['principal_acc'] = principal_acc_list context['ref_acc'] = ref_acc_list context['platform_list'] = platform_list context['my_users'] = my_users context['user_cred'] = user_cred context['my_slices'] = my_slices context['my_auths'] = my_auths context['user_status'] = user_status context['person'] = self.request.user context['firstname'] = config.get('firstname',"?") context['lastname'] = config.get('lastname',"?") context['fullname'] = context['firstname'] +' '+ context['lastname'] context['authority'] = config.get('authority',"Unknown Authority") context['user_private_key'] = account_priv_key # XXX This is repeated in all pages # more general variables expected in the template context['title'] = 'Platforms connected to MySlice' # the menu items on the top context['topmenu_items'] = topmenu_items_live('My Account', page) # so we can sho who is logged context['username'] = the_user(self.request) context['theme'] = self.theme context['section'] = "User account" # context ['firstname'] = config['firstname'] context['request'] = self.request prelude_env = page.prelude_env() context.update(prelude_env) return context
def get_context_data(self, **kwargs): ctx_my_authorities = {} ctx_delegation_authorities = {} ctx_sub_authorities = {} dest = {} # The user need to be logged in if (self.request.user): user_query = Query().get('local:user').filter_by( 'email', '==', self.request.user.email).select('user_id') user, = execute_query(self.request, user_query) user_id = user['user_id'] # Query manifold to learn about available SFA platforms for more information # In general we will at least have the portal # For now we are considering all registries all_authorities = [] platform_ids = [] sfa_platforms_query = Query().get('local:platform').filter_by( 'gateway_type', '==', 'sfa').select('platform_id', 'platform', 'auth_type') sfa_platforms = execute_query(self.request, sfa_platforms_query) for sfa_platform in sfa_platforms: logger.info("SFA PLATFORM > {}".format( sfa_platform['platform'])) if not 'auth_type' in sfa_platform: continue auth = sfa_platform['auth_type'] if not auth in all_authorities: all_authorities.append(auth) platform_ids.append(sfa_platform['platform_id']) logger.warning("W: Hardcoding platform myslice") # There has been a tweak on how new platforms are referencing a # so-called 'myslice' platform for storing authentication tokens. # XXX This has to be removed in final versions. myslice_platforms_query = Query().get('local:platform').filter_by( 'platform', '==', 'myslice').select('platform_id') myslice_platforms = execute_query(self.request, myslice_platforms_query) if myslice_platforms: myslice_platform, = myslice_platforms platform_ids.append(myslice_platform['platform_id']) # We can check on which the user has authoritity credentials = PI rights credential_authorities = set() credential_authorities_expired = set() # User account on these registries user_accounts_query = Query.get('local:account').filter_by( 'user_id', '==', user_id).filter_by('platform_id', 'included', platform_ids).select('auth_type', 'config') user_accounts = execute_query(self.request, user_accounts_query) for user_account in user_accounts: if user_account['auth_type'] == 'reference': continue # we hardcoded the myslice platform... config = json.loads(user_account['config']) creds = [] if 'authority_credentials' in config: for authority_hrn, credential in config[ 'authority_credentials'].items(): credential_authorities.add(authority_hrn) if 'delegated_authority_credentials' in config: for authority_hrn, credential in config[ 'delegated_authority_credentials'].items(): credential_authorities.add(authority_hrn) # CACHE PB with fields page = Page(self.request) metadata = page.get_metadata() user_md = metadata.details_by_object('user') user_fields = [column['name'] for column in user_md['column']] # ** Where am I a PI ** # For this we need to ask SFA (of all authorities) = PI function pi_authorities_query = Query.get('myslice:user').filter_by( 'user_hrn', '==', '$user_hrn').select(user_fields) pi_authorities_tmp = execute_query(self.request, pi_authorities_query) pi_authorities = set() try: for pa in pi_authorities_tmp: pi_authorities |= set(pa['pi_authorities']) except Exception as e: logger.error('No pi_authorities') pi_credential_authorities = pi_authorities & credential_authorities pi_no_credential_authorities = pi_authorities - credential_authorities - credential_authorities_expired pi_expired_credential_authorities = pi_authorities & credential_authorities_expired # Authorities I've been delegated PI rights pi_delegation_credential_authorities = credential_authorities - pi_authorities pi_delegation_expired_authorities = credential_authorities_expired - pi_authorities # Summary intermediary pi_my_authorities = pi_credential_authorities | pi_no_credential_authorities | pi_expired_credential_authorities pi_delegation_authorities = pi_delegation_credential_authorities | pi_delegation_expired_authorities # Summary all queried_pending_authorities = pi_my_authorities | pi_delegation_authorities #| pi_subauthorities # iterate on the requests and check if the authority matches a prefix # startswith an authority on which the user is PI if len(pi_my_authorities) > 0: requests = get_requests(pi_my_authorities) else: requests = get_requests() for r in requests: auth_hrn = r['authority_hrn'] for my_auth in pi_my_authorities: if auth_hrn.startswith(my_auth): dest = ctx_my_authorities r['allowed'] = 'allowed' #for my_auth in pi_delegation_authorities: # if auth_hrn.startswith(my_auth): # dest = ctx_delegation_authorities # r['allowed'] = 'allowed' if auth_hrn in pi_expired_credential_authorities: r['allowed'] = 'expired' if 'allowed' not in r: ## TEMP FIX for allowing new authority registration #r['allowed'] = 'denied' r['allowed'] = 'allowed' if not auth_hrn in dest: dest[auth_hrn] = [] dest[auth_hrn].append(r) # env = {} # env['my_authorities'] = ctx_my_authorities # env['sub_authorities'] = ctx_sub_authorities # env['delegation_authorities'] = ctx_delegation_authorities # # # XXX This is repeated in all pages # # more general variables expected in the template # # the menu items on the top # #env['topmenu_items'] = topmenu_items_live('Validation', page) # # so we can sho who is logged # env['username'] = request.user # env['pi'] = "is_pi" # env['theme'] = self.theme # env['section'] = "Requests" context = super(ManagementRequestsView, self).get_context_data(**kwargs) context['my_authorities'] = ctx_my_authorities context['sub_authorities'] = ctx_sub_authorities context['delegation_authorities'] = ctx_delegation_authorities # XXX This is repeated in all pages # more general variables expected in the template context['title'] = 'Test view that combines various plugins' # the menu items on the top #context['topmenu_items'] = topmenu_items_live('Validation', page) # so we can sho who is logged context['username'] = self.request.user context['pi'] = "is_pi" context['theme'] = self.theme context['section'] = "Requests" # XXX We need to prepare the page for queries #context.update(page.prelude_env()) return context