Commit 989ea01a authored by Romain Courteaud's avatar Romain Courteaud

Do not modify partition anymore.

Use the capacity_scope category on computer to desactivate everything.
The alarm is now able to open/close the allocation.

It now checks: edit workflow, access log and capacity usage.
parent 49e5a48b
...@@ -55,13 +55,81 @@ ...@@ -55,13 +55,81 @@
computer = context\n computer = context\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
\n \n
if computer.getAllocationScope() != \'open/public\':\n
# Don\'t update non public computer\n
return\n
\n
can_allocate = True\n
comment = \'\'\n
\n
# First and simple way to see if computer is dead\n
modification_date = portal.portal_workflow.getInfoFor(computer, \'time\', wf_id=\'edit_workflow\')\n modification_date = portal.portal_workflow.getInfoFor(computer, \'time\', wf_id=\'edit_workflow\')\n
if (DateTime() - modification_date) > 1:\n if (DateTime() - modification_date) > 1:\n
# Computer didn\'t talk to vifib for 1 days, do not consider it as a trustable public server for now\n # Computer didn\'t talk to vifib for 1 days, do not consider it as a trustable public server for now\n
for partition in computer.contentValues(portal_type="Computer Partition"):\n # slapformat is supposed to run at least once per day\n
if partition.getSlapState() == \'free\':\n can_allocate = False\n
# Desactivate partition. A new partition will be created if the computer runs slapformat\n comment = "Computer didn\'t contact the server for more than one day"\n
partition.markInactive()\n \n
if can_allocate:\n
# Check if computer has error reported\n
memcached_dict = portal.portal_memcached.getMemcachedDict(\n
key_prefix=\'slap_tool\',\n
plugin_path=\'portal_memcached/default_memcached_plugin\')\n
try:\n
d = memcached_dict[computer.getReference()]\n
except KeyError:\n
can_allocate = False\n
comment = "Computer didn\'t contact the server"\n
else:\n
log_dict = json.loads(d)\n
if \'#error\' in log_dict.get(\'text\', \'#error\'):\n
can_allocate = False\n
comment = \'Computer reported an error\'\n
# XXX TODO: compare creation date of #ok message\n
\n
if can_allocate:\n
# Check the computer capacity.\n
# there is a arbitrary hardcoded default value: not more than 20 instances on\n
# a computer\n
computer_capacity_quantity = computer.getCapacityQuantity(20)\n
software_release_capacity_dict = {}\n
consumed_capacity = 0\n
\n
for instance in portal.portal_catalog.portal_catalog(\n
default_aggregate_uid=computer.getUid(),\n
portal_type=[\'Software Instance\', \'Slave Instance\'],\n
validation_state=\'validated\'):\n
\n
instance = instance.getObject()\n
\n
software_release_url = instance.getRootSoftwareReleaseUrl()\n
if software_release_url in software_release_capacity_dict:\n
software_release_capacity = software_release_capacity_dict[software_release_url]\n
else:\n
delivery_line = instance.getCausalityValue().getMovementList[0]\n
software_release = delivery_line.getAggregateValue(portal_type=\'Software Release\')\n
if software_release:\n
software_release_capacity = software_release.getCapacityQuantity(1)\n
software_release_capacity_dict[software_release_url] = software_release_capacity\n
\n
consumed_capacity += software_release_capacity\n
if consumed_capacity >= computer_capacity_quantity:\n
can_allocate = False\n
comment = \'Computer capacity limit exceded\'\n
break\n
\n
new_value = None\n
if can_allocate:\n
if computer.getCapacityScope() == \'closed\':\n
new_value = \'open\'\n
else:\n
if computer.getCapacityScope() == \'open\':\n
new_value = \'closed\'\n
\n
if new_value is not None:\n
computer.edit(capacity_scope=new_value)\n
if comment:\n
portal.portal_workflow.doActionFor(computer, \'edit_action\', comment=comment)\n
]]></string> </value> ]]></string> </value>
......
3 4
\ No newline at end of file \ No newline at end of file
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