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
Labels
Merge Requests
16
Merge Requests
16
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
1eefa336
Commit
1eefa336
authored
Jun 02, 2022
by
Cédric Le Ninivin
Committed by
Cédric Le Ninivin
Mar 09, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_jio_api_style: Code cleanup to use Slapos Cache catalog mixin
parent
5c1c2c39
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
4 additions
and
164 deletions
+4
-164
master/bt5/slapos_jio_api_style/SkinTemplateItem/portal_skins/slapos_jio_api/Base_getUnrestrictedDocumentUrl.py
...l_skins/slapos_jio_api/Base_getUnrestrictedDocumentUrl.py
+0
-9
master/bt5/slapos_jio_api_style/SkinTemplateItem/portal_skins/slapos_jio_api/Base_getUnrestrictedDocumentUrl.xml
..._skins/slapos_jio_api/Base_getUnrestrictedDocumentUrl.xml
+0
-70
master/bt5/slapos_jio_api_style/SkinTemplateItem/portal_skins/slapos_jio_api/jIOWebSection_getObjectFromData.py
...l_skins/slapos_jio_api/jIOWebSection_getObjectFromData.py
+0
-1
master/bt5/slapos_jio_api_style/SkinTemplateItem/portal_skins/slapos_jio_api/jIOWebSection_requestComputerPartition.py
.../slapos_jio_api/jIOWebSection_requestComputerPartition.py
+4
-84
No files found.
master/bt5/slapos_jio_api_style/SkinTemplateItem/portal_skins/slapos_jio_api/Base_getUnrestrictedDocumentUrl.py
deleted
100644 → 0
View file @
5c1c2c39
if
REQUEST
:
raise
ValueError
(
"This script should not be called directly"
)
# No need to get all results if an error is raised when at least 2 objects
# are found
l
=
context
.
getPortalObject
().
portal_catalog
(
limit
=
2
,
select_list
=
(
"relative_url"
,),
**
kw
)
if
len
(
l
)
!=
1
:
return
None
else
:
return
l
[
0
].
relative_url
master/bt5/slapos_jio_api_style/SkinTemplateItem/portal_skins/slapos_jio_api/Base_getUnrestrictedDocumentUrl.xml
deleted
100644 → 0
View file @
5c1c2c39
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"PythonScript"
module=
"Products.PythonScripts.PythonScript"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
Script_magic
</string>
</key>
<value>
<int>
3
</int>
</value>
</item>
<item>
<key>
<string>
_bind_names
</string>
</key>
<value>
<object>
<klass>
<global
name=
"NameAssignments"
module=
"Shared.DC.Scripts.Bindings"
/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key>
<string>
_asgns
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
name_container
</string>
</key>
<value>
<string>
container
</string>
</value>
</item>
<item>
<key>
<string>
name_context
</string>
</key>
<value>
<string>
context
</string>
</value>
</item>
<item>
<key>
<string>
name_m_self
</string>
</key>
<value>
<string>
script
</string>
</value>
</item>
<item>
<key>
<string>
name_subpath
</string>
</key>
<value>
<string>
traverse_subpath
</string>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key>
<string>
_params
</string>
</key>
<value>
<string>
REQUEST=None, **kw
</string>
</value>
</item>
<item>
<key>
<string>
_proxy_roles
</string>
</key>
<value>
<tuple>
<string>
Manager
</string>
</tuple>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
Base_getUnrestrictedDocumentUrl
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_jio_api_style/SkinTemplateItem/portal_skins/slapos_jio_api/jIOWebSection_getObjectFromData.py
View file @
1eefa336
...
@@ -5,7 +5,6 @@ if portal_type == "Software Installation":
...
@@ -5,7 +5,6 @@ if portal_type == "Software Installation":
if
"compute_node_id"
in
data_dict
and
"software_release_uri"
in
data_dict
:
if
"compute_node_id"
in
data_dict
and
"software_release_uri"
in
data_dict
:
compute_node
=
portal
.
portal_catalog
.
getComputeNodeObject
(
compute_node
=
portal
.
portal_catalog
.
getComputeNodeObject
(
data_dict
[
"compute_node_id"
],
data_dict
[
"compute_node_id"
],
raise_not_found
=
False
,
)
)
if
compute_node
:
if
compute_node
:
return
compute_node
.
getSoftwareInstallationFromUrl
(
data_dict
[
"software_release_uri"
])
return
compute_node
.
getSoftwareInstallationFromUrl
(
data_dict
[
"software_release_uri"
])
...
...
master/bt5/slapos_jio_api_style/SkinTemplateItem/portal_skins/slapos_jio_api/jIOWebSection_requestComputerPartition.py
View file @
1eefa336
...
@@ -4,12 +4,6 @@ compute_partition_id = data_dict.get("compute_partition_id", None)
...
@@ -4,12 +4,6 @@ compute_partition_id = data_dict.get("compute_partition_id", None)
class
SoftwareInstanceNotReady
(
Exception
):
class
SoftwareInstanceNotReady
(
Exception
):
pass
pass
class
NotFound
(
Exception
):
pass
class
Unauthorized
(
Exception
):
pass
castToStr
=
context
.
Base_castDictToXMLString
castToStr
=
context
.
Base_castDictToXMLString
def
logError
(
e
,
error_name
=
""
,
error_code
=
400
,
detail_list
=
None
):
def
logError
(
e
,
error_name
=
""
,
error_code
=
400
,
detail_list
=
None
):
...
@@ -20,73 +14,8 @@ def logError(e, error_name="", error_code=400, detail_list=None):
...
@@ -20,73 +14,8 @@ def logError(e, error_name="", error_code=400, detail_list=None):
detail_list
=
detail_list
,
detail_list
=
detail_list
,
)
)
LOG
=
context
.
log
portal
=
context
.
getPortalObject
()
portal
=
context
.
getPortalObject
()
def
_assertACI
(
document
):
if
context
.
Base_checkPermission
(
document
.
relative_url
,
'View'
):
return
document
.
getObject
()
raise
Unauthorized
(
'User has no access to %r'
%
(
document
.
relative_url
))
def
getDocument
(
**
kwargs
):
# No need to get all results if an error is raised when at least 2 objects
# are found
l
=
portal
.
portal_catalog
.
unrestrictedSearchResults
(
limit
=
2
,
select_list
=
(
"relative_url"
,
"uid"
),
**
kwargs
)
if
len
(
l
)
!=
1
:
raise
NotFound
,
"No document found with parameters: %s"
%
kwargs
else
:
return
_assertACI
(
l
[
0
])
def
getNonCachedComputeNodeUidByReference
(
compute_node_reference
):
return
portal
.
portal_catalog
.
unrestrictedSearchResults
(
portal_type
=
'Compute Node'
,
reference
=
compute_node_reference
,
validation_state
=
"validated"
)[
0
].
UID
def
getComputePartitionDocument
(
compute_node_reference
,
compute_partition_reference
):
"""
Get the compute partition defined in an available compute_node
"""
# Related key might be nice
return
getDocument
(
portal_type
=
'Compute Partition'
,
reference
=
compute_partition_reference
,
parent_uid
=
getNonCachedComputeNodeUidByReference
(
compute_node_reference
))
def
getSoftwareInstanceForComputePartition
(
compute_node_id
,
compute_partition_id
,
slave_reference
=
None
):
compute_partition_document
=
getComputePartitionDocument
(
compute_node_id
,
compute_partition_id
)
if
compute_partition_document
.
getSlapState
()
!=
'busy'
:
LOG
(
'SlapTool::_getSoftwareInstanceForComputePartition'
+
'Compute partition %s shall be busy, is free'
%
compute_partition_document
.
getRelativeUrl
())
raise
NotFound
,
"No software instance found for: %s - %s"
%
(
compute_node_id
,
compute_partition_id
)
else
:
query_kw
=
{
'validation_state'
:
'validated'
,
'portal_type'
:
'Slave Instance'
,
'default_aggregate_uid'
:
compute_partition_document
.
getUid
(),
}
if
slave_reference
is
None
:
query_kw
[
'portal_type'
]
=
"Software Instance"
else
:
query_kw
[
'reference'
]
=
slave_reference
software_instance
=
_assertACI
(
portal
.
portal_catalog
.
unrestrictedGetResultValue
(
**
query_kw
))
if
software_instance
is
None
:
raise
NotFound
,
"No software instance found for: %s - %s"
%
(
compute_node_id
,
compute_partition_id
)
else
:
return
software_instance
# Loads partition parameter
# Loads partition parameter
partition_parameter
=
data_dict
.
get
(
"parameters"
,
None
)
partition_parameter
=
data_dict
.
get
(
"parameters"
,
None
)
if
partition_parameter
:
if
partition_parameter
:
...
@@ -120,12 +49,13 @@ try:
...
@@ -120,12 +49,13 @@ try:
shared
=
data_dict
.
get
(
"shared"
,
False
),
shared
=
data_dict
.
get
(
"shared"
,
False
),
sla_xml
=
castToStr
(
filter_kw
),
sla_xml
=
castToStr
(
filter_kw
),
state
=
data_dict
.
get
(
"state"
,
"started"
))
state
=
data_dict
.
get
(
"state"
,
"started"
))
#raise ValueError("%s" % kw)
if
compute_node_id
and
compute_partition_id
:
if
compute_node_id
and
compute_partition_id
:
requester
=
getSoftwareInstanceForComputePartition
(
compute_partition
=
portal
.
portal_catalog
.
getComputePartitionObject
(
compute_node_id
,
compute_node_id
,
compute_partition_id
)
compute_partition_id
,
)
requester
=
compute_partition
.
getSoftwareInstance
()
instance_tree
=
requester
.
getSpecialiseValue
()
instance_tree
=
requester
.
getSpecialiseValue
()
if
instance_tree
is
not
None
and
instance_tree
.
getSlapState
()
==
"stop_requested"
:
if
instance_tree
is
not
None
and
instance_tree
.
getSlapState
()
==
"stop_requested"
:
kw
[
'state'
]
=
'stopped'
kw
[
'state'
]
=
'stopped'
...
@@ -172,13 +102,3 @@ except SoftwareInstanceNotReady:
...
@@ -172,13 +102,3 @@ except SoftwareInstanceNotReady:
error_name
=
"SoftwareInstanceNotReady"
,
error_name
=
"SoftwareInstanceNotReady"
,
error_code
=
102
error_code
=
102
)
)
except
Unauthorized
,
log
:
return
logError
(
log
,
error_code
=
401
)
except
NotFound
,
log
:
return
logError
(
log
,
error_code
=
404
)
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