Commit fcc63bf1 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

slapos_jio_api_style: Add tools to get and search Shared/Slave Instances

parent 83f1aa67
<?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_get</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_slapos_json_get</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_get_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>1.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Get 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_getFromJSON</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -73,32 +73,62 @@
"$schema": "http://json-schema.org/draft-07/schema#",\n
"$id": "software-instance-base-schema.json",\n
"title": "Software Instance",\n
"description": "Software Instance",\n
"description": "Software Instance Search",\n
"type": "object",\n
"properties": {\n
"title": {\n
"title": "Title",\n
"type": "string",\n
"description": "Unique Name of the Software Instance",\n
"maxLength": 200\n
},\n
"compute_node_id": {\n
"title": "Compute Node ID",\n
"type": "string",\n
"description": "The Id of the compute node hosting the instance, example: COMP-1234"\n
},\n
"root_instante_title": {\n
"title": "Root Instance Title",\n
"type": "string",\n
"description": "Title of the Instance at the root of the instance tree. This is the title of the instance that has been requested by the user."\n
"oneOf": [\n
{\n
"properties": {\n
"title": {\n
"title": "Title",\n
"type": "string",\n
"description": "Unique Name of the Software Instance",\n
"maxLength": 200\n
},\n
"compute_node_id": {\n
"title": "Compute Node ID",\n
"type": "string",\n
"description": "The Id of the compute node hosting the instance, example: COMP-1234"\n
},\n
"root_instante_title": {\n
"title": "Root Instance Title",\n
"type": "string",\n
"description": "Title of the Instance at the root of the instance tree. This is the title of the instance that has been requested by the user."\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Software Instance",\n
"type": "string"\n
}\n
},\n
"required": ["portal_type"]\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Software Instance",\n
"type": "string"\n
{\n
"properties": {\n
"title": {\n
"title": "Title",\n
"type": "string",\n
"description": "Unique Name of the Software Instance",\n
"maxLength": 200\n
},\n
"host_instance_reference": {\n
"title": "Host Instance Reference",\n
"type": "string",\n
"description": "Reference of the Instance where this is instance is hosted, usefull for shared instances"\n
},\n
"root_instante_title": {\n
"title": "Root Instance Title",\n
"type": "string",\n
"description": "Title of the Instance at the root of the instance tree. This is the title of the instance that has been requested by the user."\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Shared Instance",\n
"type": "string"\n
}\n
},\n
"required": ["portal_type"]\n
}\n
},\n
"required": ["portal_type"]\n
]\n
}\n
</string> </value>
</item>
......
......@@ -11,7 +11,10 @@ if portal_type == "Software Installation":
elif portal_type == "Software Instance":
if "reference" in data_dict:
software_instance = portal.portal_catalog.getSoftwareInstanceObject(data_dict["reference"])
software_instance = portal.portal_catalog.getSoftwareInstanceObject(
data_dict["reference"],
include_shared=True
)
if software_instance:
return software_instance
......
search_kw = {
"portal_type": "Software Instance",
"validation_state": "validated",
"select_list": ("title", "reference", "portal_type")
}
portal_type = data_dict["portal_type"]
portal = context.getPortalObject()
if "title" in data_dict:
search_kw["title"] = data_dict["title"]
if "compute_node_id" in data_dict:
search_kw["aggregate_parent_reference"] = data_dict["compute_node_id"]
if "root_instante_title" in data_dict:
search_kw["strict_specialise_title"] = data_dict["root_instante_title"]
if portal_type == "Software Instance":
search_kw = {
"portal_type": "Software Instance",
"validation_state": "validated",
"select_list": ("title", "reference", "portal_type")
}
if "title" in data_dict:
search_kw["title"] = data_dict["title"]
if "compute_node_id" in data_dict:
search_kw["aggregate_parent_reference"] = data_dict["compute_node_id"]
if "root_instante_title" in data_dict:
search_kw["strict_specialise_title"] = data_dict["root_instante_title"]
result_list = [{
"title": x.title,
"reference": x.reference,
"portal_type": x.portal_type,
} for x in portal.portal_catalog(**search_kw)]
elif portal_type == "Shared Instance":
search_kw = {
"portal_type": "Slave Instance",
"validation_state": "validated",
"select_list": ("title", "reference", "portal_type")
}
if "host_instance_reference" in data_dict:
host_instance_list = portal.portal_catalog(
portal_type="Software Instance",
reference=data_dict["host_instance_reference"],
validation_state="validated",
)
if len(host_instance_list) != 1:
return portal.ERP5Site_logApiErrorAndReturn(
error_name="HOST-INSTANCE-NOT-FOUND",
error_message="No matching instances with the provided reference has been found",
error_code=404
)
search_kw["strict_aggregate_uid"] = host_instance_list[0].getObject().getAggregateUid()
if "root_instante_title" in data_dict:
search_kw["strict_specialise_title"] = data_dict["root_instante_title"]
#return portal.portal_catalog(src__=1, **search_kw)
result_list = [{
"title": x.title,
"reference": x.reference,
"portal_type": x.portal_type,
} for x in portal.portal_catalog(**search_kw)]
else:
return portal.ERP5Site_logApiErrorAndReturn(
error_name="UNREACHABLE",
error_message="You Reached code that was not recheable",
)
result_list = [{
"title": x.title,
"reference": x.reference,
"portal_type": x.portal_type,
} for x in context.getPortalObject().portal_catalog(**search_kw)]
import json
return json.dumps({
"$schema": json_form.absolute_url().strip() + "/getOutputJSONSchema",
......
Slave Instance | slapos_jio_api_get_software_instance
Software Installation | slapos_jio_api_put_software_installation
Software Instance | slapos_jio_api_get_software_instance
jIO Web Section | slapos_jio_api_create_compute_node
......
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