Commit 98c3bf52 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Prevent exceed capacity by updating capacity scope after allocation

For prevent over allocation, we have to update the state of the Computer just after the allocation. This don't replace alarms to control the global state (when capacity is updated etc etc)
parent f343a799
......@@ -56,13 +56,7 @@ if can_allocate:
software_release_capacity_dict = {}
consumed_capacity = 0
for instance in portal.portal_catalog.portal_catalog(
default_aggregate_relative_url='%s/%%' % computer.getRelativeUrl(),
portal_type=['Software Instance', 'Slave Instance'],
validation_state='validated'):
instance = instance.getObject()
def getSoftwareReleaseCapacity(instance):
software_release_url = instance.getUrlString()
if software_release_url in software_release_capacity_dict:
software_release_capacity = software_release_capacity_dict[software_release_url]
......@@ -75,11 +69,27 @@ if can_allocate:
else:
software_release_capacity = 1
software_release_capacity_dict[software_release_url] = software_release_capacity
return software_release_capacity
if allocated_instance is not None:
software_release_capacity = getSoftwareReleaseCapacity(allocated_instance)
consumed_capacity += software_release_capacity
if consumed_capacity >= computer_capacity_quantity:
can_allocate = False
comment = 'Computer capacity limit exceeded'
break
if can_allocate:
for instance in portal.portal_catalog.portal_catalog(
default_aggregate_relative_url='%s/%%' % computer.getRelativeUrl(),
portal_type=['Software Instance', 'Slave Instance'],
validation_state='validated'):
software_release_capacity = getSoftwareReleaseCapacity(instance.getObject())
consumed_capacity += software_release_capacity
if consumed_capacity >= computer_capacity_quantity:
can_allocate = False
comment = 'Computer capacity limit exceeded'
break
# if can_allocate:
# result_list = portal.portal_catalog.portal_catalog(
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>allocated_instance=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -119,6 +119,10 @@ else:
for computer_partition_candidate in context.portal_catalog(
limit=limit, **query_kw):
computer_partition_candidate = computer_partition_candidate.getObject()
if computer_partition_candidate.getParentValue().getCapacityScope() == "close":
# The computer was closed on this partition, so skip it.
continue
if software_instance_portal_type == "Software Instance":
# Check if the computer partition can be marked as busy
if isTransitionPossible(computer_partition_candidate, 'mark_busy'):
......
......@@ -16,3 +16,9 @@ computer_partition = portal.restrictedTraverse(computer_partition_url)
assert computer_partition.getPortalType() == "Computer Partition"
instance.edit(aggregate_value=computer_partition, activate_kw={'tag': 'allocate_%s' % computer_partition_url})
computer = computer_partition.getParentValue()
computer.Computer_checkAndUpdateCapacityScope(
allocated_instance=instance
)
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