Commit 72c6ade8 authored by Rafael Monnerat's avatar Rafael Monnerat

librecipe: Use cross-recipe cache for registerComputerPartition

Define a simple cache implementation using a Dict (Singleton) to prevent call registerComputerPartition
  multiple times over the sections.

/reviewed-on !74
parent dcbea9c7
...@@ -29,6 +29,8 @@ import time ...@@ -29,6 +29,8 @@ import time
from generic import GenericBaseRecipe from generic import GenericBaseRecipe
CONNECTION_CACHE = {}
class GenericSlapRecipe(GenericBaseRecipe): class GenericSlapRecipe(GenericBaseRecipe):
"""Base class for all slap.recipe.* needing SLAP informations like instance """Base class for all slap.recipe.* needing SLAP informations like instance
parameters. parameters.
...@@ -50,11 +52,18 @@ class GenericSlapRecipe(GenericBaseRecipe): ...@@ -50,11 +52,18 @@ class GenericSlapRecipe(GenericBaseRecipe):
self.cert_file = slap_connection.get('cert-file') self.cert_file = slap_connection.get('cert-file')
def install(self): def install(self):
cache_key = "%s_%s" % (self.computer_id, self.computer_partition_id)
self.computer_partition = CONNECTION_CACHE.get(cache_key, None)
self.slap.initializeConnection(self.server_url, self.key_file, self.slap.initializeConnection(self.server_url, self.key_file,
self.cert_file) self.cert_file)
self.computer_partition = self.slap.registerComputerPartition( if self.computer_partition is None:
self.computer_id, self.computer_partition = self.slap.registerComputerPartition(
self.computer_partition_id) self.computer_id,
self.computer_partition_id)
CONNECTION_CACHE[cache_key] = self.computer_partition
self.request = self.computer_partition.request self.request = self.computer_partition.request
self.setConnectionDict = self.computer_partition.setConnectionDict self.setConnectionDict = self.computer_partition.setConnectionDict
self.parameter_dict = self.computer_partition.getInstanceParameterDict() self.parameter_dict = self.computer_partition.getInstanceParameterDict()
......
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