Commit 7187b0de authored by Romain Courteaud's avatar Romain Courteaud

REVERT: stop spreading api code in every bt5

parent 812a96a2
......@@ -28,12 +28,9 @@
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from erp5.component.document.JSONType import JSONType
from erp5.component.document.Machine import Machine
import json
class Computer(Machine, JSONType):
class Computer(Machine):
"""
This class represents a computer like personal computer, printer, router.
"""
......@@ -57,58 +54,4 @@ class Computer(Machine, JSONType):
, PropertySheet.Mapping
, PropertySheet.Task
, PropertySheet.Reference
, PropertySheet.TextDocument
, PropertySheet.JSONTypeConstraint
)
def useRevision(self):
return getattr(self, "use_jio_api_revision", False)
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",
"compute_node_id": self.getReference().decode("UTF-8"),
"title": self.getTitle().decode("UTF-8"),
"compute_partition_list": [],
}
if self.useRevision():
web_section = self.getWebSectionValue()
web_section = web_section.getRelativeUrl() if web_section else self.REQUEST.get("web_section_relative_url", None)
if web_section:
revision = self.getJIOAPIRevision(web_section)
if revision:
compute_node_dict["api_revision"] = revision
compute_partition_list = self.contentValues(
portal_type="Compute Partition",
checked_permission="View"
)
for compute_partition in compute_partition_list:
ip_list = []
for internet_protocol_address in compute_partition.contentValues(portal_type='Internet Protocol Address'):
ip_dict = {
"ip-address": internet_protocol_address.getIpAddress().decode("UTF-8"),
"network-interface": internet_protocol_address.getNetworkInterface('').decode("UTF-8"),
}
if internet_protocol_address.getGatewayIpAddress(''):
ip_dict["gateway-ip-address"] = internet_protocol_address.getGatewayIpAddress('').decode("UTF-8")
if internet_protocol_address.getNetmask(''):
ip_dict["netmask"] = internet_protocol_address.getNetmask('').decode("UTF-8")
if internet_protocol_address.getNetworkAddress(''):
ip_dict["network-address"] = internet_protocol_address.getNetworkAddress('').decode("UTF-8")
ip_list.append(ip_dict)
compute_node_dict["compute_partition_list"].append({
"partition_id": compute_partition.getReference(),
"ip_list": ip_list,
})
return json.dumps(compute_node_dict, indent=2)
......@@ -29,9 +29,8 @@
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet
from erp5.component.document.Item import Item
from erp5.component.document.JSONType import JSONType
class ComputerPartition(Item, JSONType):
class ComputerPartition(Item):
"""Computer partition represents usage of Computer"""
meta_type = 'ERP5 Computer Partition'
portal_type = 'Computer Partition'
......@@ -50,6 +49,4 @@ class ComputerPartition(Item, JSONType):
, PropertySheet.Mapping
, PropertySheet.Task
, PropertySheet.Reference
, PropertySheet.TextDocument
, PropertySheet.JSONTypeConstraint
)
......@@ -6,12 +6,6 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>ComputerPartition</string> </value>
......@@ -20,12 +14,6 @@
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5.Document.ComputerPartition</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>document.erp5.ComputerPartition</string> </value>
......@@ -59,28 +47,13 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -93,7 +66,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -102,7 +75,7 @@
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
......
......@@ -2,7 +2,7 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="JSON Type" module="erp5.portal_type"/>
<global name="Base Type" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
......@@ -18,6 +18,10 @@
<none/>
</value>
</item>
<item>
<key> <string>factory</string> </key>
<value> <string>addXMLObject</string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
......@@ -42,119 +46,7 @@
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>JSON Type</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
"$schema": {\n
"title": "Schema URL",\n
"type": "string",\n
"description": "URL of the response schema"\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Compute Node",\n
"type": "string"\n
},\n
"compute_node_id": {\n
"title": "Compute Node ID",\n
"type": "string",\n
"description": "Unique Id of the object. It is not editable."\n
},\n
"title": {\n
"title": "Title",\n
"type": "string",\n
"maxLength": 200\n
},\n
"compute_partition_list": {\n
"title": "Compute Partition List",\n
"type": "array",\n
"descritpion": "List Compute Node Partitions hosted on the computer",\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. Used to configure firewall when necessary and allow only related instances to access it.",\n
"items": {\n
"type": "object",\n
"title": "Internet Protocol Address",\n
"description": "All element to describe the interface",\n
"properties": {\n
"ip-address": {\n
"title": "IP Address",\n
"type": "string"\n
},\n
"network-interface": {\n
"title": "Network Interface",\n
"type": "string"\n
},\n
"gateway-ip-address": {\n
"title": "Gateway Ip Address",\n
"type": "string"\n
},\n
"netmask": {\n
"title": "Netmask",\n
"type": "string"\n
},\n
"network-address": {\n
"title": "Network Address",\n
"type": "string"\n
}\n
},\n
"required": ["ip-address"]\n
}\n
}\n
},\n
"required": ["partition_id"]\n
}\n
},\n
"access_token": {\n
"title": "Access Token",\n
"description": "Access Token to retrieve Computer Certificate",\n
"type": "string",\n
"maxLength": 200\n
},\n
"certificate_url_access": {\n
"title": "Certificate URL Access",\n
"type": "string",\n
"description": "If defined, url to retrieve certificates"\n
},\n
"slapos_master_web": {\n
"title": "SlapOS Master Web Interface",\n
"type": "string"\n
},\n
"slapos_master_api": {\n
"title": "Slap API Interface Url",\n
"type": "string"\n
},\n
"initialisation_comand": {\n
"title": "Command to initiate slapos node",\n
"type": "string"\n
},\n
"api_revision": {\n
"title": "API Revision",\n
"type": "string",\n
"description": "The API Revision is set by the master node to mark when the element was last processed. It is incremental. If revision has changed, critical data has been updated"\n
}\n
}\n
}\n
</string> </value>
<value> <string>Base Type</string> </value>
</item>
<item>
<key> <string>type_class</string> </key>
......
......@@ -2,10 +2,29 @@
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="JSON Type" module="erp5.portal_type"/>
<global name="Base Type" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_property_domain_dict</string> </key>
<value>
<dictionary>
<item>
<key> <string>short_title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>acquire_local_roles</string> </key>
<value> <int>1</int> </value>
......@@ -14,12 +33,24 @@
<key> <string>content_icon</string> </key>
<value> <string>document_icon.gif</string> </value>
</item>
<item>
<key> <string>content_meta_type</string> </key>
<value> <string>ERP5 Computer</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>factory</string> </key>
<value> <string>addComputerPartition</string> </value>
</item>
<item>
<key> <string>filter_content_types</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
......@@ -45,8 +76,8 @@
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>JSON Type</string> </value>
<key> <string>title</string> </key>
<value> <string>Compute Partition</string> </value>
</item>
<item>
<key> <string>type_class</string> </key>
......@@ -61,4 +92,48 @@
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<tuple>
<global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>domain_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>property_name</string> </key>
<value> <string>short_title</string> </value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<tuple>
<global name="TranslationInformation" module="Products.ERP5Type.TranslationProviderBase"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>domain_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>property_name</string> </key>
<value> <string>title</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
erp5_base
erp5_immobilisation
erp5_json_type
\ No newline at end of file
erp5_immobilisation
\ 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