Commit 71e9708b authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

slapos_jio_api_style: Finish create Compute Node process

parent 9d2d56d1
...@@ -44,35 +44,9 @@ ...@@ -44,35 +44,9 @@
"title": "Title",\n "title": "Title",\n
"type": "string",\n "type": "string",\n
"maxLength": 200\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
},\n },\n
"required": ["title", "portal_type"]\n "required": ["portal_type"]\n
}\n }\n
</string> </value> </string> </value>
</item> </item>
......
...@@ -9,8 +9,13 @@ if person is None: ...@@ -9,8 +9,13 @@ if person is None:
response.setStatus(403) response.setStatus(403)
else: else:
compute_node = context 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.approveComputeNodeRegistration()
compute_node.generateCertificate()
response.setHeader('Content-Type', "application/json") response.setHeader('Content-Type', "application/json")
return json.dumps({ return json.dumps({
"certificate" : request.get('compute_node_certificate'), "certificate" : request.get('compute_node_certificate'),
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string>title=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
log_error = context.ERP5Site_logApiErrorAndReturn
import json import json
portal = context.getPortalObject() portal = context.getPortalObject()
person = portal.portal_membership.getAuthenticatedMember().getUserValue() person = portal.portal_membership.getAuthenticatedMember().getUserValue()
...@@ -8,32 +7,46 @@ response = request.RESPONSE ...@@ -8,32 +7,46 @@ response = request.RESPONSE
if person is None: if person is None:
response.setStatus(403) response.setStatus(403)
else: return
request_kw = dict(
compute_node_title=data_dict["title"], request_kw = dict(
approve_registration=False, compute_node_title=data_dict.get("title", None),
) approve_registration=False,
person.requestComputeNode(**request_kw) )
compute_node = context.restrictedTraverse(context.REQUEST.get('compute_node')) person.requestComputeNode(**request_kw)
compute_node = context.restrictedTraverse(context.REQUEST.get('compute_node'))
web_site = context.getWebSiteValue()
slapos_master_web_url = web_site.getLayoutProperty( web_site = context.getWebSiteValue()
"configuration_slapos_master_web_url", slapos_master_web_url = web_site.getLayoutProperty(
default=web_site.absolute_url() "configuration_slapos_master_web_url",
) default=web_site.absolute_url()
)
request_url = "%s/%s" % (slapos_master_web_url, "%s/ComputeNode_approveComputer" % compute_node.getRelativeUrl())
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") person.requestToken(request_url=request_url)
response.setHeader('Content-Type', "application/json") access_token_id = context.REQUEST.get("token")
return json.dumps({
"$schema": context.getPortalObject().portal_types.restrictedTraverse(compute_node.getPortalType()).absolute_url() slapos_master_api = web_site.getLayoutProperty(
+ "/getTextContent", "configuration_slapos_master_api", "https://slap.vifib.com")
"title" : compute_node.getTitle(),
"id" : compute_node.getRelativeUrl(), compute_node_install_command_line = web_site.getLayoutProperty(
"reference": compute_node.getReference(), "configuration_compute_node_install_command_line",
"access_token": "V2/" + compute_node.getId() + "/" + access_token_id, "wget https://deploy.erp5.net/slapos ; bash slapos")
"access_token_url": request_url,
"modification_date": compute_node.getModificationDate().HTML4(), 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