Commit e57a3284 authored by Radomir Klacza's avatar Radomir Klacza
Browse files

Speeding up myslicelib

parent f458ce1a
......@@ -3,7 +3,7 @@ from pprint import pprint
from myslicelib.util.sfa import hrn_to_urn, urn_to_hrn, unique_call_id
from myslicelib.util.builder import Builder
from myslicelib.util.parser import Parser, get_testbed_type
#from myslicelib.util.decorators import timeit
# from myslicelib.util.decorators import timeit
from myslicelib.api.sfa import Api as SfaApi
from myslicelib.api.sfa import SfaError
from myslicelib.error import MysParameterIsRequiredError
......@@ -30,7 +30,7 @@ class SfaAm(SfaApi):
def _lease(self, urn=None):
# lease don't have urn, it has a lease_id in OMF (hash), but no id in IoT-Lab
if self._version['geni_api'] == 2:
if self.endpoint.version['geni_api'] == 2:
cred = self.registry.user_credential
else:
cred = {'geni_value': self.registry.user_credential, 'geni_version': '3', 'geni_type': 'geni_sfa'}
......@@ -42,7 +42,7 @@ class SfaAm(SfaApi):
})
def _resource(self, urn=None):
if self._version['geni_api'] == 2:
if self.endpoint.version['geni_api'] == 2:
cred = self.registry.user_credential
else:
cred = {'geni_value': self.registry.user_credential, 'geni_version': '3', 'geni_type': 'geni_sfa'}
......@@ -63,17 +63,16 @@ class SfaAm(SfaApi):
}
slice_credential = self.registry.search_credential(hrn, 'slice')
if self._version['geni_api'] == 2:
if self.endpoint.version['geni_api'] == 2:
options['geni_slice_urn'] = urn
# XXX Check result
return self._proxy.ListResources([slice_credential], options)
elif self._version['geni_api'] == 3:
elif self.endpoint.version['geni_api'] == 3:
# XXX Check result
return self._proxy.Describe([urn], [slice_credential], options)
else:
raise NotImplementedError('geni_api version not supported')
#@timeit
def get(self, entity, urn=None, raw=False):
try:
result = getattr(self, "_" + entity)(urn)
......@@ -107,8 +106,8 @@ class SfaAm(SfaApi):
xml_string = result['value']
# pprint(xml_string)
# XXX if urn is not None we need to Filter - in the parser???
testbed_type = get_testbed_type(self._version['urn'])
result = Parser(testbed_type, self._version['urn'], xml_string).parse(entity)
testbed_type = get_testbed_type(self.endpoint.version['urn'])
result = Parser(testbed_type, self.endpoint.version['urn'], xml_string).parse(entity)
return result
# XXX Check result
else:
......@@ -130,18 +129,16 @@ class SfaAm(SfaApi):
else:
return []
def create(self, entity, urn, record_dict):
return self.update(entity, urn, record_dict)
#@timeit
def delete(self, entity, urn):
# self.Delete
result = []
# NITOS AM's using version 2, don't support delete function
if self._version['geni_api'] == 3:
if self.endpoint.version['geni_api'] == 3:
try:
if entity != 'slice':
raise NotImplementedError('Not implemented')
......@@ -169,6 +166,8 @@ class SfaAm(SfaApi):
'type': self.endpoint.type,
'exception': str(e)
})
else:
print("We skip deleting")
return {'data':result,'errors':self.logs}
def _renew_slice(self, urn, record_dict, api_options):
......@@ -199,11 +198,10 @@ class SfaAm(SfaApi):
else:
raise SfaError(result)
#@timeit
def update(self, entity, urn, record_dict):
result = []
if 'testbeds' not in record_dict or 'urn' not in self._version or self._version['urn'] not in record_dict['testbeds']:
if 'testbeds' not in record_dict or 'urn' not in self.endpoint.version or self.endpoint.version['urn'] not in record_dict['testbeds']:
#print("testbed is not concerned or is offline")
#pprint(self.version())
return {'data':result,'errors':self.logs}
......@@ -224,13 +222,13 @@ class SfaAm(SfaApi):
if 'expiration_date' in record_dict:
result = self._renew_slice(urn, record_dict, api_options)
parser = get_testbed_type(self._version['urn'])
rspec = Builder(parser, self._version['urn']).build(urn, record_dict)
parser = get_testbed_type(self.endpoint.version['urn'])
rspec = Builder(parser, self.endpoint.version['urn']).build(urn, record_dict)
if self._version['geni_api'] == 2:
if self.endpoint.version['geni_api'] == 2:
result = self._update_slice_v2(urn, rspec, api_options)
elif self._version['geni_api'] == 3:
elif self.endpoint.version['geni_api'] == 3:
result = self._update_slice_v3(urn, rspec, api_options)
else:
......@@ -260,7 +258,7 @@ class SfaAm(SfaApi):
# XXX Check res
# TODO: raise Exception(res)
else:
if self._version['geni_api'] == 3:
if self.endpoint.version['geni_api'] == 3:
res = self._proxy.PerformOperationalAction([urn], [object_cred], action, api_options)
# XXX Check res
# TODO: raise Exception(res)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment