def check(self): request = self.auth.request # Have we been authenticated by the ssl layer ? peer_certificate = request.channel.transport.getPeerCertificate() user_hrn = peer_certificate.get_subject().commonName if peer_certificate else None if not user_hrn: raise AuthenticationFailure, "GID verification failed" # We need to map the SFA user to the Manifold user... let's search into his accounts query_user_id = Query.get('local:linked_account').filter_by('identifier', '==', user_hrn).select('user_id') ret_user_ids = self.interface.forward(query_user_id) if ret_user_ids['code'] != 0: raise Exception, "Failure requesting linked accounts for identifier '%s'" % user_hrn user_ids = ret_user_ids['value'] if not user_ids: raise Exception, "No linked account found with identifier '%s'" % user_hrn print "user_ids", user_ids user_id = user_ids[0]['user_id'] query_user = Query.get('local:user').filter_by('user_id', '==', user_id) ret_users = self.interface.forward(query_user) if ret_users['code'] != 0: raise Exception, "Failure requesting linked accounts for identifier '%s'" % user_hrn users = ret_users['value'] if not users: raise Exception, "Internal error: no user found with user_id = '%d'" % user_id user, = users print "Linked SFA account '%s' for user: %r" % (user_hrn, user)
def get_context_data(self, **kwargs): page = Page(self.request) # This will simulate fake records in order to test the plugin fake_query = Query.get('ping').select('hrn', 'src_hostname', 'dst_hostname', 'delay') fake_query_all = Query.get('ping').select('hrn', 'src_hostname', 'dst_hostname', 'delay') generators = { 'hrn': 'random_string', 'src_hostname': 'random_string', 'dst_hostname': 'random_string', 'delay': 'random_int' } page.generate_records(fake_query, generators, 5) page.generate_records(fake_query_all, generators, 20) plugin = MadDash(query=fake_query, query_all=fake_query_all, page=page) context = super(MadDashView, self).get_context_data(**kwargs) context['unfold_main'] = plugin.render(self.request) context['title'] = 'Sandbox for MadDash plugin' context['topmenu_items'] = topmenu_items_live('maddash', page) context['username'] = the_user(self.request) prelude_env = page.prelude_env() context.update(prelude_env) return context
def get_context_data(self, **kwargs): page = Page(self.request) # This will simulate fake records in order to test the plugin fake_query = Query.get('ping').select('hrn', 'src_hostname', 'dst_hostname', 'delay') fake_query_all = Query.get('ping').select('hrn', 'src_hostname', 'dst_hostname', 'delay') generators = { 'hrn': 'random_string', 'src_hostname': 'random_string', 'dst_hostname': 'random_string', 'delay': 'random_int' } page.generate_records(fake_query, generators, 5) page.generate_records(fake_query_all, generators, 20) plugin = MadDash(query = fake_query, query_all = fake_query_all, page = page) context = super(MadDashView, self).get_context_data(**kwargs) context['unfold_main'] = plugin.render(self.request) context['title'] = 'Sandbox for MadDash plugin' context['topmenu_items'] = topmenu_items_live ('maddash', page) context['username'] = the_user(self.request) prelude_env = page.prelude_env() context.update(prelude_env) return context
def check(self): assert self.auth.has_key('session') query_sessions = Query.get('local:session').filter_by('session', '==', self.auth['session']) sessions = self.interface.execute_local_query(query_sessions) if not sessions: del self.auth['session'] raise AuthenticationFailure, "No such session: %s" % self.auth session = sessions[0] user_id = session['user_id'] try: query_users = Query.get('local:user').filter_by('user_id', '==', user_id) user, = self.interface.execute_local_query(query_users) except Exception, e: raise AuthenticationFailure, "No such user_id: %s" % e
def topmenu_items_live(current, page): request = page.request # XXX TODO This should be triggered only when user is logged in # We might use local storage instead # REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2 if request.user.is_authenticated(): query_pi_auths = Query.get('myslice:user').filter_by( 'user_hrn', '==', '$user_hrn').select('user_hrn', 'pi_authorities') page.enqueue_query(query_pi_auths) else: query_pi_auths = Query() # # even though this plugin does not have any html materialization, the corresponding domid # # must exist because it is searched at init-time to create the JS plugin # # so we simply piggy-back the target button created in the topmenu topmenuvalidation = TopmenuValidation( page=page, # see above domid='topmenu-validation', query=query_pi_auths, # this one is the target for a $.show() when the query comes back button_domid="topmenu-validation") # although the result does not matter, rendering is required for the JS init code to make it in the page topmenuvalidation.render(request) return topmenu_items_static(current, request)
def setLocalFields(self): query = Query.get('local:object').filter_by('table', '==', self.type).select('column.name') results = execute_query(self.request, query) if results : for r in results[0]['column'] : self.fields.append(r['name']) else : raise Exception, 'Manifold db error'
def load(self): Target.register_plugins() query_rules = Query.get('local:policy').select('policy_json') rules = self._interface.execute_local_query(query_rules) for rule in rules: self.rules.append(Rule.from_dict(json.loads(rule['policy_json'])))
def authority_get_pi_emails(request, authority_hrn): #return ['*****@*****.**', '*****@*****.**'] pi_users = authority_get_pis(request,authority_hrn) pi_user_hrns = [ hrn for x in pi_users for hrn in x['pi_users'] ] query = Query.get('user').filter_by('user_hrn', 'included', pi_user_hrns).select('email') results = execute_query(request, query) print "mails", [result['email'] for result in results] return [result['email'] for result in results]
def get(self): query = Query.get(self.type) if (self.id is not None) and (self.id not in self.fields) : query.select(self.fields + [self.id]) else : query.select(self.fields) query = self.applyFilters(query) return execute_query(self.request, query)
def authority_get_pis(request, authority_hrn): query = Query.get('authority').filter_by('authority_hrn', '==', authority_hrn).select('pi_users') results = execute_query(request, query) # NOTE: temporarily commented. Because results is giving empty list. # Needs more debugging #if not results: # raise Exception, "Authority not found: %s" % authority_hrn #result, = results #return result['pi_users'] return results
def setKey(self): # What about key formed of multiple fields??? query = Query.get('local:object').filter_by('table', '==', self.type).select('key') results = execute_query(self.request, query) logger.debug("key of object = {}".format(results)) if results : for r in results[0]['key'] : self.id = r else : raise Exception, 'Manifold db error'
def sfa_add_user_to_slice(request, user_hrn, slice_params): # UPDATE myslice:slice SET researcher=['ple.upmc.jordan_auge','ple.inria.thierry_parmentelat','ple.upmc.loic_baron','ple.upmc.ciro_scognamiglio','ple.upmc.mohammed-yasin_rahman','ple.upmc.azerty'] where slice_hrn=='ple.upmc.myslicedemo' query_current_users = Query.get('slice').select('user').filter_by('slice_hrn','==',slice_params['hrn']) results_current_users = execute_query(request, query_current_users) slice_params['researcher'] = slice_params['researcher'] | results_current_users query = Query.update('slice').filter_by('user_hrn', '==', user_hrn).set(slice_params).select('slice_hrn') results = execute_query(request, query) # Also possible but not supported yet # UPDATE myslice:user SET slice=['ple.upmc.agent','ple.upmc.myslicedemo','ple.upmc.tophat'] where user_hrn=='ple.upmc.azerty' if not results: raise Exception, "Could not create %s. Already exists ?" % slice_params['hrn'] return results
def dispatch(request, action): results = [] error = None try: if request.method == 'POST': req_items = request.POST elif request.method == 'GET': req_items = request.GET for el in req_items.items(): if el[0].startswith('slice_hrn'): slice_hrn = el[1] elif el[0].startswith('initscript_code'): initscript_code = el[1] if (action == 'get'): # select initscript_code from initscript where slice_hrn=='onelab.upmc.express' query = Query.get('initscript').filter_by( 'slice_hrn', '==', slice_hrn).select('initscript_code') results = execute_admin_query(request, query) if (action == 'update'): # UPDATE initscript SET initscript_code='test3' where slice_hrn=='onelab.upmc.express' params = {'initscript_code': initscript_code} query = Query.update('initscript').filter_by( 'slice_hrn', '==', slice_hrn).set(params) results = execute_admin_query(request, query) if results[0]['initscript_code'] == 1: results[0]['initscript_code'] = initscript_code else: error = "Error in update return value" if (action == 'delete'): # delete from initscript where slice_hrn=='onelab.upmc.express' query = Query.delete('initscript').filter_by( 'slice_hrn', '==', slice_hrn) results = execute_admin_query(request, query) if results[0]['initscript_code'] == 1: results[0]['initscript_code'] = "" else: error = "Error in delete return value" except Exception, e: error = str(e)
def is_ple_enabled(self, pending_user): pending_authorities = PendingAuthority.objects.filter( site_authority__iexact=pending_user.authority_hrn) if pending_authorities: return False pending_user_email = pending_user.email try: query = Query.get('myplcuser').filter_by( 'email', '==', pending_user_email).select('enabled') results = execute_admin_query(self.request, query) for result in results: # User is enabled in PLE if 'enabled' in result and result['enabled'] == True: return True except Exception as e: logger.error("Exception in myplc query = {}".format(e)) return False
def check(self): # Method.type_check() should have checked that all of the # mandatory fields were present. assert self.auth.has_key('Username') # Get record (must be enabled) try: query_users = Query.get('local:user').filter_by('email', '==', self.auth['Username'].lower()) user, = self.interface.execute_local_query(query_users) except Exception, e: import traceback traceback.print_exc() Log.warning("Authentication failed, delete expired sessions") query_sessions = Query.delete('local:session').filter_by('expires', '<', int(time.time())) try: self.interface.execute_local_query(query_sessions) except: pass raise AuthenticationFailure, "No such account (PW): %s" % e
def topmenu_items_live(current, page): request = page.request query_pi_auths = Query.get("user").filter_by("user_hrn", "==", "$user_hrn").select("pi_authorities") page.enqueue_query(query_pi_auths) # # even though this plugin does not have any html materialization, the corresponding domid # # must exist because it is searched at init-time to create the JS plugin # # so we simply piggy-back the target button created in the topmenu topmenuvalidation = TopmenuValidation( page=page, # see above domid="topmenu-validation", query=query_pi_auths, # this one is the target for a $.show() when the query comes back button_domid="topmenu-validation", ) # although the result does not matter, rendering is required for the JS init code to make it in the page topmenuvalidation.render(request) return topmenu_items_static(current, request)
def authenticate(self, token=None): if not token: return None try: username = token['username'] password = token['password'] request = token['request'] auth = {'AuthMethod': 'password', 'Username': username, 'AuthString': password} api = ManifoldAPI(auth) sessions_result = api.forward(Query.create('local:session').to_dict()) print "result" sessions = sessions_result.ok_value() print "ok" if not sessions: print "GetSession failed", sessions_result.error() return print "first", sessions session = sessions[0] # Change to session authentication api.auth = {'AuthMethod': 'session', 'session': session['session']} self.api = api # Get account details # the new API would expect Get('local:user') instead persons_result = api.forward(Query.get('local:user').to_dict()) persons = persons_result.ok_value() if not persons: print "GetPersons failed",persons_result.error() return person = persons[0] print "PERSON=", person request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']} except ManifoldException, e: print "ManifoldBackend.authenticate caught ManifoldException, returning corresponding ManifoldResult" return e.manifold_result
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 print_err(err): print "-" * 80 print "Exception %(code)s raised by %(origin)s: %(description)s" % err for line in err["traceback"].split("\n"): print "\t", line print "" query = Query.get("traceroute").select( [ "src_ip", "src_hostname", "dst_ip", "dst_hostname"#, # "hops.ip", # "hops.ttl", # "hops.hostname" ]).filter_by([ ("src_ip", "=", "141.22.213.34"), ("dst_ip", "=", "139.91.90.239") # or 195.116.60.211 ]).at("2012-09-09 14:30:09") print query ret = Router().forward(query, user = Auth(auth).check()) if ret["code"] != 0: if isinstance(ret["description"], list): # We have a list of errors for err in ret["description"]:
def get_or_post (self, request, method): # Using cache manifold-tables to get the list of authorities faster authorities_query = Query.get('authority').select('name', 'authority_hrn') authorities = execute_admin_query(request, authorities_query) if authorities is not None: authorities = sorted(authorities) user_query = Query().get('local:user').select('email') user_email = execute_query(self.request, user_query) self.user_email = user_email[0].get('email') account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') account_details = execute_query(self.request, account_query) platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled') platform_details = execute_query(self.request, platform_query) # getting user_hrn from local:account for account_detail in account_details: for platform_detail in platform_details: if platform_detail['platform_id'] == account_detail['platform_id']: # taking user_hrn only from myslice account # NOTE: we should later handle accounts filter_by auth_type= managed OR user if 'myslice' in platform_detail['platform']: account_config = json.loads(account_detail['config']) user_hrn = account_config.get('user_hrn','N/A') #user_query = Query().get('user').select('user_hrn').filter_by('user_hrn','==','$user_hrn') #user_hrn = execute_query(self.request, user_query) #self.user_hrn = user_hrn[0].get('user_hrn') page = Page(request) page.add_css_files ( [ "http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" ] ) if method == 'POST': self.errors = [] # The form has been submitted slice_name = request.POST.get('slice_name', '') authority_hrn = request.POST.get('authority_hrn', '') number_of_nodes = request.POST.get('number_of_nodes', '') purpose = request.POST.get('purpose', '') email = self.user_email #user_hrn = user_hrn cc_myself = True if (authority_hrn is None or authority_hrn == ''): self.errors.append('Please, select an authority') # What kind of slice name is valid? if (slice_name is None or slice_name == ''): self.errors.append('Slice Name is mandatory') if (purpose is None or purpose == ''): self.errors.append('Purpose is mandatory') if not self.errors: ctx = { 'email': email, 'slice_name': slice_name, 'authority_hrn': authority_hrn, 'number_of_nodes': number_of_nodes, 'purpose': purpose, } s = PendingSlice( slice_name = slice_name, user_hrn = user_hrn, authority_hrn = authority_hrn, number_of_nodes = number_of_nodes, purpose = purpose ) s.save() # The recipients are the PI of the authority recipients = authority_get_pi_emails(request, authority_hrn) #if cc_myself: recipients.append('*****@*****.**') msg = render_to_string('slice-request-email.txt', ctx) #print "email, msg, email, recipients", email , msg, email, recipients send_mail("Onelab user %s requested a slice"%email , msg, email, recipients) return render(request,'slice-request-ack-view.html') # Redirect after POST template_env = { 'topmenu_items': topmenu_items_live('Request a slice', page), 'errors': self.errors, 'slice_name': request.POST.get('slice_name', ''), 'authority_hrn': request.POST.get('authority_hrn', ''), 'number_of_nodes': request.POST.get('number_of_nodes', ''), 'purpose': request.POST.get('purpose', ''), 'email': self.user_email, 'user_hrn': user_hrn, 'cc_myself': True, 'authorities': authorities, } template_env.update(page.prelude_env ()) return render(request, 'slicerequest_view.html',template_env)
continue seen.add(current) for child in current.children: out.append(" \"%s\" -> \"%s\"" % (current, child)) stack.append(child) out.append("}") return "\n".join(out) ################################################################################ if __name__ == '__main__': from manifold.core.query import Query q1 = Query.get('table').filter_by('prop', '==', 1) q2 = Query.get('table').select('test') q3 = Query.get('table').filter_by('prop', '==', 1).select('test') q4 = Query.get('table') l = Lattice() for i, q in enumerate([q1, q2, q3, q4]): #print '#'*80 #print "# q%d # %s" % (i+1, q) #print '#'*80 l.add(q) print l.dump()
def get_or_post(self, request, method): errors = [] # List authorities already in the Registry in order to avoid duplicates # Using cache manifold-tables to get the list of authorities faster authorities_query = Query.get("authority").select("name", "authority_hrn") authorities = execute_admin_query(request, authorities_query) if authorities is not None: authorities = sorted(authorities) root_authorities = sorted([a for a in authorities if "." not in a["authority_hrn"]]) page = Page(request) page.add_js_files(["js/jquery.validate.js", "js/join.js"]) page.add_css_files(["css/onelab.css", "css/registration.css"]) page.add_css_files(["http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"]) if method == "POST": # xxx tocheck - if authorities is empty, it's no use anyway # (users won't be able to validate the form anyway) # List local users in Manifold DB in order ot avoid duplicates user_query = Query().get("local:user").select("user_id", "email") list_users = execute_admin_query(self.request, user_query) reg_root_authority_hrn = request.POST.get("root_authority_hrn", "").lower() reg_site_name = request.POST.get("site_name", "") reg_site_authority = request.POST.get("site_authority", "").lower() reg_site_abbreviated_name = request.POST.get("site_abbreviated_name", "") reg_site_url = request.POST.get("site_url", "") reg_site_latitude = request.POST.get("site_latitude", "") reg_site_longitude = request.POST.get("site_longitude", "") reg_fname = request.POST.get("pi_first_name", "") reg_lname = request.POST.get("pi_last_name", "") reg_auth = reg_root_authority_hrn + "." + reg_site_authority reg_email = request.POST.get("pi_email", "").lower() reg_phone = request.POST.get("pi_phone", "") # prepare user_hrn split_email = reg_email.split("@")[0] split_email = split_email.replace(".", "_") user_hrn = reg_auth + "." + split_email + str(randint(1, 1000000)) UserModel = get_user_model() reg_address_line1 = request.POST.get("address_line1", "") reg_address_line2 = request.POST.get("address_line2", "") reg_address_line3 = request.POST.get("address_line3", "") reg_address_city = request.POST.get("address_city", "") reg_address_postalcode = request.POST.get("address_postalcode", "") reg_address_state = request.POST.get("address_state", "") reg_address_country = request.POST.get("address_country", "") # POST value validation if re.search(r"^[\w+\s.@+-]+$", reg_fname) == None: errors.append("First Name may contain only letters, numbers, spaces and @/./+/-/_ characters.") if re.search(r"^[\w+\s.@+-]+$", reg_lname) == None: errors.append("Last Name may contain only letters, numbers, spaces and @/./+/-/_ characters.") if re.search(r"^\w+$", reg_site_authority) == None: errors.append("Site Authority may contain only letters or numbers.") # checking in django_db !! if PendingUser.objects.filter(email__iexact=reg_email): errors.append("Email is pending for validation. Please provide a new email address.") if PendingAuthority.objects.filter(site_authority__iexact=reg_auth): errors.append("This site is pending for validation.") if PendingAuthority.objects.filter(site_name__iexact=reg_site_name): errors.append("This site is pending for validation.") if UserModel._default_manager.filter(email__iexact=reg_email): errors.append("This email is not usable. Please contact the administrator or try with another email.") for user_detail in list_users: if user_detail["email"] == reg_email: errors.append("Email already registered in Manifold. Please provide a new email address.") # XXX TODO: Factorize with portal/accountview.py # if 'generate' in request.POST['question']: from Crypto.PublicKey import RSA private = RSA.generate(1024) private_key = json.dumps(private.exportKey()) public = private.publickey() public_key = json.dumps(public.exportKey(format="OpenSSH")) # Saving to DB account_config = ( '{"user_public_key":' + public_key + ', "user_private_key":' + private_key + ', "user_hrn":"' + user_hrn + '"}' ) auth_type = "managed" public_key = public_key.replace('"', "") if not errors: reg_password = request.POST["pi_password"] a = PendingAuthority( site_name=reg_site_name, site_authority=reg_root_authority_hrn + "." + reg_site_authority, site_abbreviated_name=reg_site_abbreviated_name, site_url=reg_site_url, site_latitude=reg_site_latitude, site_longitude=reg_site_longitude, address_line1=reg_address_line1, address_line2=reg_address_line2, address_line3=reg_address_line3, address_city=reg_address_city, address_postalcode=reg_address_postalcode, address_state=reg_address_state, address_country=reg_address_country, authority_hrn=reg_root_authority_hrn, ) a.save() reg_password = request.POST["pi_password"] b = PendingUser( first_name=reg_fname, last_name=reg_lname, authority_hrn=reg_auth, email=reg_email, password=reg_password, keypair=account_config, pi=reg_auth, ) b.save() # saves the user to django auth_user table [needed for password reset] user = User.objects.create_user(reg_email, reg_email, reg_password) # creating user to manifold local:user user_config = ( '{"firstname":"' + reg_fname + '", "lastname":"' + reg_lname + '", "authority":"' + reg_auth + '"}' ) user_params = {"email": reg_email, "password": reg_password, "config": user_config, "status": 1} manifold_add_user(request, user_params) # creating local:account in manifold user_id = user_detail["user_id"] + 1 # the user_id for the newly created user in local:user account_params = { "platform_id": 5, "user_id": user_id, "auth_type": auth_type, "config": account_config, } manifold_add_account(request, account_params) # Send email ctx = { "first_name": reg_fname, "last_name": reg_lname, "authority_hrn": reg_auth, "email": reg_email, "user_hrn": user_hrn, "public_key": public_key, } recipients = authority_get_pi_emails(request, reg_auth) # We don't need to send this email to user. # it's for the PI only # if ctx['cc_myself']: # recipients.append(ctx['email']) msg = render_to_string("user_request_email.txt", ctx) send_mail( "Onelab New Authority request for %s submitted" % reg_email, msg, "*****@*****.**", recipients ) return render(request, "user_register_complete.html") template_env = { "topmenu_items": topmenu_items_live("join", page), "errors": errors, "pi_first_name": request.POST.get("pi_first_name", ""), "pi_last_name": request.POST.get("pi_last_name", ""), "pi_email": request.POST.get("pi_email", ""), "pi_phone": request.POST.get("pi_phone", ""), "pi_password": request.POST.get("pi_password", ""), "site_name": request.POST.get("site_name", ""), "site_authority": request.POST.get("site_authority", "").lower(), "site_abbreviated_name": request.POST.get("site_abbreviated_name", ""), "site_url": request.POST.get("site_url", ""), "site_latitude": request.POST.get("site_latitude", ""), "site_longitude": request.POST.get("site_longitude", ""), "address_line1": request.POST.get("address_line1", ""), "address_line2": request.POST.get("address_line2", ""), "address_line3": request.POST.get("address_line3", ""), "address_city": request.POST.get("address_city", ""), "address_postalcode": request.POST.get("address_postalcode", ""), "address_state": request.POST.get("address_state", ""), "address_country": request.POST.get("address_country", ""), "root_authority_hrn": request.POST.get("root_authority_hrn", "").lower(), "root_authorities": root_authorities, "authorities": authorities, } template_env.update(page.prelude_env()) return render(request, "join_view.html", template_env)
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 test_plugin_view(request): page = Page(request) page.expose_js_metadata() # variables that will get passed to this template template_env = {} slicename = 'ple.inria.heartbeat' main_query = Query.get('resource').filter_by( 'slice_hrn', '=', slicename).select(['network', 'type', 'hrn', 'hostname', 'sliver']) # without an querytable, this would use use : run_it=False as nothing would listen to the results page.enqueue_query( main_query, # run_it=False ) main_plugin = \ Stack ( page=page, title='thestack', togglable=True, domid='stack', sons=[ \ # make sure the 2 things work together Messages ( page=page, title="Transient Runtime messages", domid="messages-transient", levels='ALL', ), QueryTable ( page=page, title="Slice %s - checkboxes"%slicename, query=main_query, domid="querytable", checkboxes=True, togglable=True, ), Messages ( page=page, title="Inline Runtime messages", domid="messages", levels='ALL', togglable=True, transient=False, ), Raw ( page=page, title="issue messages", togglable=True, html=""" <input type="button" id="bouton" value="Click me" /> """, ), ]) page.add_js_chunks(""" function issue_debug() {console.log("issue_debug");messages.debug("issue_debug");}; $(function(){$("#bouton").click(issue_debug);}); """) # define 'unfold_main' to the template engine template_env['unfold_main'] = main_plugin.render(request) # more general variables expected in the template template_env['title'] = 'Single Plugin View' template_env['topmenu_items'] = topmenu_items_live('plugin', page) 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) return render_to_response('view-unfold1.html', template_env, context_instance=RequestContext(request))
def dashboard_view(request): page = Page(request) slices_query = Query.get("slice").select("slice_hrn") # old# # xxx filter : should filter on the slices the logged user can see # old# # we don't have the user's hrn yet # old# # in addition this currently returns all slices anyways # old# # filter = ... # old# sort='slice_hrn',) page.enqueue_query(slices_query) main_plugin = Stack( page=page, title="Putting stuff together", sons=[ QueryCode(page=page, title="Vizualize your query", query=slices_query, toggled=False), QuickFilter( # we play with this one for demo purposes in dashboard.css domid="myquickfilter", page=page, title="play with filters", criterias=quickfilter_criterias, toggled=False, ), SliceList( # setting visible attributes first page=page, title="Asynchroneous SliceList", header="slices list", with_datatables=False, # this is the query at the core of the slice list query=slices_query, ), ], ) # variables that will get passed to the view-unfold2.html template template_env = {} # define 'unfold_main' to the template engine template_env["unfold_main"] = main_plugin.render(request) # more general variables expected in the template template_env["title"] = "Test view for a full request cycle" # the menu items on the top template_env["topmenu_items"] = topmenu_items_live("dashboard", page) # so we can sho who is logged template_env["username"] = the_user(request) # ########## add another plugin with the same request, on the RHS pane # will show up in the right-hand side area named 'related' related_plugin = SliceList( page=page, title="Same request, other layout", domid="sidelist", with_datatables=True, header="paginated slices", # share the query query=slices_query, ) # likewise but on the side view template_env["unfold_margin"] = related_plugin.render(request) # add our own css in the mix # page.add_css_files ( 'css/dashboard.css') # 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) return render_to_response("view-unfold2.html", template_env, context_instance=RequestContext(request))
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_or_post(self, request, method): errors = [] # List authorities already in the Registry in order to avoid duplicates # Using cache manifold-tables to get the list of authorities faster authorities_query = Query.get('authority').select( 'name', 'authority_hrn') authorities = execute_admin_query(request, authorities_query) if authorities is not None: authorities = sorted(authorities) root_authorities = sorted( [a for a in authorities if '.' not in a['authority_hrn']]) page = Page(request) page.add_js_files( ["js/jquery.validate.js", "js/join.js", "js/jquery.qtip.min.js"]) page.add_css_files([ "css/onelab.css", "css/registration.css", "css/jquery.qtip.min.css" ]) page.add_css_files([ "https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" ]) if method == 'POST': # xxx tocheck - if authorities is empty, it's no use anyway # (users won't be able to validate the form anyway) # List local users in Manifold DB in order ot avoid duplicates user_query = Query().get('local:user').select('user_id', 'email') list_users = execute_admin_query(self.request, user_query) reg_root_authority_hrn = request.POST.get('root_authority_hrn', '').lower() reg_site_name = request.POST.get('site_name', '') reg_site_authority = request.POST.get('site_authority', '').lower() reg_site_abbreviated_name = request.POST.get( 'site_abbreviated_name', '').lower() reg_site_url = request.POST.get('site_url', '') reg_site_latitude = request.POST.get('site_latitude', '') reg_site_longitude = request.POST.get('site_longitude', '') reg_fname = request.POST.get('pi_first_name', '') reg_lname = request.POST.get('pi_last_name', '') reg_auth = 'onelab.' + reg_site_abbreviated_name reg_email = request.POST.get('pi_email', '').lower() reg_phone = request.POST.get('pi_phone', '') #prepare user_hrn split_email = reg_email.split("@")[0] split_email = split_email.replace(".", "_") # Replace + by _ => more convenient for testing and validate with a real email split_email = split_email.replace("+", "_") user_hrn = reg_auth + '.' + split_email UserModel = get_user_model() reg_address_line1 = request.POST.get('address_line1', '') reg_address_line2 = request.POST.get('address_line2', '') reg_address_line3 = request.POST.get('address_line3', '') reg_address_city = request.POST.get('address_city', '') reg_address_postalcode = request.POST.get('address_postalcode', '') reg_address_state = request.POST.get('address_state', '') reg_address_country = request.POST.get('address_country', '') #POST value validation if (re.search(r'^[\w+\s.@+-]+$', reg_fname) == None): errors.append( 'First Name may contain only letters, numbers, spaces and @/./+/-/_ characters.' ) if (re.search(r'^[\w+\s.@+-]+$', reg_lname) == None): errors.append( 'Last Name may contain only letters, numbers, spaces and @/./+/-/_ characters.' ) if (re.search(r'^[A-Za-z0-9_ ]*$', reg_site_name) == None): errors.append( 'Name of organization may contain only letters, numbers, and underscore.' ) if (re.search(r'^[A-Za-z ]*$', reg_address_city) == None): errors.append('City may contain only letters.') if (re.search(r'^[A-Za-z ]*$', reg_address_country) == None): errors.append('Country may contain only letters.') if (re.search(r'^[A-Za-z0-9]*$', reg_site_abbreviated_name) == None): errors.append( 'Shortname may contain only letters and numbers') if (re.search(r'^[0-9]*$', reg_phone) == None): errors.append('Phone number may contain only numbers.') #if (re.search(r'^\w+$', reg_site_authority) == None): # errors.append('Site Authority may contain only letters or numbers.') # checking in django_db !! if PendingUser.objects.filter(email__iexact=reg_email): errors.append( 'Email is pending for validation. Please provide a new email address.' ) if PendingAuthority.objects.filter( site_abbreviated_name__iexact=reg_site_abbreviated_name): errors.append('This site is pending for validation.') #if PendingAuthority.objects.filter(site_name__iexact=reg_site_name): # errors.append('This site is pending for validation.') if UserModel._default_manager.filter(email__iexact=reg_email): errors.append( 'This email is not usable. Please contact the administrator or try with another email.' ) for user_detail in list_users: if user_detail['email'] == reg_email: errors.append( 'Email already registered in Manifold. Please provide a new email address.' ) # XXX TODO: Factorize with portal/accountview.py # XXX TODO: Factorize with portal/registrationview.py # XXX TODO: Factorize with portal/joinview.py # if 'generate' in request.POST['question']: from Crypto.PublicKey import RSA private = RSA.generate(1024) private_key = private.exportKey() public_key = private.publickey().exportKey(format='OpenSSH') # Saving to DB auth_type = 'managed' if not errors: reg_password = request.POST['pi_password'] a = PendingAuthority( site_name=reg_site_name, site_authority=reg_auth, site_abbreviated_name=reg_site_abbreviated_name, site_url=reg_site_url, site_latitude=reg_site_latitude, site_longitude=reg_site_longitude, address_line1= reg_email, # XXX field name must be renamed. Email needed 4 rejection email. address_line2=reg_address_line2, address_line3=reg_address_line3, address_city=reg_address_city, address_postalcode=reg_address_postalcode, address_state=reg_address_state, address_country=reg_address_country, authority_hrn=reg_root_authority_hrn, ) a.save() reg_password = request.POST['pi_password'] salt = randint(1, 100000) if request.is_secure(): current_site = 'https://' else: current_site = 'http://' current_site += request.META['HTTP_HOST'] email_hash = md5(str(salt) + reg_email).hexdigest() user_request = { 'first_name': reg_fname, 'last_name': reg_lname, 'organization': reg_site_name, 'authority_hrn': reg_auth, 'email': reg_email, 'password': reg_password, 'public_key': public_key, 'private_key': private_key, 'current_site': current_site, 'email_hash': email_hash, 'user_hrn': user_hrn, 'pi': [reg_auth], 'auth_type': 'managed', 'validation_link': current_site + '/portal/email_activation/' + email_hash } create_pending_user(request, user_request, user_detail) # saves the user to django auth_user table [needed for password reset] #user = User.objects.create_user(reg_email, reg_email, reg_password) #creating user to manifold local:user #user_config = '{"first_name":"'+ reg_fname + '", "last_name":"'+ reg_lname + '", "authority_hrn":"'+ reg_auth + '"}' #user_params = {'email': reg_email, 'password': reg_password, 'config': user_config, 'status': 1} #manifold_add_user(request,user_params) #creating local:account in manifold #user_id = user_detail['user_id']+1 # the user_id for the newly created user in local:user #account_params = {'platform_id': 5, 'user_id': user_id, 'auth_type': auth_type, 'config': account_config} #manifold_add_account(request,account_params) # Send email try: ctx = { 'site_name': reg_site_name, 'authority_hrn': reg_root_authority_hrn + '.' + reg_site_authority, 'site_abbreviated_name': reg_site_abbreviated_name, 'site_url': reg_site_url, 'address_city': reg_address_city, 'address_country': reg_address_country, 'first_name': reg_fname, 'last_name': reg_lname, 'authority_hrn': reg_auth, 'email': reg_email, 'user_hrn': user_hrn, 'public_key': public_key, } #recipients = authority_get_pi_emails(request,reg_auth) self.template_name = 'authority_request_email.html' html_content = render_to_string(self.template, ctx) self.template_name = 'authority_request_email.txt' text_content = render_to_string(self.template, ctx) self.template_name = 'authority_request_email_subject.txt' subject = render_to_string(self.template, ctx) subject = subject.replace('\n', '') #theme.template_name = 'email_default_sender.txt' #sender = render_to_string(theme.template, ctx) #sender = sender.replace('\n', '') sender = reg_email msg = EmailMultiAlternatives(subject, text_content, sender, ['*****@*****.**']) msg.attach_alternative(html_content, "text/html") msg.send() except Exception, e: logger.error( "Failed to send email, please check the mail templates and the SMTP configuration of your server" ) import traceback logger.error(traceback.format_exc()) self.template_name = 'join_complete.html' # log institution activity activity.institution.joined(self.request) return render(request, self.template, {'theme': self.theme})
from manifold.core.router import Router from manifold.core.query import Query from config import auth import sys, pprint def print_err(err): print '-' * 80 print 'Exception', err['code'], 'raised by', err['origin'], ':', err[ 'description'] for line in err['traceback'].split("\n"): print "\t", line print '' query = Query.get('local:session') ret = Router().forward(query, user=Auth(auth).check()) if ret['code'] != 0: if isinstance(ret['description'], list): # We have a list of errors for err in ret['description']: print_err(err) ret = ret['value'] print "===== RESULTS =====" for r in ret: pprint.pprint(r)
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) ) # -------------------------------------------------------------------------- # 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(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' # 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('Slice', page.request) # so we can sho who is logged template_env['username'] = UserAccessProfile(request).username # 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_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 dashboard_view(request): page = Page(request) slices_query = Query.get('slice').select('slice_hrn') #old# # xxx filter : should filter on the slices the logged user can see #old# # we don't have the user's hrn yet #old# # in addition this currently returns all slices anyways #old# # filter = ... #old# sort='slice_hrn',) page.enqueue_query(slices_query) main_plugin = Stack( page=page, title="Putting stuff together", sons=[ QueryCode( page=page, title="Vizualize your query", query=slices_query, toggled=False, ), QuickFilter( # we play with this one for demo purposes in dashboard.css domid='myquickfilter', page=page, title='play with filters', criterias=quickfilter_criterias, toggled=False, ), SliceList( # setting visible attributes first page=page, title='Asynchroneous SliceList', header='slices list', with_datatables=False, # this is the query at the core of the slice list query=slices_query, ), ]) # variables that will get passed to the view-unfold2.html template template_env = {} # define 'unfold_main' to the template engine template_env['unfold_main'] = main_plugin.render(request) # more general variables expected in the template template_env['title'] = 'Test view for a full request cycle' # the menu items on the top template_env['topmenu_items'] = topmenu_items_live('dashboard', page) # so we can sho who is logged template_env['username'] = the_user(request) # ########## add another plugin with the same request, on the RHS pane # will show up in the right-hand side area named 'related' related_plugin = SliceList( page=page, title='Same request, other layout', domid='sidelist', with_datatables=True, header='paginated slices', # share the query query=slices_query, ) # likewise but on the side view template_env['unfold_margin'] = related_plugin.render(request) # add our own css in the mix #page.add_css_files ( 'css/dashboard.css') # 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) return render_to_response('view-unfold2.html', template_env, context_instance=RequestContext(request))
def get_user_config(self, user, platform): # all are dict platform_name = platform['platform'] platform_id = platform['platform_id'] auth_type = platform.get('auth_type', None) if not auth_type: Log.warning("'auth_type' is not set in platform = %s" % platform_name) return None # XXX platforms might have multiple auth types (like pam) # XXX we should refer to storage if auth_type in ["none", "default"]: user_config = {} # For default, take myslice account elif auth_type == 'user': if not user: raise Exception, "Cannot use auth_type user when no user is configured" user_id = user['user_id'] if user else None # User account information query_accounts = Query.get('local:account').filter_by('user_id', '==', user_id).filter_by('platform_id', '==', platform_id) accounts = self.execute_local_query(query_accounts) if accounts: account = accounts[0] user_config = account.get('config', None) if user_config: user_config = json.loads(user_config) # XXX This should disappear with the merge with router-v2 if account['auth_type'] == 'reference': ref_platform_name = user_config['reference_platform'] query_ref_platform = Query.get('local:platform').filter_by('platform', '==', ref_platform_name) ref_platforms = self.execute_local_query(query_ref_platform) if not ref_platforms: raise Exception, 'Cannot find reference platform %s for platform %s' % (platform_name, ref_platform_name) ref_platform = ref_platforms[0] query_ref_account = Query.get('local:account').filter_by('user_id', '==', user_id).filter_by('platform_id', '==', ref_platform['platform_id']) ref_accounts = self.execute_local_query(query_ref_account) if not ref_accounts: raise Exception, 'Cannot find account information for reference platform %s' % ref_platform_name ref_account = ref_accounts[0] user_config = ref_account.get('config', None) if user_config: user_config = json.loads(user_config) else: user_config = {} else: raise ValueError("This 'auth_type' not supported: %s" % auth_type) return user_config
def main(): argc = len(sys.argv) program_name = sys.argv[0] with Router() as router: ret_gateways = router.forward( Query.get('local:gateway').select('name')) if ret_gateways['code'] != 0: print "W: Could not contact the Manifold server to list available gateways. Check disabled." supported_gateways = None else: gateways = ret_gateways['value'] if not gateways: print "W: Could not contact the Manifold server to list available gateways. Check disabled." supported_gateways = None else: supported_gateways = [gw['name'] for gw in gateways] # Check number of arguments if argc not in [6, 7]: print >> sys.stderr, "%s: Invalid number of arguments (is equal to %d, should be equal to 6 or 7) " % ( program_name, argc) usage(supported_gateways) sys.exit(1) name, longname, gateway, auth_type, config = sys.argv[1:6] if argc == 7: disabled = sys.argv[6] else: disabled = "1" # Check NAME if name != name.lower(): print >> sys.stderr, "%s: Invalid NAME parameter (is '%s', should be '%s')" % ( program_name, name, name.lower()) usage(supported_gateways) sys.exit(1) # Check GATEWAY if supported_gateways and gateway not in supported_gateways: print >> sys.stderr, "%s: Invalid GATEWAY parameter (is '%s', should be in '%s')" % ( program_name, gateway, "', '".join(supported_gateways)) usage(supported_gateways) sys.exit(1) # Check AUTH_TYPE supported_auth_type = ["none", "default", "user"] if auth_type not in supported_auth_type: print >> sys.stderr, "%s: Invalid AUTH_TYPE parameter (is '%s', should be in '%s')" % ( program_name, auth_type, "', '".join(supported_auth_type)) usage(supported_gateways) sys.exit(1) # Check DISABLED if argc == 7: supported_disabled = [ "False", "FALSE", "NO", "0", "True", "TRUE", "YES", "1" ] if str(sys.argv[6]) not in supported_disabled: print >> sys.stderr, "%s: Invalid DISABLED parameter (is '%s', should be in '%s')" % ( program_name, disabled, "', '".join(supported_disabled)) usage(supported_gateways) sys.exit(1) disabled = str(sys.argv[6]) in ["False", "FALSE", "NO", "0"] # why 2 different fields for the same config ? platform_params = { 'platform': name, 'platform_longname': longname, 'gateway_type': gateway, 'auth_type': auth_type, 'config': config, 'disabled': disabled } router.forward(Query.create('local:platform').set(platform_params))
def manifold_details(url, email, password, logger): """ return a tuple with (session, auth, person, slices) associated with these credentials at the manifold backend * session : the session with the manifold API * auth : ready-to use auth to talk to the API again * user : a flat structure with at least the following keys * email, hrn * firstname, lastname in case of failure, return tuple with same size with only None's """ failure_result = None, None, None auth = { 'AuthMethod': 'password', 'Username': email, 'AuthString': password } api = ManifoldAPI(url, auth) sessions_result = api.forward(Query.create('local:session').to_dict()) logger.debug("sessions_result = ", sessions_result) sessions = sessions_result.ok_value() if not sessions: logger.error("GetSession failed: {}".format(sessions_result.error())) return failure_result session = sessions[0] # Change to session authentication api.auth = {'AuthMethod': 'session', 'session': session['session']} # Get account details persons_result = api.forward(Query.get('local:user').to_dict()) logger.debug("persons_result=", persons_result) persons = persons_result.ok_value() if not persons: logger.error("GetPersons failed: {}".format(persons_result.error())) return failure_result person = persons[0] logger.debug("PERSON : {}".format(person)) # get related slices query = Query.get('myslice:user').filter_by( 'user_hrn', '==', '$user_hrn').select(['user_hrn', 'slices']) mf_result = api.forward(query.to_dict()) logger.debug("mf_result=", mf_result) # xxx - needs more work # for now if hrn is not properly filled we want to proceed # however this is wrong; it can happen for example # when credentials upstream have expired and # need to be uploaded again to the manifold end # so it would be best to refuse logging in and to provide this kind of hint # we don't report login_message properly yet though... hrn = "<unknown_hrn>" try: # xxx use ManifoldResult ? # this is a list of dicts that have a 'slices' field val_d_s = mf_result['value'] # in fact there is only one of these dicts because we have specified # myslice:user hrns = [val_d['user_hrn'] for val_d in val_d_s] if hrns: hrn = hrns[0] except Exception as e: logger.exception("mfdetails: Could not retrieve user's slices") # looks like it's useless # # add hrn in person # person['hrn'] = hrn # synthesize our own user structure import json person_config = json.loads(person['config']) user_details = { 'email': person['email'], 'hrn': hrn, 'firstname': person_config['firstname'], 'lastname': person_config['lastname'], } return session, auth, user_details
#! -*- coding: utf-8 -*- from manifold.auth import * from manifold.core.router import Router from manifold.core.query import Query from config import auth import sys, pprint def print_err(err): print '-'*80 print 'Exception', err['code'], 'raised by', err['origin'], ':', err['description'] for line in err['traceback'].split("\n"): print "\t", line print '' query = Query.get('local:user') ret = Router().forward(query, user=Auth(auth).check()) if ret['code'] != 0: if isinstance(ret['description'], list): # We have a list of errors for err in ret['description']: print_err(err) ret = ret['value'] print "===== RESULTS =====" for r in ret: pprint.pprint(r)
def wrap(source, args): token = yield SFATokenMgr().get_token(self.interface) args = (name, ) + args self.callRemote(*args).addCallbacks(proxy_success_cb, proxy_error_cb) ReactorThread().callInReactor(wrap, self, args) return d return _missing if __name__ == '__main__': query = Query.get('local:platform').select('platform') proxy = Proxy('https://localhost:7080/', allowNone=True, useDateTime=False) if USE_CLIENT_CERT: annotations = {} # We need this to define the private key and certificate (GID) to use proxy.setSSLClientContext(CtxFactory()) else: annotations = { 'authentication': { 'AuthMethod': 'password', 'Username': '******', 'AuthString': 'demo' } }
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_context_data(self, **kwargs): pi = "" # We might have slices on different registries with different user accounts # We note that this portal could be specific to a given registry, to which we register users, but i'm not sure that simplifies things # Different registries mean different identities, unless we identify via SFA HRN or have associated the user email to a single hrn #messages.info(self.request, 'You have logged in') page = Page(self.request) ctx_my_authorities = {} ctx_delegation_authorities = {} ctx_sub_authorities = {} dest = {} # The user need to be logged in if the_user(self.request): # Who can a PI validate: # His own authorities + those he has credentials for. # In MySlice we need to look at credentials also. # XXX This will have to be asynchroneous. Need to implement barriers, # for now it will be sufficient to have it working statically # get user_id to later on query accounts # XXX Having real query plan on local tables would simplify all this # XXX $user_email is still not available for local tables #user_query = Query().get('local:user').filter_by('email', '==', '$user_email').select('user_id') user_query = Query().get('local:user').filter_by( 'email', '==', the_user(self.request)).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) #print "=" * 80 #print user_accounts #print "=" * 80 for user_account in user_accounts: logger.debug("USER ACCOUNT {}".format(user_account)) if user_account['auth_type'] == 'reference': continue # we hardcoded the myslice platform... config = json.loads(user_account['config']) creds = [] logger.debug("CONFIG KEYS {}".format(config.keys())) if 'authority_credentials' in config: logger.debug("*** AC {}".format( config['authority_credentials'].keys())) for authority_hrn, credential in config[ 'authority_credentials'].items(): #if credential is not expired: credential_authorities.add(authority_hrn) #else # credential_authorities_expired.add(authority_hrn) if 'delegated_authority_credentials' in config: logger.debug("*** DAC {}".format( config['delegated_authority_credentials'].keys())) for authority_hrn, credential in config[ 'delegated_authority_credentials'].items(): #if credential is not expired: credential_authorities.add(authority_hrn) #else # credential_authorities_expired.add(authority_hrn) logger.debug( 'credential_authorities = {}'.format(credential_authorities)) logger.debug('credential_authorities_expired = {}'.format( credential_authorities_expired)) # # Using cache manifold-tables to get the list of authorities faster # all_authorities_query = Query.get('authority').select('name', 'authority_hrn') # all_authorities = execute_query(self.request, all_authorities_query) # ** 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('pi_authorities') 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') # TODO: exception if no parent_authority # try: # for pa in pi_authorities_tmp: # pi_authorities |= set(pa['pi_authorities']) # except: # # include all sub-authorities of the PI # # if PI on ple, include all sub-auths ple.upmc, ple.inria and so on... # pi_subauthorities = set() # for authority in all_authorities: # authority_hrn = authority['authority_hrn'] # for my_authority in pi_authorities: # if authority_hrn.startswith(my_authority) and authority_hrn not in pi_subauthorities: # pi_subauthorities.add(authority_hrn) #print "pi_authorities =", pi_authorities #print "pi_subauthorities =", pi_subauthorities # My authorities + I have a credential 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 #print "pi_credential_authorities =", pi_credential_authorities #print "pi_no_credential_authorities =", pi_no_credential_authorities #print "pi_expired_credential_authorities =", pi_expired_credential_authorities #print "pi_delegation_credential_authorities = ", pi_delegation_credential_authorities #print "pi_delegation_expired_authorities = ", pi_delegation_expired_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 #print "--" #print "pi_my_authorities = ", pi_my_authorities #print "pi_delegation_authorities = ", pi_delegation_authorities #print "pi_subauthorities = ", pi_subauthorities # Summary all queried_pending_authorities = pi_my_authorities | pi_delegation_authorities #| pi_subauthorities #print "----" #print "queried_pending_authorities = ", queried_pending_authorities # iterate on the requests and check if the authority matches a prefix startswith an authority on which the user is PI requests = get_requests() # requests = get_requests(queried_pending_authorities) for request in requests: auth_hrn = request['authority_hrn'] for my_auth in pi_my_authorities: if auth_hrn.startswith(my_auth): dest = ctx_my_authorities request['allowed'] = 'allowed' for my_auth in pi_delegation_authorities: if auth_hrn.startswith(my_auth): dest = ctx_delegation_authorities request['allowed'] = 'allowed' if auth_hrn in pi_expired_credential_authorities: request['allowed'] = 'expired' if 'allowed' not in request: request['allowed'] = 'denied' #print "authority for this request", auth_hrn # if auth_hrn in pi_my_authorities: # dest = ctx_my_authorities # # # define the css class # if auth_hrn in pi_credential_authorities: # request['allowed'] = 'allowed' # elif auth_hrn in pi_expired_credential_authorities: # request['allowed'] = 'expired' # else: # pi_no_credential_authorities # request['allowed'] = 'denied' # # elif auth_hrn in pi_delegation_authorities: # dest = ctx_delegation_authorities # # if auth_hrn in pi_delegation_credential_authorities: # request['allowed'] = 'allowed' # else: # pi_delegation_expired_authorities # request['allowed'] = 'expired' # # elif auth_hrn in pi_subauthorities: # dest = ctx_sub_authorities # # if auth_hrn in pi_subauthorities: # request['allowed'] = 'allowed' # else: # pi_delegation_expired_authorities # request['allowed'] = 'denied' # # else: # continue if not auth_hrn in dest: dest[auth_hrn] = [] dest[auth_hrn].append(request) context = super(ValidatePendingView, self).get_context_data(**kwargs) logger.debug("testing") logger.debug(ctx_my_authorities) 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'] = the_user(self.request) 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
def get_or_post (self, request, method): errors = [] # Using cache manifold-tables to get the list of authorities faster authorities_query = Query.get('authority').select('name', 'authority_hrn') #onelab_enabled_query = Query.get('local:platform').filter_by('platform', '==', 'ple').filter_by('disabled', '==', 'False') #onelab_enabled = not not execute_admin_query(request, onelab_enabled_query) #if onelab_enabled: if True: print "ONELAB ENABLED" #authorities_query = Query.get('ple:authority').select('name', 'authority_hrn').filter_by('authority_hrn', 'included', ['ple.inria', 'ple.upmc', 'ple.ibbtple', 'ple.nitos']) # Now using Cache else: print "FIREXP ENABLED" authorities = execute_admin_query(request, authorities_query) if authorities is not None: authorities = sorted(authorities) # xxx tocheck - if authorities is empty, it's no use anyway # (users won't be able to validate the form anyway) page = Page(request) page.add_js_files ( [ "js/jquery.validate.js", "js/my_account.register.js" ] ) page.add_css_files ( [ "css/onelab.css", "css/registration.css" ] ) page.add_css_files ( [ "http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" ] ) print 'registration view, method',method user_query = Query().get('local:user').select('user_id','email') user_details = execute_admin_query(self.request, user_query) if method == 'POST': # We shall use a form here #get_email = PendingUser.objects.get(email) reg_fname = request.POST.get('firstname', '') reg_lname = request.POST.get('lastname', '') #reg_aff = request.POST.get('affiliation','') reg_auth = request.POST.get('authority_hrn', '') #reg_login = request.POST.get('login', '') reg_email = request.POST.get('email','').lower() #prepare user_hrn split_email = reg_email.split("@")[0] split_email = split_email.replace(".", "_") user_hrn = reg_auth + '.' + split_email+ str(randint(1,1000000)) UserModel = get_user_model() #POST value validation if (re.search(r'^[\w+\s.@+-]+$', reg_fname)==None): errors.append('First Name may contain only letters, numbers, spaces and @/./+/-/_ characters.') if (re.search(r'^[\w+\s.@+-]+$', reg_lname) == None): errors.append('Last Name may contain only letters, numbers, spaces and @/./+/-/_ characters.') # checking in django_db !! if PendingUser.objects.filter(email__iexact=reg_email): errors.append('Email is pending for validation. Please provide a new email address.') if UserModel._default_manager.filter(email__iexact=reg_email): errors.append('This email is not usable. Please contact the administrator or try with another email.') for user_detail in user_details: if user_detail['email']==reg_email: errors.append('Email already registered in Manifold. Please provide a new email address.') # XXX TODO: Factorize with portal/accountview.py if 'generate' in request.POST['question']: from Crypto.PublicKey import RSA private = RSA.generate(1024) private_key = json.dumps(private.exportKey()) public = private.publickey() public_key = json.dumps(public.exportKey(format='OpenSSH')) # # Generate public and private keys using SFA Library # from sfa.trust.certificate import Keypair # k = Keypair(create=True) # public_key = k.get_pubkey_string() # private_key = k.as_pem() # private_key = ''.join(private_key.split()) # public_key = "ssh-rsa " + public_key # Saving to DB account_config = '{"user_public_key":'+ public_key + ', "user_private_key":'+ private_key + ', "user_hrn":"'+ user_hrn + '"}' auth_type = 'managed' #keypair = re.sub("\r", "", keypair) #keypair = re.sub("\n", "\\n", keypair) #keypair = keypair.rstrip('\r\n') #keypair = ''.join(keypair.split()) #for sending email: removing existing double qoute public_key = public_key.replace('"', ''); else: up_file = request.FILES['user_public_key'] file_content = up_file.read() file_name = up_file.name file_extension = os.path.splitext(file_name)[1] allowed_extension = ['.pub','.txt'] if file_extension in allowed_extension and re.search(r'ssh-rsa',file_content): account_config = '{"user_public_key":"'+ file_content + '", "user_hrn":"'+ user_hrn +'"}' account_config = re.sub("\r", "", account_config) account_config = re.sub("\n", "\\n",account_config) account_config = ''.join(account_config.split()) auth_type = 'user' # for sending email public_key = file_content public_key = ''.join(public_key.split()) else: errors.append('Please upload a valid RSA public key.') #b = PendingUser(first_name=reg_fname, last_name=reg_lname, affiliation=reg_aff, # email=reg_email, password=request.POST['password'], keypair=keypair) #b.save() #saving to django db 'portal_pendinguser' table if not errors: b = PendingUser( first_name = reg_fname, last_name = reg_lname, #affiliation = reg_aff, authority_hrn = reg_auth, #login = reg_login, email = reg_email, password = request.POST['password'], keypair = account_config, pi = '', ) b.save() # saves the user to django auth_user table [needed for password reset] user = User.objects.create_user(reg_email, reg_email, request.POST['password']) #creating user to manifold local:user user_config = '{"firstname":"'+ reg_fname + '", "lastname":"'+ reg_lname + '", "authority":"'+ reg_auth + '"}' user_params = {'email': reg_email, 'password': request.POST['password'], 'config': user_config, 'status': 1} manifold_add_user(request,user_params) #creating local:account in manifold user_id = user_detail['user_id']+1 # the user_id for the newly created user in local:user account_params = {'platform_id': 5, 'user_id': user_id, 'auth_type': auth_type, 'config': account_config} manifold_add_account(request,account_params) # Send email ctx = { 'first_name' : reg_fname, 'last_name' : reg_lname, 'authority_hrn' : reg_auth, 'email' : reg_email, 'user_hrn' : user_hrn, 'public_key' : public_key, } recipients = authority_get_pi_emails(request,reg_auth) # backup email: if authority_get_pi_emails fails recipients.append('*****@*****.**') msg = render_to_string('user_request_email.txt', ctx) send_mail("Onelab New User request for %s submitted"%reg_email, msg, '*****@*****.**', recipients) return render(request, 'user_register_complete.html') template_env = { 'topmenu_items': topmenu_items_live('Register', page), 'errors': errors, 'firstname': request.POST.get('firstname', ''), 'lastname': request.POST.get('lastname', ''), #'affiliation': request.POST.get('affiliation', ''), 'authority_hrn': request.POST.get('authority_hrn', ''), 'email': request.POST.get('email', ''), 'password': request.POST.get('password', ''), 'authorities': authorities, } template_env.update(page.prelude_env ()) return render(request, 'registration_view.html',template_env)
def print_err(err): print '-' * 80 print 'Exception', err['code'], 'raised by', err['origin'], ':', err[ 'description'] for line in err['traceback'].split("\n"): print "\t", line print '' slicename = sys.argv[1] if len(sys.argv) > 2 else DEFAULT_SLICE query = Query.get('slice').filter_by('slice_hrn', '==', slicename).select([ 'slice_hrn', 'resource.resource_hrn', 'resource.hostname', 'resource.type', 'resource.authority', 'user.user_hrn', # 'application.measurement_point.counter' ]) with Router() as router: ret = router.forward(query, user=Auth(auth).check()) if ret['code'] != 0: if isinstance(ret['description'], list): # We have a list of errors for err in ret['description']: print_err(err) ret = ret['value']
def test_plugin_view (request): page = Page(request) page.expose_js_metadata() # variables that will get passed to this template template_env = {} slicename='ple.inria.heartbeat' main_query = Query.get('resource').filter_by('slice_hrn', '=', slicename).select(['network','type','hrn','hostname','sliver']) # without an querytable, this would use use : run_it=False as nothing would listen to the results page.enqueue_query (main_query, # run_it=False ) main_plugin = \ Stack ( page=page, title='thestack', togglable=True, domid='stack', sons=[ \ # make sure the 2 things work together Messages ( page=page, title="Transient Runtime messages", domid="messages-transient", levels='ALL', ), QueryTable ( page=page, title="Slice %s - checkboxes"%slicename, query=main_query, domid="querytable", checkboxes=True, togglable=True, ), Messages ( page=page, title="Inline Runtime messages", domid="messages", levels='ALL', togglable=True, transient=False, ), Raw ( page=page, title="issue messages", togglable=True, html=""" <input type="button" id="bouton" value="Click me" /> """, ), ]) page.add_js_chunks ( """ function issue_debug() {console.log("issue_debug");messages.debug("issue_debug");}; $(function(){$("#bouton").click(issue_debug);}); """) # define 'unfold_main' to the template engine template_env [ 'unfold_main' ] = main_plugin.render(request) # more general variables expected in the template template_env [ 'title' ] = 'Single Plugin View' template_env [ 'topmenu_items' ] = topmenu_items_live('plugin', page) 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) return render_to_response ('view-unfold1.html',template_env, context_instance=RequestContext(request))