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

erp5_computer_immobilisation: Add asJSONText on Computer

parent 7642f7db
...@@ -31,6 +31,8 @@ from Products.ERP5Type import Permissions, PropertySheet ...@@ -31,6 +31,8 @@ from Products.ERP5Type import Permissions, PropertySheet
from erp5.component.document.JSONType import JSONType from erp5.component.document.JSONType import JSONType
from erp5.component.document.Machine import Machine from erp5.component.document.Machine import Machine
import json
class Computer(Machine, JSONType): class Computer(Machine, JSONType):
""" """
This class represents a computer like personal computer, printer, router. This class represents a computer like personal computer, printer, router.
...@@ -58,3 +60,48 @@ class Computer(Machine, JSONType): ...@@ -58,3 +60,48 @@ class Computer(Machine, JSONType):
, PropertySheet.TextDocument , PropertySheet.TextDocument
, PropertySheet.JSONTypeConstraint , PropertySheet.JSONTypeConstraint
) )
security.declareProtected(Permissions.AccessContentsInformation,
'asJSONText')
def asJSONText(self):
"""
Return a minimal representation of the Compute Node
"""
compute_node_dict = {
"$schema": self.getPortalObject().portal_types.restrictedTraverse(
self.getPortalType()
).absolute_url()
+ "/getTextContent",
"portal_type": "Compute Node",
"id": self.getReference().decode("UTF-8"),
"title": self.getTitle().decode("UTF-8"),
"compute_partition_list": [],
}
compute_partition_list = self.contentValues(
portal_type="Compute Partition",
checked_permission="View"
)
for compute_partition in compute_partition_list:
ip_list = []
full_ip_list = []
for internet_protocol_address in compute_partition.contentValues(portal_type='Internet Protocol Address'):
# XXX - There is new values, and we must keep compatibility
address_tuple = (
internet_protocol_address.getNetworkInterface('').decode("UTF-8"),
internet_protocol_address.getIpAddress().decode("UTF-8"))
if internet_protocol_address.getGatewayIpAddress('') and \
internet_protocol_address.getNetmask(''):
address_tuple = address_tuple + (
internet_protocol_address.getGatewayIpAddress().decode("UTF-8"),
internet_protocol_address.getNetmask().decode("UTF-8"),
internet_protocol_address.getNetworkAddress('').decode("UTF-8"))
full_ip_list.append(address_tuple)
else:
ip_list.append(address_tuple)
compute_node_dict["compute_partition_list"].append({
"partition_id": compute_partition.getReference(),
"ip_list": ip_list,
})
return json.dumps(compute_node_dict, indent=2)
...@@ -73,11 +73,33 @@ ...@@ -73,11 +73,33 @@
"type": "string",\n "type": "string",\n
"maxLength": 200\n "maxLength": 200\n
},\n },\n
"reference": {\n "compute_partition_list": {\n
"title": "Compute Node Reference",\n "title": "Compute Partition List",\n
"description": "Unique identifier of the Compute Node",\n "type": "array",\n
"type": "string",\n "descritpion": "List Compute Node Partitions hosted on the computer",\n
"maxLength": 50\n "items": {\n
"type": "object",\n
"title": "Compute Node Partition",\n
"description": "Compute Node Partitions host Software Instances",\n
"properties": {\n
"partition_id": {\n
"title": "Partition ID",\n
"descritpion": "Unique ID of the Compute Node Partition",\n
"type": "string"\n
},\n
"ip_list": {\n
"title": "IP List",\n
"type": "array",\n
"descritpion": "List of IPs usable by the Software Instance on the partition",\n
"items": {\n
"type": "array",\n
"items": {\n
"type": "string"\n
}\n
}\n
}\n
}\n
}\n
},\n },\n
"access_token": {\n "access_token": {\n
"title": "Access Token",\n "title": "Access Token",\n
...@@ -88,7 +110,7 @@ ...@@ -88,7 +110,7 @@
"certificate_url_access": {\n "certificate_url_access": {\n
"title": "Certificate URL Access",\n "title": "Certificate URL Access",\n
"type": "string",\n "type": "string",\n
"description": "If defined, url to retrieve certificates",\n "description": "If defined, url to retrieve certificates"\n
},\n },\n
"slapos_master_web": {\n "slapos_master_web": {\n
"title": "SlapOS Master Web Interface",\n "title": "SlapOS Master Web Interface",\n
......
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