Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Roque
slapos.core
Commits
20cfc233
Commit
20cfc233
authored
Apr 20, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_cloud: implement asJSONText for software instance
parent
7919dd01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
139 additions
and
2 deletions
+139
-2
master/bt5/slapos_cloud/DocumentTemplateItem/portal_components/document.erp5.SoftwareInstance.py
...eItem/portal_components/document.erp5.SoftwareInstance.py
+31
-2
master/bt5/slapos_cloud/PortalTypeTemplateItem/portal_types/Software%20Instance.xml
...rtalTypeTemplateItem/portal_types/Software%20Instance.xml
+108
-0
No files found.
master/bt5/slapos_cloud/DocumentTemplateItem/portal_components/document.erp5.SoftwareInstance.py
View file @
20cfc233
...
@@ -29,6 +29,7 @@ from AccessControl import ClassSecurityInfo
...
@@ -29,6 +29,7 @@ from AccessControl import ClassSecurityInfo
from
Products.ERP5Type
import
Permissions
from
Products.ERP5Type
import
Permissions
from
erp5.component.document.Item
import
Item
from
erp5.component.document.Item
import
Item
from
erp5.component.document.JSONType
import
JSONType
from
erp5.component.document.JSONType
import
JSONType
import
json
from
lxml
import
etree
from
lxml
import
etree
import
collections
import
collections
...
@@ -183,7 +184,7 @@ class SoftwareInstance(Item, JSONType):
...
@@ -183,7 +184,7 @@ class SoftwareInstance(Item, JSONType):
portal
=
self
.
getPortalObject
()
portal
=
self
.
getPortalObject
()
compute_partition
=
self
.
getAggregateValue
(
portal_type
=
"Compute Partition"
)
compute_partition
=
self
.
getAggregateValue
(
portal_type
=
"Compute Partition"
)
if
compute_partition
is
None
:
if
compute_partition
is
None
:
raise
ValueError
(
"Instance isn't allocated to call _asParamterDict"
)
raise
ValueError
(
"Instance isn't allocated to call _asParam
e
terDict"
)
timestamp
=
int
(
compute_partition
.
getModificationDate
())
timestamp
=
int
(
compute_partition
.
getModificationDate
())
newtimestamp
=
int
(
self
.
getBangTimestamp
(
int
(
self
.
getModificationDate
())))
newtimestamp
=
int
(
self
.
getBangTimestamp
(
int
(
self
.
getModificationDate
())))
...
@@ -311,7 +312,35 @@ class SoftwareInstance(Item, JSONType):
...
@@ -311,7 +312,35 @@ class SoftwareInstance(Item, JSONType):
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'asJSONText'
)
'asJSONText'
)
def
asJSONText
(
self
):
def
asJSONText
(
self
):
return
self
.
getJsonContent
()
try
:
parameter_dict
=
self
.
_asParameterDict
()
except
ValueError
:
parameter_dict
=
{}
requested_state
=
self
.
getSlapState
()
if
requested_state
==
"stop_requested"
:
state
=
'stopped'
elif
requested_state
==
"start_requested"
:
state
=
'started'
elif
requested_state
==
"destroy_requested"
:
state
=
'destroyed'
else
:
raise
ValueError
(
"Unknown slap state : %s"
%
requested_state
)
# software instance has to define an xml parameter
result
=
{
"$schema"
:
self
.
getPortalObject
().
portal_types
.
restrictedTraverse
(
self
.
getPortalType
()).
absolute_url
()
+
"/getTextContent"
,
"reference"
:
self
.
getReference
().
decode
(
"UTF-8"
),
"title"
:
self
.
getTitle
().
decode
(
"UTF-8"
),
"connection_parameters"
:
self
.
getConnectionXmlAsDict
(),
"parameters"
:
self
.
getInstanceXmlAsDict
(),
"node"
:
self
.
getSlaXmlAsDict
(),
"state"
:
state
,
"id"
:
self
.
getRelativeUrl
(),
}
result
.
update
(
parameter_dict
)
return
json
.
dumps
(
result
,
indent
=
2
)
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'fromJSONText'
)
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'fromJSONText'
)
def
fromJSONText
(
self
,
json_content
):
def
fromJSONText
(
self
,
json_content
):
...
...
master/bt5/slapos_cloud/PortalTypeTemplateItem/portal_types/Software%20Instance.xml
View file @
20cfc233
...
@@ -59,6 +59,114 @@
...
@@ -59,6 +59,114 @@
</tuple>
</tuple>
</value>
</value>
</item>
</item>
<item>
<key>
<string>
text_content
</string>
</key>
<value>
<string>
{\n
"$schema": "http://json-schema.org/draft-07/schema#",\n
"$id": "software-instance-base-schema.json",\n
"title": "Software Instance",\n
"description": "Software Instance",\n
"type": "object",\n
"properties": {\n
"$schema": {\n
"title": "Schema URL",\n
"type": "string",\n
"description": "URL of the response schema"\n
},\n
"title": {\n
"title": "Title",\n
"type": "string",\n
"description": "Unique Name of the Software Instance",\n
"maxLength": 200\n
},\n
"reference": {\n
"title": "Software Instance Reference",\n
"description": "Unique identifier of the Software Instance",\n
"type": "string",\n
"maxLength": 50\n
},\n
"software_release_uri": {\n
"title": "Software Release URI",\n
"type": "string"\n
},\n
"software_type": {\n
"title": "Software Type",\n
"type": "string",\n
"description": "Software type to be requested"\n
},\n
"state": {\n
"title": "Requested State",\n
"type": "string",\n
"enum": ["started", "stopped", "destroyed"],\n
"description": "State of the requested instance"\n
},\n
"connection_parameters": {\n
"title": "Connections Parameters",\n
"type": "object",\n
"additionalProperties": { "type": "string" }\n
},\n
"parameters": {\n
"title": "Instance Parameters",\n
"type": "object",\n
"additionalProperties": { "type": "string" }\n
},\n
"shared": {\n
"title": "Shared Instance",\n
"type": "boolean",\n
"description": "Ask for a Shared Instance"\n
},\n
"sla_parameters": {\n
"title": "Target Node Selection Parameters",\n
"type": "object",\n
"description": "Also known as SLA parameters. Used to pick where an how the instance is to be deployed",\n
"properties": {\n
"computer_guid": {\n
"title": "Requested Compute Node",\n
"descritpion": "Requested Compute Node Reference, like COMP-1234",\n
"type": "string"\n
},\n
"project_guid": {\n
"title": "Requested Project",\n
"descritpion": "Requested Project Reference",\n
"type": "string"\n
},\n
"instance_guid": {\n
"title": "Requested Host Instance",\n
"descritpion": "Only applicable to shared instance. Requested Host Instance Reference, like SOFTINST-1234",\n
"type": "string"\n
},\n
"network_guid": {\n
"title": "Requested Network",\n
"descritpion": "Requested Network Reference",\n
"type": "string"\n
}\n
},\n
"additionalProperties": { "type": "string" }\n
},\n
"compute_node_id": {\n
"title": "Compute Node Id",\n
"type": "string",\n
"description": "Id Of the Requesting Compute Node, used by Slap Client when an instance is requesting an instance"\n
},\n
"compute_partition_id": {\n
"title": "Compute Partition Id",\n
"type": "string",\n
"description": "Id Of the Requesting Compute Partition, used by Slap Client when an instance is requesting an instance"\n
},\n
"portal_type": {\n
"title": "Portal Type",\n
"const": "Software Instance",\n
"type": "string"\n
},\n
"id": {\n
"title": "ID",\n
"type": "string",\n
"description": "Unique Id of the object. It is not editable."\n
}\n
}\n
}\n
</string>
</value>
</item>
<item>
<item>
<key>
<string>
type_class
</string>
</key>
<key>
<string>
type_class
</string>
</key>
<value>
<string>
SoftwareInstance
</string>
</value>
<value>
<string>
SoftwareInstance
</string>
</value>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment