Commit bd6c2814 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Romain Courteaud

slapos_cloud: Add getSoftwareInstanceObject to Slapos Catalog Tool Mixin

parent 7b4bfd25
......@@ -30,7 +30,6 @@ from OFS.Traversable import NotFound
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
class SlapOSCatalogToolCacheMixin(object):
""" Quering Caching Extension for Catalog for handle specific queries
relying on caching.
......@@ -92,3 +91,28 @@ class SlapOSCatalogToolCacheMixin(object):
(compute_node_reference, compute_partition_reference))
else:
return _assertACI(compute_partition_list[0].getObject())
def _getNonCachedSoftwareInstance(self, reference, include_shared=False):
# No need to get all results if an error is raised when at least 2 objects
# are found
if not include_shared:
portal_type = "Software Instance"
else:
portal_type = ("Software Instance", "Slave Instance")
software_instance_list = self.unrestrictedSearchResults(limit=2,
portal_type=portal_type,
validation_state="validated",
reference=reference)
if len(software_instance_list) != 1:
raise NotFound, "No document found with parameters: %s" % reference
else:
return _assertACI(software_instance_list[0].getObject()).getRelativeUrl()
def getSoftwareInstanceObject(self, reference, include_shared=False):
"""
Get the validated compute_node with this reference.
"""
result = CachingMethod(self._getNonCachedSoftwareInstance,
id='_getSoftwareInstanceObject',
cache_factory='slap_cache_factory')(reference, include_shared=include_shared)
return self.getPortalObject().restrictedTraverse(result)
\ No newline at end of file
......@@ -6,6 +6,12 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>SlapOSCatalogToolCacheMixin</string> </value>
......@@ -55,13 +61,28 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -74,7 +95,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -83,7 +104,7 @@
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
......
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