Commit 61b11b97 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_administration: Include alarm to clean up business templates.

This alarm is focus on keep only the minimal and usable set of bt5 installed, this helps on quick upgrades.
parent b28ead07
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_cleanupBusinessTemplate</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Check Unindexed Security UIDs</string> </value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_erp5_cleanup_business_template</string> </value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>433814400.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Clean up Business Template</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>active_process = context.newActiveProcess().getRelativeUrl()\n
\n
context.portal_templates.TemplateTool_deleteObsoleteTemplateList(\n
fixit=fixit, tag=tag, active_process=active_process)\n
\n
context.portal_templates.TemplateTool_unindexDeletedObjectList(\n
fixit=fixit, tag=tag, active_process=active_process)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag,fixit, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_cleanupBusinessTemplate</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
"""\n
This is a custom version, because we don\'t want to definitly delete the objects\n
but only change state to \'deleted\'.\n
\n
This script can also include custom deletions, which comes from legacy \n
implementations and/or garbage left behind from upgrader.\n
"""\n
\n
from Products.CMFActivity.ActiveResult import ActiveResult\n
portal = context.getPortalObject()\n
active_process = portal.restrictedTraverse(active_process)\n
\n
\n
portal_templates = context.getPortalObject().portal_templates\n
delete_list = []\n
bt_list = portal_templates.objectValues()\n
for bt in bt_list:\n
bt_id = bt.getId()\n
installation_state = bt.getInstallationState()\n
if installation_state in (\'replaced\'):\n
if fixit:\n
bt.getObject().delete()\n
summary="%s was deleted." % bt.getRelativeUrl()\n
else:\n
summary="%s is going to be deleted." % bt.getRelativeUrl()\n
active_process.postResult(ActiveResult(\n
summary=summary,\n
severity=2,\n
detail=""))\n
\n
elif installation_state == \'not_installed\':\n
title = bt.getTitle()\n
modification_date = bt.getModificationDate()\n
for x in bt_list:\n
if (x.getTitle() == title and\n
x.getInstallationState() in (\'installed\', \'not_installed\') and\n
x.getModificationDate() > modification_date):\n
if fixit:\n
bt.getObject().delete()\n
summary="%s was deleted." % bt.getRelativeUrl()\n
else:\n
summary="%s is going to be deleted." % bt.getRelativeUrl()\n
active_process.postResult(ActiveResult(\n
summary=summary,\n
severity=2,\n
detail=""))\n
break\n
\n
elif bt.getTitle().startswith("vifib_") and bt.getVersion() == "999": \n
delete_list.append(bt_id)\n
\n
if len(delete_list):\n
if fixit:\n
context.portal_templates.manage_delObjects(delete_list)\n
summary="The bt5 with the followed ids were deleted forever: %s" % delete_list\n
else:\n
summary="The bt5 with the followed ids are going to be deleted forever: %s" % delete_list\n
active_process.postResult(ActiveResult(\n
summary=summary,\n
severity=2,\n
detail=""))\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit, active_process, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TemplateTool_deleteObsoleteTemplateList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>"""\n
Unindexed deleted business template in order to the manager don\'t see it.\n
\n
This is script is probably a workarround.\n
"""\n
\n
from Products.CMFActivity.ActiveResult import ActiveResult\n
portal = context.getPortalObject()\n
active_process = portal.restrictedTraverse(active_process)\n
\n
unindexed_list = []\n
for i in context.portal_templates.portal_catalog(portal_type="Business Template"):\n
if i.getInstallationState() == "deleted":\n
unindexed_list.append(i.path)\n
if fixit:\n
context.portal_catalog.activate(\n
activity="SQLQueue").unindexObject(uid=i.uid)\n
\n
if len(unindexed_list):\n
if fixit:\n
summary="The followed bt5 were unindexed: %s" % unindexed_list\n
else:\n
summary="The followed bt5 are going to be unindexed: %s" % unindexed_list\n
active_process.postResult(ActiveResult(\n
summary=summary,\n
severity=2,\n
detail=""))\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>tag, fixit, active_process, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TemplateTool_unindexDeletedObjectList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal_alarms/slapos_check_duplicated_software_instance
portal_alarms/slapos_check_security_uid
portal_alarms/slapos_erp5_cleanup_active_process
\ No newline at end of file
portal_alarms/slapos_erp5_cleanup_active_process
portal_alarms/slapos_erp5_cleanup_business_template
\ 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