Merge branch 'master' of ssh://git.onelab.eu/git/myslice
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 6 Dec 2013 16:20:30 +0000 (17:20 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 6 Dec 2013 16:20:30 +0000 (17:20 +0100)
1  2 
manifold/manifoldapi.py
portal/sliceview.py

diff --combined manifold/manifoldapi.py
@@@ -9,29 -9,16 +9,29 @@@ from manifold.core.result_value import 
  
  debug=False
  debug=True
 +debug_deep=False
 +#debug_deep=True
  
 +########## ugly stuff for hopefully nicer debug messages
  def mytruncate (obj, l):
      # we will add '..' 
      l1=l-2
      repr="%s"%obj
      return (repr[:l1]+'..') if len(repr)>l1 else repr
  
 +from time import time, gmtime, strftime
 +from math import trunc
 +def mytime (start=None):
 +    gm=gmtime()
 +    t=time()
 +    msg=strftime("%H:%M:%S-", gmtime())+"%03d"%((t-trunc(t))*1000)
 +    if start is not None: msg += " (%03fs)"%(t-start)
 +    return t,msg
 +##########
 +
  class ManifoldAPI:
  
 -    def __init__(self, auth=None, cainfo=None):
 +    def __init__ (self, auth=None, cainfo=None):
          
          self.auth = auth
          self.cainfo = cainfo
                  else:           print '+++',k,':',mytruncate (v,30)
          else:                                 print "[dont know how to display result] %s"%result
  
 +    # how to display a call
 +    def _repr_query (self,methodName, query):
 +        try:    action=query['action']
 +        except: action="???"
 +        try:    subject=query['object']
 +        except: subject="???"
 +        # most of the time, we run 'forward'
 +        if methodName=='forward':       return "forward(%s(%s))"%(action,subject)
 +        else:                           return "%s(%s)"%(action,subject)
 +
      # xxx temporary code for scaffolding a ManifolResult on top of an API that does not expose error info
      # as of march 2013 we work with an API that essentially either returns the value, or raises 
      # an xmlrpclib.Fault exception with always the same 8002 code
      # a SESSION_EXPIRED code
      def __getattr__(self, methodName):
          def func(*args, **kwds):
 -            # how to display a call
 -            def repr ():
 -                # most of the time, we run 'forward'
 -                if methodName=='forward':
 -                    try:    action="forward(%s)"%args[0]['action']
 -                    except: action="forward(??)"
 -                else: action=methodName
 -                return action
 +            # shorthand
 +            def repr(): return self._repr_query (methodName, args[0])
              try:
                  if debug:
 -                    print "====> ManifoldAPI.%s"%repr(),"url",self.url
 +                    start,msg = mytime()
 +                    print "====>",msg,"ManifoldAPI.%s"%repr(),"url",self.url
                      # No password in the logs
                      logAuth = copy.copy(self.auth)
                      for obfuscate in ['Authring','session']: 
                          if obfuscate in logAuth:  logAuth[obfuscate]="XXX"
 -                    print "=> auth",logAuth
 -                    print "=> args",args,"kwds",kwds
 +                    if debug_deep: print "=> auth",logAuth
 +                    if debug_deep: print "=> args",args,"kwds",kwds
                  annotations = {
                      'authentication': self.auth
                  }
                  if debug:
                      print '<= result=',
                      self._print_result(result)
 -                    print '<==== backend call %s returned'%(repr()),
 +                    end,msg = mytime(start)
 +                    print "<====",msg,"backend call %s returned"%(repr())
  
                  return ResultValue(**result)
  
@@@ -132,6 -113,8 +132,8 @@@ def _execute_query(request, query, mani
      print "-"*80
      result = manifold_api.forward(query.to_dict())
      if result['code'] == 2:
+         # XXX only if we know it is the issue
+         del request.session['manifold']
          raise Exception, 'Error running query: %r' % result
      
      if result['code'] == 1:
diff --combined portal/sliceview.py
@@@ -12,16 -12,12 +12,16 @@@ from plugins.raw                     im
  from plugins.stack                   import Stack
  from plugins.tabs                    import Tabs
  from plugins.querytable              import QueryTable 
 +from plugins.querygrid               import QueryGrid
  from plugins.queryupdater            import QueryUpdater
  from plugins.googlemap               import GoogleMap
  from plugins.senslabmap              import SensLabMap
  from plugins.scheduler               import Scheduler
  from plugins.querycode               import QueryCode
 -from plugins.query_editor            import QueryEditor
 +# Thierry
 +# stay away from query editor for now as it seems to make things go very slow
 +# see https://lists.myslice.info/pipermail/devel-myslice/2013-December/000221.html 
 +#from plugins.query_editor            import QueryEditor
  from plugins.active_filters          import ActiveFilters
  from plugins.quickfilter             import QuickFilter
  from plugins.messages                import Messages
@@@ -38,9 -34,6 +38,9 @@@ do_query_users=Fals
  #do_query_leases=True
  do_query_leases=False
  
 +insert_grid=False
 +#insert_grid=True
 +
  insert_messages=False
  #insert_messages=True
  
@@@ -69,7 -62,7 +69,7 @@@ class SliceView (LoginRequiredAutoLogou
          main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
          main_query.select(
                  'slice_hrn',
-                 'resource.hrn', 'resource.hostname', 'resource.type', 
+                 'resource.hrn', 'resource.urn', 'resource.hostname', 'resource.type', 
                  'resource.network_hrn',
                  'lease.urn',
                  'user.user_hrn',
@@@ -77,7 -70,7 +77,7 @@@
          )
          # for internal use in the querytable plugin;
          # needs to be a unique column present for each returned record
-         main_query_key = 'hrn'
+         #main_query_key = 'hrn'
      
          query_resource_all = Query.get('resource').select(resource_fields)
          if do_query_users:
          # --------------------------------------------------------------------------
          # Filter Resources
         
 -        filter_query_editor = QueryEditor(
 -            page  = page,
 -            query = sq_resource, 
 -            query_all = query_resource_all,
 -            title = "Select Columns",
 -            domid = 'select-columns',
 -            )
 +# 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,
              page                = page,
              title               = 'Filter Resources',
              domid               = 'filters',
 -            sons                = [filter_query_editor, filter_active_filters],
 +            sons                = [# filter_query_editor, 
 +                                   filter_active_filters],
              togglable           = True,
              toggled             = 'persistent',
              outline_complete    = True, 
              query      = sq_resource,
              query_all  = query_resource_all,
              # safer to use 'hrn' as the internal unique key for this plugin
-             id_key     = main_query_key,
+             #id_key     = main_query_key,
              checkboxes = True,
              datatables_options = { 
                  'iDisplayLength': 25,
                  },
              )
  
 +        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,
 +                # safer to use 'hrn' as the internal unique key for this plugin
 +                id_key     = main_query_key,
 +                checkboxes = True,
 +                )
 +
          if do_query_leases:
              resources_as_scheduler = Scheduler(
                  page        = page,
              resources_as_3dmap,
              resources_as_list_area,
              ]
 +        if insert_grid:
 +            resources_sons.append(resources_as_grid)
 +
 +        print 40*'+-',"resources_sons has",len(resources_sons),"son"
  
          resources_area = Tabs ( page=page, 
                                  domid="resources",