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

slapos_jio_api_style: Finish create Compute Node process

parent 5d35c895
......@@ -44,35 +44,9 @@
"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
"required": ["portal_type"]\n
}\n
</string> </value>
</item>
......
......@@ -9,8 +9,13 @@ if person is None:
response.setStatus(403)
else:
compute_node = context
compute_node.generateCertificate()
if title:
compute_node.edit(title=title)
else:
# Make sure a title is defined
compute_node.setTitle(compute_node.getTitle())
compute_node.approveComputeNodeRegistration()
compute_node.generateCertificate()
response.setHeader('Content-Type', "application/json")
return json.dumps({
"certificate" : request.get('compute_node_certificate'),
......
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>title=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
log_error = context.ERP5Site_logApiErrorAndReturn
import json
portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue()
......@@ -8,32 +7,46 @@ 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(),
})
return
request_kw = dict(
compute_node_title=data_dict.get("title", None),
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.strip("/"), "%s/ComputeNode_approveComputer" % compute_node.getRelativeUrl())
person.requestToken(request_url=request_url)
access_token_id = context.REQUEST.get("token")
slapos_master_api = web_site.getLayoutProperty(
"configuration_slapos_master_api", "https://slap.vifib.com")
compute_node_install_command_line = web_site.getLayoutProperty(
"configuration_compute_node_install_command_line",
"wget https://deploy.erp5.net/slapos ; bash slapos")
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,
"certificate_url_access": request_url,
"initialisation_comand": compute_node_install_command_line,
"slapos_master_web": slapos_master_web_url,
"slapos_master_api": slapos_master_api,
"modification_date": compute_node.getModificationDate().HTML4(),
# Kept for backward compatibility
"command_line": compute_node_install_command_line,
})
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