Commit c219f1fb authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Cédric Le Ninivin

slapos_jio_api_style: Add action to create Compute node and retrieve certificates

parent d5581972
<?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_post</string>
</tuple>
</value>
</item>
<item>
<key> <string>category</string> </key>
<value> <string>object_slapos_json_post</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_create_compute_node</string> </value>
</item>
<item>
<key> <string>permissions</string> </key>
<value>
<tuple>
<string>View</string>
</tuple>
</value>
</item>
<item>
<key> <string>priority</string> </key>
<value> <float>10.0</float> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Create Compute Node</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}/jIOWebSection_createComputeNodeFromJSON</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>jIOWebSection_createComputeNode</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>jIOWebSection_createComputeNodeFromJSON</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jIOWebSection_createComputeNodeFromJSON</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": "compute-node-base-schema.json",\n
"title": "Compute Node",\n
"description": "Compute Node",\n
"type": "object",\n
"properties": {\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Compute Node",\n
"type": "string"\n
},\n
"title": {\n
"title": "Title",\n
"type": "string",\n
"maxLength": 200\n
},\n
"network": {},\n
"site": {},\n
"project": {},\n
"monitoring": {},\n
"capacity_scope": {},\n
"upgrade_scope": {},\n
"allocation_scope": {\n
"type": "string"\n
},\n
"os_type": {\n
"title": "OS Type",\n
"type": "string",\n
"description": "Type of the OS of the current Compute Node"\n
},\n
"public_ipv4_address": {\n
"title": "Public IPV4 Address",\n
"type":"string"\n
},\n
"python_version": {\n
"title": "Python Version",\n
"type": "string"\n
},\n
"slapos_version": {\n
"title": "SlapOS Version",\n
"type": "string"\n
}\n
},\n
"required": ["title", "portal_type"]\n
}\n
</string> </value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>001</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_jio_api</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
import json
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
request = context.REQUEST
response = request.RESPONSE
if person is None:
response.setStatus(403)
else:
compute_node = context
compute_node.generateCertificate()
compute_node.approveComputeNodeRegistration()
response.setHeader('Content-Type', "application/json")
return json.dumps({
"certificate" : request.get('compute_node_certificate'),
"key" : request.get('compute_node_key'),
"reference": compute_node.getReference(),
"relative_url": compute_node.getRelativeUrl()
})
<?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>ComputeNode_approveComputer</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
log_error = context.ERP5Site_logApiErrorAndReturn
import json
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
request = context.REQUEST
response = request.RESPONSE
if person is None:
response.setStatus(403)
else:
request_kw = dict(
compute_node_title=data_dict["title"],
approve_registration=False,
)
person.requestComputeNode(**request_kw)
compute_node = context.restrictedTraverse(context.REQUEST.get('compute_node'))
web_site = context.getWebSiteValue()
slapos_master_web_url = web_site.getLayoutProperty(
"configuration_slapos_master_web_url",
default=web_site.absolute_url()
)
request_url = "%s/%s" % (slapos_master_web_url, "%s/ComputeNode_approveComputer" % compute_node.getRelativeUrl())
person.requestToken(request_url=request_url)
access_token_id = context.REQUEST.get("token")
response.setHeader('Content-Type', "application/json")
return json.dumps({
"$schema": context.getPortalObject().portal_types.restrictedTraverse(compute_node.getPortalType()).absolute_url()
+ "/getTextContent",
"title" : compute_node.getTitle(),
"id" : compute_node.getRelativeUrl(),
"reference": compute_node.getReference(),
"access_token": "V2/" + compute_node.getId() + "/" + access_token_id,
"access_token_url": request_url,
"modification_date": compute_node.getModificationDate().HTML4(),
})
<?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, form_reference</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jIOWebSection_createComputeNode</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
jIO Web Section | slapos_jio_api_create_compute_node
\ No newline at end of file
portal_callables/jIOWebSection_createComputeNodeFromJSON
\ No newline at end of file
slapos_jio_api
\ No newline at end of file
slapos_jio_api_style
\ 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