Commit 1f330244 authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: check Allocation Supply to filter where allocation can be done

parent e88d2877
......@@ -6,22 +6,90 @@ portal = person.getPortalObject()
assert project_uid
compute_partition = None
filter_kw_copy = filter_kw.copy()
query_kw = {
'portal_type': 'Compute Partition',
'parent__follow_up__uid': project_uid,
'allocation_scope__uid': portal.restrictedTraverse("portal_categories/allocation_scope/open").getUid(),
'software_release_url': software_release_url,
'portal_type': 'Compute Partition',
}
if software_instance_portal_type == "Slave Instance":
query_kw['free_for_request'] = 0
query_kw['software_type'] = software_type
compute_node_portal_type = 'Instance Node'
elif software_instance_portal_type == "Software Instance":
query_kw['free_for_request'] = 1
query_kw['software_release_url'] = software_release_url
compute_node_portal_type = 'Compute Node'
else:
raise NotImplementedError("Unknown portal type %s"%
software_instance_portal_type)
### Step 1, check where the allocation is allowed
from Products.CMFCore.utils import getToolByName
domain_tool = getToolByName(portal, 'portal_domains')
# XXX prototype for now
tmp_instance = portal.portal_trash.newContent(
portal_type='Instance Tree',
temp_object=1,
url_string=software_release_url,
source_reference=software_type,
follow_up_uid=project_uid
)
software_product, release_variation, type_variation = tmp_instance.InstanceTree_getSoftwareProduct()
if software_product is None:
raise ValueError('No Software Product matching')
tmp_context = portal.portal_trash.newContent(
portal_type='Movement',
temp_object=1,
resource_value=software_product,
software_type_value=type_variation,
software_release_value=release_variation,
)
allocation_cell_list = [x.getObject() for x in \
domain_tool.searchPredicateList(
tmp_context, portal_type=['Allocation Supply Cell'],
validation_state='validated',
destination_project__uid=project_uid,
tested_base_category_list=['resource', 'software_type', 'software_release']) if x.isAllocable()]
#context.log('allocation_cell_list %s' % str(allocation_cell_list))
if not allocation_cell_list:
raise ValueError('No Allocation Supply allowing this operation')
# Get the list of allowed Compute Node, Instance Node
compute_node_list_list = [x.getParentValue().getParentValue().getAggregateValueList(portal_type=compute_node_portal_type) for x in allocation_cell_list]
parent_uid_list = []
partition_uid_list = []
for compute_node_list in compute_node_list_list:
for compute_node in compute_node_list:
if compute_node.getPortalType() == 'Compute Node':
parent_uid_list.append(compute_node.getUid())
elif compute_node.getPortalType() == 'Instance Node':
shared_instance = compute_node.getSpecialiseValue(portal_type='Software Instance')
if shared_instance is not None:
# No need to search for original software type/url
#query_kw['software_release_url'] = software_release_url
#query_kw['software_type'] = software_type
shared_partition = shared_instance.getAggregateValue(portal_type='Compute Partition')
if shared_partition is not None:
partition_uid_list.append(shared_partition.getUid())
else:
raise NotImplementedError('Unsupported Node type: %s' % compute_node.getPortalType())
if len(parent_uid_list) == 0:
# Ensure nothing will be found
parent_uid_list.append(-1)
if len(partition_uid_list) == 0:
# Ensure nothing will be found
partition_uid_list.append(-1)
if software_instance_portal_type == "Slave Instance":
query_kw['uid'] = partition_uid_list
elif software_instance_portal_type == "Software Instance":
query_kw['parent_uid'] = parent_uid_list
# Explicit location
if "computer_guid" in filter_kw:
query_kw["parent_reference"] = SimpleQuery(parent_reference=filter_kw.pop("computer_guid"))
......@@ -107,7 +175,6 @@ if offset >= SQL_WINDOW_SIZE:
else:
limit = (0, SQL_WINDOW_SIZE)
for compute_partition_candidate in portal.portal_catalog(
limit=limit, **query_kw):
compute_partition_candidate = compute_partition_candidate.getObject()
......
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