from myslice.settings import logger
+from rest.sfa_api import sfa_client
+
theme = ThemeView()
import activity.slice
print e
return None
+def getAuthorities(request, admin = False):
+ result = sfa_client(request,'List',hrn='onelab',object_type='authority',platforms=['myslice'],admin=admin)
+ authorities = list()
+ for item in result['myslice']:
+ authorities.append({'authority_hrn':item['hrn']})
+ return sorted(authorities)
+
+
# Get the list of pis in a given authority
def authority_get_pis(request, authority_hrn):
# CACHE PB with fields
for t in itertools.izip_longest(total_platform_list)]
## check pi or no
- pi_status = authority_check_pis(self.request, user_email)
+ pi_status = request.session['user']['pi']
context = super(UserView, self).get_context_data(**kwargs)
context['principal_acc'] = principal_acc_list
+import requests
import json
import time
import re
from unfold.loginrequired import LoginRequiredAutoLogoutView
-from portal.actions import create_pending_project, create_pending_join, sfa_add_authority, authority_add_pis, is_pi
+from portal.actions import create_pending_project, create_pending_join, sfa_add_authority, authority_add_pis, is_pi, getAuthorities
from portal.models import PendingProject, PendingJoin
from myslice.theme import ThemeView
class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView):
template_name = 'projectrequest_view.html'
- def getAuthorities(self, request):
- #if self.theme == 'fed4fire':
- authorities_query = Query.get('myslice:authority').select('authority_hrn')
- #else:
- # authorities_query = Query.get('authority').select('name', 'authority_hrn')
- authorities = execute_admin_query(request, authorities_query)
- if authorities is not None:
- # Remove the root authority from the list
- matching = [s for s in authorities if "." in s['authority_hrn']]
- authorities = sorted(matching, key=lambda k: k['authority_hrn'])
- #if self.theme != 'fed4fire':
- # authorities = sorted(matching, key=lambda k: k['name'])
- return authorities
-
def getUserAuthority(self, request):
# Get user_email (XXX Would deserve to be simplified)
user_query = Query().get('local:user').select('email','config')
user_email = self.getUserEmail(wsgi_request)
- authorities = self.getAuthorities(wsgi_request)
+ authorities = getAuthorities(wsgi_request)
user_authority = self.getUserAuthority(wsgi_request)
from manifold.core.query import Query
from portal.models import PendingUser
-from portal.actions import create_pending_user
+from portal.actions import create_pending_user, getAuthorities
from myslice.theme import ThemeView
from myslice.settings import logger
"""
"""
errors = []
- authority_hrn = None
- # REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
- authorities_query = Query.get('authority').select('name', 'authority_hrn')
- authorities = execute_admin_query(wsgi_request, authorities_query)
- if authorities is not None:
- # Remove the root authority from the list
- matching = [s for s in authorities if "." in s['authority_hrn']]
- authorities = sorted(matching, key=lambda k: k['authority_hrn'])
- authorities = sorted(matching, key=lambda k: k['name'])
+
+ authorities = getAuthorities(wsgi_request, admin = True)
+
+ #authority_hrn = None
+ ## REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2
+ #authorities_query = Query.get('authority').select('name', 'authority_hrn')
+ #authorities = execute_admin_query(wsgi_request, authorities_query)
+ #if authorities is not None:
+ # # Remove the root authority from the list
+ # matching = [s for s in authorities if "." in s['authority_hrn']]
+ # authorities = sorted(matching, key=lambda k: k['authority_hrn'])
+ # authorities = sorted(matching, key=lambda k: k['name'])
logger.debug("############ BREAKPOINT 1 #################")
# Page rendering
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_admin_query, execute_query
-from portal.actions import is_pi, create_slice, create_pending_slice, clear_user_creds, authority_check_pis
+from portal.actions import is_pi, create_slice, create_pending_slice, clear_user_creds, authority_check_pis, getAuthorities
#from portal.forms import SliceRequestForm
from unfold.loginrequired import LoginRequiredAutoLogoutView
from ui.topmenu import topmenu_items_live, the_user
authority_hrn = None
authority_name = None
# Retrieve the list of authorities
- #if self.theme == 'fed4fire' or self.theme == 'onelab':
- authorities_query = Query.get('myslice:authority').select('authority_hrn')
- #else:
- # authorities_query = Query.get('authority').select('name', 'authority_hrn')
- authorities = execute_admin_query(request, authorities_query)
- if authorities is not None:
- authorities = sorted(authorities, key=lambda k: k['authority_hrn'])
- #if self.theme != 'fed4fire' or self.theme != 'onelab':
- # authorities = sorted(authorities, key=lambda k: k['name'])
+
+ authorities = getAuthorities(request, admin=True)
+
+ ##if self.theme == 'fed4fire' or self.theme == 'onelab':
+ #authorities_query = Query.get('myslice:authority').select('authority_hrn')
+ ##else:
+ ## authorities_query = Query.get('authority').select('name', 'authority_hrn')
+ #authorities = execute_admin_query(request, authorities_query)
+ #if authorities is not None:
+ # authorities = sorted(authorities, key=lambda k: k['authority_hrn'])
+ # #if self.theme != 'fed4fire' or self.theme != 'onelab':
+ # # authorities = sorted(authorities, key=lambda k: k['name'])
# Get user_email (XXX Would deserve to be simplified)
user_query = Query().get('local:user').select('email','config')
user_hrn = account_config.get('user_hrn','N/A')
# acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
-
- # checking if pi or not
- #if acc_auth_cred == {} or acc_auth_cred == 'N/A':
- # pi = "is_not_pi"
- #else:
- # pi = "is_pi"
-
- pi = authority_check_pis (request, user_email)
- logger.debug("SLICEREQUESTVIEW.PY ----- pi= {}".format(pi))
+ pi = request.session['user']['pi']
# Page rendering
page = Page(request)
from unfold.loginrequired import LoginRequiredView
-from myslice.settings import logger
+from myslice.settings import logger, config
from rest.json_encoder import MyEncoder
def dispatch(request, method):
- Config = ConfigParser.ConfigParser()
- Config.read(os.getcwd() + "/myslice/monitor.ini")
-
- #logger.debug(request.session['user']['email'])
- user_email = request.session['user']['email']
- platforms = list()
- options = dict()
- rspec = ''
- results = dict()
- urn = ''
hrn = ''
+ urn = ''
object_type = ''
- display = None
+ rspec = ''
recursive = False
+ options = dict()
+ platforms = list()
+
+ results = dict()
+ display = None
if request.method == 'POST':
req_items = request.POST
elif el[0].startswith('display'):
display = el[1]
+ results = sfa_client(request, method, hrn, urn, object_type, recursive, options, platforms)
+
+ 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(user_email, platform_name):
+ """
+ Returns the user configuration for a given platform.
+ This function does not resolve references.
+ """
+ user = db.query(User).filter(User.email == user_email).one()
+ platform = db.query(Platform).filter(Platform.platform == platform_name).one()
+ accounts = [a for a in user.accounts if a.platform == platform]
+ 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(user_email, pf)
+
+ return accounts[0]
+
+def sfa_client(request, method, hrn=None, urn=None, object_type=None, rspec=None, recursive=None, options=None, platforms=None, admin=False):
+
+ Config = ConfigParser.ConfigParser()
+ Config.read(os.getcwd() + "/myslice/monitor.ini")
+
+ 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 = ''
+ if recursive is None:
+ recursive = False
+ if options is None:
+ options = dict()
+ if platforms is None:
+ platforms = list()
+
if method not in ['GetVersion','ListResources']:
try:
if not hrn:
user_config = get_user_config(user_email, pf)
if 'delegated_user_credential' in user_config:
user_cred = user_config['delegated_user_credential']
+ elif 'user_credential' in user_config:
+ user_cred = user_config['user_credential']
else:
user_cred = {}
for obj_name, cred in user_config['delegated_%s_credentials'%object_type].items():
if obj_name == hrn:
object_cred = cred
+ elif '%s_credentials'%object_type in user_config:
+ for obj_name, cred in user_config['%s_credentials'%object_type].items():
+ if obj_name == hrn:
+ object_cred = cred
# Both AM & Registry
if method == "GetVersion":
record_dict = {'urn': urn, 'hrn': hrn, 'type': object_type}
if method == "List":
# hrn is required
- options['recursive'] = recursive
- result = server.List(hrn, user_cred, options)
+ api_options['recursive'] = recursive
+ result = server.List(hrn, user_cred, api_options)
if object_type:
result = filter_records(object_type, result)
elif method == "Resolve":
# hrn is required
# details can be True or False
- options['details']=True
- result = server.Resolve(hrn, user_cred, options)
+ api_options['details']=True
+ result = server.Resolve(hrn, user_cred, api_options)
if object_type:
result = filter_records(object_type, result)
elif method == "Register":
logger.error(traceback.format_exc())
logger.error(e)
results[pf] = {'error':'-3', 'error_msg': str(e)}
- if display == 'table':
- return render_to_response('table-default.html', {'data' : data, 'fields' : columns, 'id' : '@component_id', 'options' : None})
- else:
- results['columns'] = columns
- return HttpResponse(json.dumps(results, cls=MyEncoder), content_type="application/json")
-def get_user_account(user_email, platform_name):
- """
- Returns the user configuration for a given platform.
- This function does not resolve references.
- """
- user = db.query(User).filter(User.email == user_email).one()
- platform = db.query(Platform).filter(Platform.platform == platform_name).one()
- accounts = [a for a in user.accounts if a.platform == platform]
- 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(user_email, pf)
-
- return accounts[0]
+ results['columns'] = columns
+ return results
def get_user_config(user_email, platform_name):
account = get_user_account(user_email, platform_name)