+ elif method == "Describe":
+ version = server.GetVersion()
+ logger.debug(version['geni_api'])
+ # if GetVersion = v2
+ if version['geni_api'] == 2:
+ # ListResources(slice_hrn)
+ api_options['geni_slice_urn'] = urn
+ result = server.ListResources([object_cred], api_options)
+ dict_result = xmltodict.parse(result['value'])
+ # else GetVersion = v3
+ else:
+ result = server.Describe([urn] ,[object_cred], api_options)
+ dict_result = xmltodict.parse(result['value']['geni_rspec'])
+
+ result['json'] = json.dumps(dict_result)
+ if 'rspec' in dict_result and 'node' in dict_result['rspec']:
+ if isinstance(dict_result['rspec']['node'], list):
+ columns.extend(dict_result['rspec']['node'][0].keys())
+ else:
+ columns.extend(dict_result['rspec']['node'].keys())
+
+ elif method == 'Renew':
+ # Renew till 1 month from now
+ d = datetime.datetime.utcnow() + datetime.timedelta(365/12)
+ date = d.isoformat("T") + "Z"
+ result = server.Renew([urn] ,[object_cred], date, 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 = []
+
+ # Registry API Calls
+ else:
+ record_dict = {'urn': urn, 'hrn': hrn, 'type': object_type}
+ if method == "List":
+ # hrn is required
+ 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
+ api_options['details']=True
+ result = server.Resolve(hrn, user_cred, api_options)
+ if object_type:
+ result = filter_records(object_type, 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
+ if dict_result:
+ if 'rspec' in dict_result and 'node' in dict_result['rspec']:
+ if isinstance(dict_result['rspec']['node'], list):
+ data = data + dict_result['rspec']['node']
+ else:
+ data.append(dict_result['rspec']['node'])
+ except Exception,e:
+ import traceback
+ logger.error(traceback.format_exc())
+ logger.error(e)
+ results[pf] = {'error':'-3', 'error_msg': str(e)}
+
+ results['columns'] = columns
+ return results