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
Ivan Tyagov
slapos.core
Commits
a814846f
Commit
a814846f
authored
Sep 11, 2012
by
Romain Courteaud
Committed by
Cédric de Saint Martin
Sep 12, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a simple status publisher for computer and instance
parent
13161c8d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
1 deletion
+75
-1
master/bt5/vifib_slapos_rest_api_v1/DocumentTemplateItem/portal_components/VifibRestAPIV1.py
.../DocumentTemplateItem/portal_components/VifibRestAPIV1.py
+74
-0
master/bt5/vifib_slapos_rest_api_v1/bt/revision
master/bt5/vifib_slapos_rest_api_v1/bt/revision
+1
-1
No files found.
master/bt5/vifib_slapos_rest_api_v1/DocumentTemplateItem/portal_components/VifibRestAPIV1.py
View file @
a814846f
...
...
@@ -491,6 +491,74 @@ class ComputerPublisher(GenericPublisher):
self
.
REQUEST
.
response
.
setStatus
(
204
)
return
self
.
REQUEST
.
response
class
StatusPublisher
(
GenericPublisher
):
@
responseSupport
()
def
__call__
(
self
):
"""Log GET support"""
if
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'POST'
:
self
.
REQUEST
.
response
.
setStatus
(
404
)
return
self
.
REQUEST
.
response
elif
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'GET'
:
if
self
.
REQUEST
[
'traverse_subpath'
]:
self
.
__status_info
()
else
:
self
.
__status_list
()
def
__status_list
(
self
):
kw
=
dict
(
portal_type
=
(
'Computer'
,
'Software Instance'
),
)
d
=
{
"list"
:
[]}
a
=
d
[
'list'
].
append
for
si
in
self
.
getPortalObject
().
portal_catalog
(
**
kw
):
a
(
'/'
.
join
([
self
.
getAPIRoot
(),
'status'
,
si
.
getRelativeUrl
()]))
try
:
d
[
'list'
][
0
]
except
IndexError
:
# no results, so nothing to return
self
.
REQUEST
.
response
.
setStatus
(
204
)
else
:
self
.
REQUEST
.
response
.
setStatus
(
200
)
self
.
REQUEST
.
response
.
setHeader
(
'Cache-Control'
,
'max-age=300, private'
)
self
.
REQUEST
.
response
.
setBody
(
jsonify
(
d
))
return
self
.
REQUEST
.
response
# XXX Use a decated document to keep the history
@
extractDocument
([
'Computer'
,
'Software Instance'
])
# @supportModifiedSince('document_url')
def
__status_info
(
self
):
certificate
=
False
document
=
self
.
restrictedTraverse
(
self
.
document_url
)
try
:
memcached_dict
=
self
.
getPortalObject
().
portal_memcached
.
getMemcachedDict
(
key_prefix
=
'slap_tool'
,
plugin_path
=
'portal_memcached/default_memcached_plugin'
)
try
:
d
=
memcached_dict
[
document
.
getReference
()]
except
KeyError
:
d
=
{
"user"
:
"SlapOS Master"
,
'created_at'
:
'%s'
%
rfc1123_date
(
DateTime
()),
"text"
:
"#error no data found for %s"
%
document
.
getReference
()
}
else
:
d
=
json
.
loads
(
d
)
except
Exception
:
LOG
(
'VifibRestApiV1'
,
ERROR
,
'Problem while trying to generate status information:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
jsonify
({
'error'
:
'There is system issue, please try again later.'
}))
else
:
d
[
'@document'
]
=
self
.
document_url
self
.
REQUEST
.
response
.
setStatus
(
200
)
self
.
REQUEST
.
response
.
setHeader
(
'Cache-Control'
,
'max-age=300, private'
)
self
.
REQUEST
.
response
.
setBody
(
jsonify
(
d
))
return
self
.
REQUEST
.
response
class
VifibRestAPIV1
(
Implicit
):
security
=
ClassSecurityInfo
()
security
.
declareObjectProtected
(
Permissions
.
AccessContentsInformation
)
...
...
@@ -512,6 +580,12 @@ class VifibRestAPIV1(Implicit):
"""Computer publisher"""
return
ComputerPublisher
().
__of__
(
self
)
security
.
declarePublic
(
'log'
)
@
ComputedAttribute
def
status
(
self
):
"""Status publisher"""
return
StatusPublisher
().
__of__
(
self
)
@
responseSupport
(
True
)
def
OPTIONS
(
self
,
*
args
,
**
kwargs
):
"""HTTP OPTIONS implementation"""
...
...
master/bt5/vifib_slapos_rest_api_v1/bt/revision
View file @
a814846f
16
\ No newline at end of file
17
\ No newline at end of file
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