.. note::
- This class is the implementation of an OMF 5.4 API. Since the version 5.4.1, the Topic Architecture start with OMF_5.4 instead of OMF used for OMF5.3
+ This class is the implementation of an OMF 5.4 API.
+ Since the version 5.4.1, the Topic Architecture start with OMF_5.4
+ instead of OMF used for OMF5.3
"""
- def __init__(self, slice, host, port, password, xmpp_root = None):
+ def __init__(self, slice, host, port, password, xmpp_root = None,
+ exp_id = None):
"""
:param slice: Xmpp Slice
"""
super(OMFAPI, self).__init__("OMFAPI")
-
date = tsformat()
tz = -time.altzone if time.daylight != 0 else -time.timezone
date += "%+06.2f" % (tz / 3600) # timezone difference is in seconds
- self._user = "%s-%s" % (slice, date)
+ self._exp_id = exp_id or date
+ self._user = "%s-%s" % (slice, self._exp_id)
self._slice = slice
self._host = host
self._port = port
# OMF xmpp client
self._client = None
+
# message handler
self._message = None
""" Publish New Experiment Message
"""
- address = "/%s/%s/%s/%s" % (self._host, self._xmpp_root, self._slice, self._user)
+ address = "/%s/%s/%s/%s" % (self._host, self._xmpp_root, self._slice,
+ self._user)
#print address
payload = self._message.newexp_function(self._user, address)
slice_sid = "/%s/%s" % (self._xmpp_root, self._slice)
:type hostname: str
"""
- return "/%s/%s/%s/%s" % (self._xmpp_root, self._slice, self._user, hostname)
+ return "/%s/%s/%s/%s" % (self._xmpp_root, self._slice, self._user,
+ hostname)
def _host_resource_id(self, hostname):
""" Return the Topic Name as /xmpp_root/slice/resources/hostname
self._client.delete(xmpp_node)
def enroll_host(self, hostname):
- """ Create and Subscribe to the session topic and the resources corresponding to the hostname
+ """ Create and Subscribe to the session topic and the resources
+ corresponding to the hostname
:param hostname: Full hrn of the node
:type hostname: str
:param hostname: Full hrn of the node
:type hostname: str
- :param attribute: Attribute that need to be configured (often written as /net/wX/attribute, with X the interface number)
+ :param attribute: Attribute that need to be configured (
+ often written as /net/wX/attribute, with X the interface number)
:type attribute: str
:param value: Value of the attribute
:type value: str
:param hostname: Full hrn of the node
:type hostname: str
- :param app_id: Application Id (Any id that represents in a unique way the application)
+ :param app_id: Application Id (Any id that represents in a unique
+ way the application)
:type app_id: str
:param arguments: Arguments of the application
:type arguments: str
:type env: str
"""
- payload = self._message.execute_function(hostname, app_id, arguments, path, env)
+ payload = self._message.execute_function(hostname, app_id, arguments,
+ path, env)
xmpp_node = self._host_session_id(hostname)
self._client.publish(payload, xmpp_node)
"""
.. note::
- It allows the different RM to use the same xmpp client if they use the same credentials.
- For the moment, it is focused on Xmpp.
+ It allows the different RM to use the same xmpp client if they use
+ the same credentials. For the moment, it is focused on XMPP.
"""
- # use lock to avoid concurrent access to the Api list at the same times by 2 different threads
+ # use lock to avoid concurrent access to the Api list at the same times by 2
+ # different threads
lock = threading.Lock()
_apis = dict()
@classmethod
- def get_api(cls, slice, host, port, password):
+ def get_api(cls, slice, host, port, password, exp_id = None):
""" Get an OMF Api
:param slice: Xmpp Slice Name
"""
if slice and host and port and password:
- key = cls._make_key(slice, host, port, password)
+ key = cls._make_key(slice, host, port, password, exp_id)
cls.lock.acquire()
if key in cls._apis:
#print "Api Counter : " + str(cls._apis[key]['cnt'])
cls.lock.release()
return cls._apis[key]['api']
else :
- omf_api = cls.create_api(slice, host, port, password)
+ omf_api = cls.create_api(slice, host, port, password, exp_id)
cls.lock.release()
return omf_api
return None
@classmethod
- def create_api(cls, slice, host, port, password):
+ def create_api(cls, slice, host, port, password, exp_id):
""" Create an OMF API if this one doesn't exist yet with this credentials
:param slice: Xmpp Slice Name
:type password: str
"""
- omf_api = OMFAPI(slice, host, port, password)
- key = cls._make_key(slice, host, port, password)
+ omf_api = OMFAPI(slice, host, port, password, exp_id = exp_id)
+ key = cls._make_key(slice, host, port, password, exp_id)
cls._apis[key] = {}
cls._apis[key]['api'] = omf_api
cls._apis[key]['cnt'] = 1
return omf_api
@classmethod
- def release_api(cls, slice, host, port, password):
+ def release_api(cls, slice, host, port, password, exp_id = None):
""" Release an OMF API with this credentials
:param slice: Xmpp Slice Name
"""
if slice and host and port and password:
- key = cls._make_key(slice, host, port, password)
+ key = cls._make_key(slice, host, port, password, exp_id)
if key in cls._apis:
cls._apis[key]['cnt'] -= 1
#print "Api Counter : " + str(cls._apis[key]['cnt'])