Commit d45b7ae8 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Titouan Soulard

slapos_jio_api_style: Introduce first version of update instance

Still missing:
* Update connection parameters
* Update state
parent bba31a6a
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/object_slapos_json_put</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_slapos_json_put</string> </value>
</item>
<item>
<key> <string>condition</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_jio_api_put_software_instance</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Action Information</string> </value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>7.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Update Software Instance</string> </value>
</item>
<item>
<key> <string>visible</string> </key>
<value> <int>1</int> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="Expression" module="Products.CMFCore.Expression"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>text</string> </key>
<value> <string>string:${object_url}/SoftwareInstance_updateFromJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="JSON Form" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>after_method_id</string> </key>
<value> <string>SoftwareInstance_updateFromDict</string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>application/json</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>SoftwareInstance_updateFromJSON</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstance_updateFromJSON</string> </value>
</item>
<item>
<key> <string>output_schema</string> </key>
<value> <string>{\n
"$schema": "http://json-schema.org/draft-07/schema#",\n
"title": "Software Instance Updated",\n
"description": "Response when the software instance is updated",\n
"type": "object",\n
"properties": {\n
"reference": {\n
"title": "Software Instance Id/Reference",\n
"type": "string",\n
"description": "The unique reference of the Software Instance, example: SOFTINST-1234"\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Software Instance",\n
"type": "string"\n
},\n
"date": {\n
"title": "Date",\n
"description": "Date and Time of the operation",\n
"type": "string",\n
"format": "date-time"\n
}\n
}\n
}\n
</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>JSON Form</string> </value>
</item>
<item>
<key> <string>text_content</string> </key>
<value> <string>{\n
"$schema": "http://json-schema.org/draft-07/schema#",\n
"$id": "software-instance-base-schema.json",\n
"title": "Software Instance",\n
"description": "Software Instance",\n
"type": "object",\n
"properties": {\n
"reference": {\n
"title": "Software Instance Id/Reference",\n
"type": "string",\n
"description": "The unique reference of the Software Instance, example: SOFTINST-1234"\n
},\n
"reported_state": {\n
"title": "Reported State",\n
"type": "string",\n
"enum": ["started", "destroyed", "stopped", "error", "bang"],\n
"description": "State reported by the node installing the Software Installation"\n
},\n
"status_message": {\n
"title": "Status Message",\n
"description": "Message Used to inform master with readable text. Use to justify an error or a bang",\n
"type": "string"\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Software Instance",\n
"type": "string"\n
},\n
"title": {\n
"title": "New Title",\n
"type": "string",\n
"description": "Use this to change the name of your instance. Very dangerous. DO NOT USE IF YOU DO NOT KNOW WHAT YOU ARE DOING",\n
"maxLength": 200\n
}\n
},\n
"required": ["reference", "portal_type"]\n
}\n
</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import json
software_instance = context
logError = context.ERP5Site_logApiErrorAndReturn
if "reported_state" in data_dict:
# Change desired state
reported_state = data_dict["reported_state"]
if (reported_state == "started"):
software_instance.setAccessStatus(
'Instance correctly started', "started", reindex=1)
elif (reported_state == "stopped"):
software_instance.setAccessStatus(
'Instance correctly stopped', "stopped", reindex=1)
elif (reported_state == "destroyed"):
if software_instance.getSlapState() == 'destroy_requested':
# remove certificate from SI
software_instance.revokeCertificate()
if software_instance.getValidationState() == 'validated':
software_instance.invalidate()
elif (reported_state == "bang"):
software_instance.setErrorStatus('bang called')
timestamp = str(int(software_instance.getModificationDate()))
key = "%s_bangstamp" % software_instance.getReference()
if not software_instance.isLastData(key, timestamp):
software_instance.bang(bang_tree=True, comment=data_dict.get("status_message", ""))
elif (reported_state == "error"):
error_log = data_dict.get("status_message", "")
software_instance.setErrorStatus('while instanciating: %s' % error_log[-80:], reindex=1)
else:
return logError(
error_name="SOFTWARE-INSTANCE-WRONG-REPORTED-STATE",
error_message="Unexcepected Reported State: %s" % reported_state,
)
if "title" in data_dict and data_dict["title"] != software_instance.getTitle():
software_instance.rename(
new_name=data_dict["title"],
comment="Rename %s into %s" % (software_instance.getTitle(), data_dict["title"])
)
return json.dumps({
"$schema": json_form.absolute_url().strip() + "/getOutputJSONSchema",
"reference": software_instance.getReference(),
"portal_type": "Software Instance",
"date": str(DateTime()),
"success": "Done"
}, indent=2)
<?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>data_dict, json_form</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SoftwareInstance_updateFromDict</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -3,6 +3,7 @@ Slave Instance | slapos_jio_api_get_software_instance
Software Installation | slapos_jio_api_get_software_installation
Software Installation | slapos_jio_api_put_software_installation
Software Instance | slapos_jio_api_get_software_instance
Software Instance | slapos_jio_api_put_software_instance
jIO Web Section | slapos_jio_api_create_compute_node
jIO Web Section | slapos_jio_api_create_software_installation
jIO Web Section | slapos_jio_api_request_software_instance
......
......@@ -2,6 +2,7 @@ portal_callables/ComputeNode_getFromJSON
portal_callables/SoftwareInstallation_getFromJSON
portal_callables/SoftwareInstallation_updateFromJSON
portal_callables/SoftwareInstance_getFromJSON
portal_callables/SoftwareInstance_updateFromJSON
portal_callables/jIOWebSection_createComputeNodeFromJSON
portal_callables/jIOWebSection_createSoftwareInstallationFromJSON
portal_callables/jIOWebSection_requestComputerPartitionFromJSON
......
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