Commit 60231443 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_jio: Include script to report partition reported state

The reported state is informed by the partition giving user more accurate view on the state, so it can know if the partition was processed or not.
parent 74183ece
from DateTime import DateTime
import json
slap_state = context.getSlapState()
_translate = context.Base_translateString
NOT_ALLOCATED = _translate("Searching Partition")
STARTING = _translate("Starting")
STARTED = _translate("Started")
STOPPING = _translate("Stopping")
STOPPED = _translate("Stopped")
DESTROYING = _translate("Destroying")
DESTROYED = _translate("Destroyed")
FAILING_STOP = _translate("Failing to stop")
FAILING_START = _translate("Failing to start")
UNKNOWN = _translate("Waiting contact from the instance")
computer_partition = context.getAggregateValue(portal_type="Computer Partition")
if computer_partition is not None:
memcached_dict = context.Base_getSlapToolMemcachedDict()
try:
d = memcached_dict[context.getReference()]
except KeyError:
return _translate(context.getSlapStateTitle())
d = json.loads(d)
result = d['text']
reported_state = d.get("state", "")
if reported_state == "":
return UNKNOWN
if slap_state == "destroy_requested":
return DESTROYING
if reported_state == "stopped":
if slap_state == "start_requested":
if result.startswith('#error '):
return FAILING_START
return STARTING
elif slap_state == "stop_requested":
return STOPPED
elif reported_state == "started":
if slap_state == "start_requested":
return STARTED
elif slap_state == "stop_requested":
if result.startswith('#error '):
return FAILING_STOP
return STOPPING
raise ValueError("%s %s %s Unknown State" % (context.getRelativeUrl(), result, slap_state))
if slap_state == "destroy_requested":
return DESTROYED
return NOT_ALLOCATED
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstance_getReportedState</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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