Commit fbfd1b35 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Add constraint for detect duplicated instance in the same tree

   This replaces one alarm on slapos_administration for the same purpose
parent 1bf8c5a0
......@@ -51,6 +51,7 @@
<item>Reference</item>
<item>SlaveInstanceConstraint</item>
<item>SoftwareInstance</item>
<item>SoftwareInstanceDuplicationConstraint</item>
<item>TextDocument</item>
<item>Url</item>
<item>VariationRange</item>
......@@ -65,6 +66,7 @@
<item>Reference</item>
<item>SoftwareInstance</item>
<item>SoftwareInstanceConstraint</item>
<item>SoftwareInstanceDuplicationConstraint</item>
<item>SoftwareInstanceUpgradeConstraint</item>
<item>TextDocument</item>
<item>Url</item>
......
......@@ -2,54 +2,65 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
<global name="Property Sheet" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_searchDuplicatedSoftwareInstance</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string>Search for Duplicated Software Instance on a Single Instance Tree</string> </value>
<key> <string>_count</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>0</int> </value>
<key> <string>_mt_index</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_check_duplicated_software_instance</string> </value>
<key> <string>_tree</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<key> <string>description</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>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
<key> <string>id</string> </key>
<value> <string>SoftwareInstanceDuplicationConstraint</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Search Duplicated Software Instances</string> </value>
<key> <string>portal_type</string> </key>
<value> <string>Property Sheet</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Length" module="BTrees.Length"/>
</pickle>
<pickle> <int>0</int> </pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="OOBTree" module="BTrees.OOBTree"/>
</pickle>
<pickle>
<none/>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Script Constraint" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_identity_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>_range_criterion</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>constraint_type/default</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>duplication_instance_on_instance_tree_constraint_constraint</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Script Constraint</string> </value>
</item>
<item>
<key> <string>script_id</string> </key>
<value> <string>SoftwareInstance_checkDuplicationOnInstanceTreeConsistency</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
if context.getSlapState() == "destroy_requested":
return []
instance_tree = context.getSpecialiseValue(portal_type="Instance Tree")
error_list = []
if instance_tree:
title = context.getTitle()
for instance in instance_tree.getSpecialiseRelatedValueList(
portal_type=["Slave Instance", "Software Instance"]):
if instance.getSlapState() == "destroy_requested" or\
instance.getUid() == context.getUid():
continue
if instance.getTitle() == title:
error_list.append("%s is duplicated with %s " % (
title, instance.getRelativeUrl()))
return error_list
......@@ -50,11 +50,11 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>fixit, active_process</string> </value>
<value> <string>fixit=False</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InstanceTree_checkDuplicatedInstance</string> </value>
<value> <string>SoftwareInstance_checkDuplicationOnInstanceTreeConsistency</string> </value>
</item>
</dictionary>
</pickle>
......
......@@ -27,6 +27,7 @@ Slave Instance | InstanceTree
Slave Instance | Reference
Slave Instance | SlaveInstanceConstraint
Slave Instance | SoftwareInstance
Slave Instance | SoftwareInstanceDuplicationConstraint
Slave Instance | TextDocument
Slave Instance | Url
Slave Instance | VariationRange
......@@ -37,6 +38,7 @@ Software Instance | InstanceTree
Software Instance | Reference
Software Instance | SoftwareInstance
Software Instance | SoftwareInstanceConstraint
Software Instance | SoftwareInstanceDuplicationConstraint
Software Instance | SoftwareInstanceUpgradeConstraint
Software Instance | TextDocument
Software Instance | Url
......
......@@ -10,6 +10,7 @@ ComputerPartitionUpgradeConstraint
ComputePartition
SoftwareInstance
SoftwareInstanceUpgradeConstraint
SoftwareInstanceDuplicationConstraint
InstanceTree
SlaposCapacity
SlaposPersonConstraint
......
active_process = context.newActiveProcess().getRelativeUrl()
context.getPortalObject().portal_catalog.searchAndActivate(
method_id='InstanceTree_checkDuplicatedInstance',
method_kw=dict(fixit=fixit, active_process=active_process),
activate_kw=dict(tag=tag, priority=5),
portal_type="Instance Tree",
validation_state="validated")
<?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>_params</string> </key>
<value> <string>tag, fixit, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_searchDuplicatedSoftwareInstance</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from Products.CMFActivity.ActiveResult import ActiveResult
portal = context.getPortalObject()
software_instance_list = context.getSpecialiseRelatedValueList(
portal_type=["Slave Instance", "Software Instance"])
if len(software_instance_list) == 1:
return
title_dict = {}
active_process = portal.restrictedTraverse(active_process)
for software_instance in software_instance_list:
if software_instance.getSlapState() == "destroy_requested":
continue
title = software_instance.getTitle()
if title in title_dict:
title_dict[title].append(software_instance.getObject())
else:
title_dict[title] = [software_instance.getObject()]
for title in title_dict:
if len(title_dict[title]) > 1:
if fixit:
for software_instance in title_dict[title]:
if len(software_instance.getAggregate([])) == 0:
active_process.postResult(ActiveResult(
summary="Fixing %s which duplication and is not allocated (%s)" \
% (software_instance.getRelativeUrl(), context.getRelativeUrl()),
severity=0,
detail=""))
software_instance.activate().SoftwareInstance_destroyAsSelf()
else:
active_process.postResult(ActiveResult(
summary="%s has duplication" % context.getRelativeUrl(),
severity=100,
detail="%s has duplication on %s (%s)" % (context.getRelativeUrl(), title, len(title_dict[title]))))
notification_message_module/slapos_erp5_credential_recovery_password_expiration_link_en_001
notification_message_module/slapos_erp5_credential_recovery_password_expiration_link_en_001/**
portal_alarms/open_bugs_alarm
portal_alarms/slapos_check_duplicated_software_instance
portal_alarms/slapos_check_security_uid
portal_alarms/slapos_check_stored_broken_state
portal_alarms/slapos_erp5_cleanup_active_process
......
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