+ logger.debug("dispatch got = %s" % req_items.dict())
+ #t = dict(req_items.iterlists())
+ #rspec = req_items.getlist('rspec')
+ #logger.debug("dispatch got = %s" % t)
+
+ platforms = req_items.getlist('platform[]')
+ for k in req_items.dict():
+ logger.debug("key = %s - value = %s" % (k,req_items.get(k)))
+ if k == 'rspec':
+ rspec = req_items.get(k)
+ if k == 'options':
+ options = req_items.get(k)
+ if k == 'output_format':
+ output_format = req_items.get(k)
+ if k == 'hrn':
+ hrn = req_items.get(k)
+ if k == 'urn':
+ urn = req_items.get(k)
+ if k == 'type':
+ object_type = req_items.get(k)
+ if k == 'recursive':
+ if v == '1':
+ recursive = True
+ else:
+ recursive = False
+ if k == 'display':
+ display = req_items.get(k)
+
+ if rspec is not None:
+ try:
+ rspec = json.loads(rspec)
+ except Exception,e:
+ logger.debug("rspec type = %s" % type(rspec))
+ if type(rspec) is dict:
+ rspec = xmltodict.unparse(rspec)
+
+ start_time = time.time()
+ results = sfa_client(request, method, hrn=hrn, urn=urn, object_type=object_type, rspec=rspec, recursive=recursive, options=options, platforms=platforms, output_format=output_format, admin=False)
+ logger.debug("EXEC TIME - sfa_client() - %s sec." % (time.time() - start_time))
+ if display == 'table':
+ return render_to_response('table-default.html', {'data' : data, 'fields' : columns, 'id' : '@component_id', 'options' : None})
+ else:
+ return HttpResponse(json.dumps(results, cls=MyEncoder), content_type="application/json")
+
+def get_user_account(request, user_email, platform_name):
+ """
+ Returns the user configuration for a given platform.
+ This function does not resolve references.
+ """
+ user_query = Query().get('local:user').filter_by('email', '==', user_email).select('user_id')
+ user_details = execute_admin_query(request, user_query)
+ platform_query = Query().get('local:platform').filter_by('platform', '==', platform_name).select('platform_id')
+ platform_details = execute_admin_query(request, platform_query)
+
+ account_query = Query().get('local:account').filter_by('platform_id','==',platform_details[0]['platform_id']).filter_by('user_id', '==', user_details[0]['user_id']).select('user_id','platform_id','auth_type','config')
+ accounts = execute_admin_query(request, account_query)
+
+ if not accounts:
+ raise Exception, "this account does not exist"
+
+ if accounts[0]['auth_type'] == 'reference':
+ pf = json.loads(accounts[0]['config'])['reference_platform']
+ return get_user_account(request, user_email, pf)
+
+ return accounts[0]
+
+#@lru_cache(100)
+def sfa_client(request, method, hrn=None, urn=None, object_type=None, rspec=None, recursive=False, options=None, platforms=None, output_format=None, admin=False):
+
+ Config = ConfigParser.ConfigParser()
+ monitor_file = os.path.abspath(os.path.dirname(__file__) + '/../myslice/monitor.ini')
+ Config.read(monitor_file)
+
+ if admin:
+ user_email, admin_password = config.manifold_admin_user_password()
+ else:
+ #logger.debug(request.session['user']['email'])
+ user_email = request.session['user']['email']
+
+ results = dict()
+
+ if hrn is None:
+ hrn = ''
+ if urn is None:
+ urn = ''
+ if object_type is None:
+ object_type = ''
+ if rspec is None:
+ rspec = ''
+ else:
+ logger.debug("RSPEC = %s" % rspec)
+ if recursive is None:
+ recursive = False
+ if options is None:
+ options = dict()
+ if platforms is None:
+ platforms = list()