Commit 41c78b59 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin Committed by Romain Courteaud

slapos_cloud: Add asJSONText on Software Installation

parent d3084701
......@@ -31,6 +31,8 @@ from Products.ERP5Type import Permissions, PropertySheet
from erp5.component.document.Item import Item
from erp5.component.document.JSONType import JSONType
import json
class SoftwareInstallation(Item, JSONType):
"""
This class represents a computer like personal computer, printer, router.
......@@ -47,3 +49,30 @@ class SoftwareInstallation(Item, JSONType):
property_sheets = ( PropertySheet.TextDocument
, PropertySheet.JSONTypeConstraint
)
security.declareProtected(Permissions.AccessContentsInformation,
'asJSONText')
def asJSONText(self):
requested_state = self.getSlapState()
if requested_state == "stop_requested":
state = 'stopped'
elif requested_state in ("start_requested", "started"):
state = 'available'
elif requested_state == "destroy_requested":
state = 'destroyed'
else:
raise ValueError("Unknown slap state : %s" % requested_state)
# software instance has to define an xml parameter
status_dict = self.getAccessStatus()
result = {
"$schema": self.getPortalObject().portal_types.restrictedTraverse(self.getPortalType()).absolute_url()
+ "/getTextContent",
"reference": self.getReference().decode("UTF-8"),
"software_release_uri": self.getUrlString(),
"compute_node_id": self.getAggregateReference(),
"state": state,
"reported_state": status_dict.get("state"),
"status_message": status_dict.get("text"),
}
result.update()
return json.dumps(result, indent=2)
......@@ -72,13 +72,23 @@
"description": "State of the requested software",\n
"default": "available"\n
},\n
"reported_state": {\n
"title": "Reported State",\n
"type": "string",\n
"enum": ["available", "destroyed", "building", ""],\n
"description": "State reported by the node installing the Software Installation"\n
},\n
"status_message": {\n
"title": "Status Message",\n
"description": "Last Message received for the Software Installation",\n
"type": "string"\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Software Installation",\n
"type": "string"\n
}\n
},\n
"required": ["portal_type", "software_release_uri", "compute_node_id"]\n
}\n
}\n
</string> </value>
</item>
......
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