Commit 65f73750 authored by Yusei Tahara's avatar Yusei Tahara

slapos/slap/slap.py slap.initializeConnection: Cache master node's Hateoas URL...

slapos/slap/slap.py slap.initializeConnection: Cache master node's Hateoas URL and do not ask many times. Communication to master node is expensive.
parent 15dedb62
...@@ -821,6 +821,7 @@ class ConnectionHelper: ...@@ -821,6 +821,7 @@ class ConnectionHelper:
return req.text.encode('utf-8') return req.text.encode('utf-8')
getHateoasUrl_cache = {}
class slap: class slap:
zope.interface.implements(interface.slap) zope.interface.implements(interface.slap)
...@@ -835,8 +836,14 @@ class slap: ...@@ -835,8 +836,14 @@ class slap:
self._connection_helper = ConnectionHelper(slapgrid_uri, key_file, cert_file, master_ca_file, timeout) self._connection_helper = ConnectionHelper(slapgrid_uri, key_file, cert_file, master_ca_file, timeout)
if not slapgrid_rest_uri: if not slapgrid_rest_uri:
getHateoasUrl_cache_key = (slapgrid_uri, key_file, cert_file, master_ca_file, timeout)
try: try:
slapgrid_rest_uri = self._connection_helper.GET('getHateoasUrl') slapgrid_rest_uri = getHateoasUrl_cache[getHateoasUrl_cache_key]
except KeyError:
pass
if not slapgrid_rest_uri:
try:
slapgrid_rest_uri = getHateoasUrl_cache[getHateoasUrl_cache_key] = self._connection_helper.GET('getHateoasUrl')
except: except:
pass pass
if slapgrid_rest_uri: if slapgrid_rest_uri:
......
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