Commit f7fd97b4 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: only allocate on allocation_scope/open

parent e6b5063a
import random
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, ComplexQuery
person = context
portal = person.getPortalObject()
assert project_uid
......@@ -8,6 +9,7 @@ compute_partition = None
filter_kw_copy = filter_kw.copy()
query_kw = {
'parent__follow_up__uid': project_uid,
'allocation_scope__uid': portal.restrictedTraverse("portal_categories/allocation_scope").getUid(),
'software_release_url': software_release_url,
'portal_type': 'Compute Partition',
}
......@@ -104,8 +106,8 @@ if test_mode:
SQL_WINDOW_SIZE = 50
# fetch at mot 50 random Compute Partitions, and check if they are ok
isTransitionPossible = person.getPortalObject().portal_workflow.isTransitionPossible
result_count = person.portal_catalog.countResults(**query_kw)[0][0]
isTransitionPossible = portal.portal_workflow.isTransitionPossible
result_count = portal.portal_catalog.countResults(**query_kw)[0][0]
offset = max(0, result_count-1)
if offset >= SQL_WINDOW_SIZE:
limit = (random.randint(0, offset), SQL_WINDOW_SIZE)
......@@ -113,7 +115,7 @@ else:
limit = (0, SQL_WINDOW_SIZE)
for compute_partition_candidate in context.portal_catalog(
for compute_partition_candidate in portal.portal_catalog(
limit=limit, **query_kw):
compute_partition_candidate = compute_partition_candidate.getObject()
if compute_partition_candidate.getParentValue().getCapacityScope() == "close":
......
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