- # Get user config from Manifold
- user_config = get_user_config(user_email, pf)
- if 'delegated_user_credential' in user_config:
- user_cred = user_config['delegated_user_credential']
- else:
- user_cred = {}
-
- #if 'delegated_slice_credentials' in user_config:
- # for slice_name, cred in user_config['delegated_slice_credentials']:
- # if slice_name == slice_param
-
- if method == "GetVersion":
- result = server.GetVersion()
- elif method == "ListResources":
- api_options = {}
- #api_options ['call_id'] = unique_call_id()
- api_options['geni_rspec_version'] = {'type': 'GENI', 'version': '3'}
- result = server.ListResources([user_cred], api_options)
- elif method == "Describe":
- api_options = {}
- #api_options ['call_id'] = unique_call_id()
- api_options['geni_rspec_version'] = {'type': 'GENI', 'version': '3'}
- result = server.Describe([urn] ,[object_cred], api_options)
-
- else:
- return HttpResponse(json.dumps({'error' : '-3','msg':'method not supported yet'}), content_type="application/json")
-
- results[pf] = result
-
- return HttpResponse(json.dumps(results), content_type="application/json")
+ try:
+ # Get user config from Manifold
+ user_config = get_user_config(user_email, pf)
+ if 'delegated_user_credential' in user_config:
+ user_cred = user_config['delegated_user_credential']
+ else:
+ user_cred = {}
+
+ if object_type:
+ if 'delegated_%s_credentials'%object_type in user_config:
+ for obj_name, cred in user_config['delegated_%s_credentials'%object_type].items():
+ if obj_name == hrn:
+ object_cred = cred
+
+ # Both AM & Registry
+ if method == "GetVersion":
+ result = server.GetVersion()
+ else:
+ # AM V3
+ if server_am:
+ if method == "ListResources":
+ result = server.ListResources([user_cred], api_options)
+ elif method == "Describe":
+ # if GetVersion = v2
+ # ListResources(slice_hrn)
+ # else GetVersion = v3
+ result = server.Describe([urn] ,[object_cred], api_options)
+ elif method == 'Renew':
+ result = server.Renew([urn] ,[object_cred], api_options)
+ elif method == 'Delete':
+ result = server.Delete([urn] ,[object_cred], api_options)
+ elif method == 'Allocate':
+ # if GetVersion = v2
+ # CreateSliver(slice_hrn)
+ # else GetVersion = v3
+ api_options['call_id'] = unique_call_id()
+ # List of users comes from the Registry
+ api_options['sfa_users'] = sfa_users
+ api_options['geni_users'] = geni_users
+ result = server.Allocate([urn] ,[object_cred], rspec, api_options)
+ elif method == 'Provision':
+ # if GetVersion = v2
+ # Nothing it is not supported by v2 AMs
+ api_options['call_id'] = unique_call_id()
+ # List of users comes from the Registry
+ api_options['sfa_users'] = sfa_users
+ api_options['geni_users'] = geni_users
+ result = server.Provision([urn] ,[object_cred], api_options)
+ elif method == 'Status':
+ result = server.Status([urn] ,[object_cred], api_options)
+ elif method == 'PerformOperationalAction':
+ # if GetVersion = v2
+ # Nothing it is not supported by v2 AMs
+ result = server.PerformOperationalAction([urn] ,[object_cred], action, api_options)
+ elif method == 'Shutdown':
+ result = server.Shutdown(urn ,[object_cred], api_options)
+ else:
+ #return HttpResponse(json.dumps({'error' : '-3','msg':'method not supported by AM'}), content_type="application/json")
+ logger.debug('method %s not handled by AM' % method)
+ result = []
+ else:
+ if method == "List":
+ # hrn is required
+ result = server.List(hrn, user_cred, options)
+ logger.debug(result)
+ elif method == "Resolve":
+ # hrn is required
+ # details can be True or False
+ options['details']=True
+ result = server.Resolve(hrn, user_cred, options)
+ logger.debug(result)
+ elif method == "Register":
+ # record_dict must be crafted
+ # auth_cred must be selected in the list of auth_creds from user's account
+ result = server.Register(record_dict, auth_cred)
+ elif method == "Update":
+ # record_dict must be crafted
+ # object_cred must be selected in the list of creds for the object type
+ # from user's account
+ result = server.Update(record_dict, object_cred)
+ elif method == "Remove":
+ # hrn is required
+ # auth_cred must be selected in the list of auth_creds from user's account
+ # object_type is required
+ result = server.Remove(hrn, auth_cred, object_type)
+ else:
+ #return HttpResponse(json.dumps({'error' : '-3','msg':'method not supported by Registry'}), content_type="application/json")
+ logger.debug('method %s not handled by Registry' % method)
+ result = []
+
+ results[pf] = result
+ except Exception,e:
+ import traceback
+ logger.error(traceback.format_exc())
+ logger.error(e)
+ results[pf] = {'error':'-3', 'error_msg': str(e)}
+
+ return HttpResponse(json.dumps(results, cls=MyEncoder), content_type="application/json")