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: ...@@ -17,17 +17,11 @@ else:
raise NotImplementedError("Unknown portal type %s"% raise NotImplementedError("Unknown portal type %s"%
software_instance_portal_type) software_instance_portal_type)
# support SLA
# Explicit location # Explicit location
explicit_location = False
if "computer_guid" in filter_kw: if "computer_guid" in filter_kw:
explicit_location = True
query_kw["parent_reference"] = SimpleQuery(parent_reference=filter_kw.pop("computer_guid")) query_kw["parent_reference"] = SimpleQuery(parent_reference=filter_kw.pop("computer_guid"))
if "instance_guid" in filter_kw: if "instance_guid" in filter_kw:
explicit_location = True
portal = context.getPortalObject()
instance_guid = filter_kw.pop("instance_guid") instance_guid = filter_kw.pop("instance_guid")
query_kw["aggregate_related_reference"] = SimpleQuery(aggregate_related_reference=instance_guid) query_kw["aggregate_related_reference"] = SimpleQuery(aggregate_related_reference=instance_guid)
...@@ -35,6 +29,20 @@ if 'network_guid' in filter_kw: ...@@ -35,6 +29,20 @@ if 'network_guid' in filter_kw:
network_guid = filter_kw.pop('network_guid') network_guid = filter_kw.pop('network_guid')
query_kw["default_subordination_reference"] = SimpleQuery(default_subordination_reference=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 computer_network_query:
if query_kw.get("default_subordination_reference"): if query_kw.get("default_subordination_reference"):
query_kw["default_subordination_reference"] = ComplexQuery( query_kw["default_subordination_reference"] = ComplexQuery(
...@@ -76,9 +84,9 @@ for base_category in computer_base_category_list: ...@@ -76,9 +84,9 @@ for base_category in computer_base_category_list:
query_kw["%s_uid" % base_category] = category.getUid() query_kw["%s_uid" % base_category] = category.getUid()
query_kw["capacity_scope_uid"] = context.getPortalObject().portal_categories.capacity_scope.open.getUid() query_kw["capacity_scope_uid"] = context.getPortalObject().portal_categories.capacity_scope.open.getUid()
# if not explicit_location: if subscription_reference is not None:
# # Only allocation on public computer # Subscriptions uses a specific set of allocation scope
# query_kw["allocation_scope_uid"] = context.getPortalObject().portal_categories.allocation_scope.open.public.getUid() query_kw["allocation_scope_uid"] = context.getPortalObject().portal_categories.allocation_scope.open.subscription.getUid()
extra_query_kw = context.ComputerPartition_getCustomAllocationParameterDict( extra_query_kw = context.ComputerPartition_getCustomAllocationParameterDict(
software_release_url, software_type, software_instance_portal_type, software_release_url, software_type, software_instance_portal_type,
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <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>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -24,11 +24,15 @@ def assignComputerPartition(software_instance, hosting_subscription): ...@@ -24,11 +24,15 @@ def assignComputerPartition(software_instance, hosting_subscription):
if not person.Person_isAllowedToAllocate(): if not person.Person_isAllowedToAllocate():
raise Unauthorized('Allocation disallowed') raise Unauthorized('Allocation disallowed')
subscription_request = hosting_subscription.getAggregateRelatedValue( subscription_request = hosting_subscription.getAggregateRelatedValue(
portal_type="Subscription Request") portal_type="Subscription Request")
if subscription_request is not None: if subscription_request is not None:
subscription_reference = subscription_request.getReference()
if subscription_request.getSimulationState() not in ["confirmed", "started"]: if subscription_request.getSimulationState() not in ["confirmed", "started"]:
raise Unauthorized("Related Subscription Requested isn't confirmed or started") raise Unauthorized("Related Subscription Requested isn't confirmed or started")
else:
subscription_reference = None
tag = None tag = None
try: try:
...@@ -88,7 +92,7 @@ def assignComputerPartition(software_instance, hosting_subscription): ...@@ -88,7 +92,7 @@ def assignComputerPartition(software_instance, hosting_subscription):
shadow_document=person, shadow_document=person,
callable_object=person.Person_findPartition, callable_object=person.Person_findPartition,
argument_list=[software_instance.getUrlString(), software_instance.getSourceReference(), 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 return computer_partition_relative_url, tag
software_instance = context software_instance = context
......
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