Commit f35b79a6 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Allow allocation per Subscription and project_guid

Based on allocation scope computers can be segmented for subscribers type, and project_guid can
be used to limit the targeting case.
parent aa2603ab
......@@ -17,17 +17,11 @@ else:
raise NotImplementedError("Unknown portal type %s"%
software_instance_portal_type)
# support SLA
# Explicit location
explicit_location = False
if "computer_guid" in filter_kw:
explicit_location = True
query_kw["parent_reference"] = SimpleQuery(parent_reference=filter_kw.pop("computer_guid"))
if "instance_guid" in filter_kw:
explicit_location = True
portal = context.getPortalObject()
instance_guid = filter_kw.pop("instance_guid")
query_kw["aggregate_related_reference"] = SimpleQuery(aggregate_related_reference=instance_guid)
......@@ -35,6 +29,20 @@ if 'network_guid' in filter_kw:
network_guid = filter_kw.pop('network_guid')
query_kw["default_subordination_reference"] = SimpleQuery(default_subordination_reference=network_guid)
if 'project_guid' in filter_kw:
# This implementation isn't optimal, as we would prefere place a direct query rather them make an
# direct query.
project_reference = filter_kw.pop("project_guid")
# Get Computer list from Tracking API
from DateTime import DateTime
project = context.portal_catalog(portal_type="Project", refernece=project_reference)
if project is not None:
query_kw["parent_reference"] = SimpleQuery(parent_reference=[i.getReference()
for i in context.portal_simulation.getCurrentTrackingList(
{"project_uid": project.getUid(), "at_date": DateTime()})])
if computer_network_query:
if query_kw.get("default_subordination_reference"):
query_kw["default_subordination_reference"] = ComplexQuery(
......@@ -76,9 +84,9 @@ for base_category in computer_base_category_list:
query_kw["%s_uid" % base_category] = category.getUid()
query_kw["capacity_scope_uid"] = context.getPortalObject().portal_categories.capacity_scope.open.getUid()
# if not explicit_location:
# # Only allocation on public computer
# query_kw["allocation_scope_uid"] = context.getPortalObject().portal_categories.allocation_scope.open.public.getUid()
if subscription_reference is not None:
# Subscriptions uses a specific set of allocation scope
query_kw["allocation_scope_uid"] = context.getPortalObject().portal_categories.allocation_scope.open.subscription.getUid()
extra_query_kw = context.ComputerPartition_getCustomAllocationParameterDict(
software_release_url, software_type, software_instance_portal_type,
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>software_release_url, software_type, software_instance_portal_type, filter_kw, computer_network_query=None, test_mode=False</string> </value>
<value> <string>software_release_url, software_type, software_instance_portal_type, filter_kw, computer_network_query=None, subscription_reference=None,test_mode=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -24,11 +24,15 @@ def assignComputerPartition(software_instance, hosting_subscription):
if not person.Person_isAllowedToAllocate():
raise Unauthorized('Allocation disallowed')
subscription_request = hosting_subscription.getAggregateRelatedValue(
portal_type="Subscription Request")
if subscription_request is not None:
subscription_reference = subscription_request.getReference()
if subscription_request.getSimulationState() not in ["confirmed", "started"]:
raise Unauthorized("Related Subscription Requested isn't confirmed or started")
else:
subscription_reference = None
tag = None
try:
......@@ -77,7 +81,7 @@ def assignComputerPartition(software_instance, hosting_subscription):
default_subordination_uid=computer_network.getUid()),
logical_operator='not',
))
computer_network_query = ComplexQuery(*computer_network_query_list)
hosting_subscription.serialize()
......@@ -88,7 +92,7 @@ def assignComputerPartition(software_instance, hosting_subscription):
shadow_document=person,
callable_object=person.Person_findPartition,
argument_list=[software_instance.getUrlString(), software_instance.getSourceReference(),
software_instance.getPortalType(), sla_dict, computer_network_query])
software_instance.getPortalType(), sla_dict, computer_network_query, subscription_reference])
return computer_partition_relative_url, tag
software_instance = context
......@@ -106,7 +110,7 @@ try:
if tag:
hosting_subscription.activate(activity="SQLQueue", tag=tag,
after_tag="allocate_%s" % computer_partition_url).getId()
except ValueError:
# It was not possible to find free Computer Partition
markHistory(software_instance, 'Allocation failed: no free Computer Partition')
......
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