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
Ophélie Gagnard
slapos.core
Commits
25ed7ce8
Commit
25ed7ce8
authored
May 04, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement software instance bang.
parent
77af3b71
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
1 deletion
+71
-1
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+71
-1
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
25ed7ce8
...
...
@@ -100,6 +100,73 @@ class GenericPublisher(Implicit):
class
InstancePublisher
(
GenericPublisher
):
"""Instance publisher"""
@
requireHeader
({
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
})
def
__bang
(
self
):
self
.
REQUEST
.
stdin
.
seek
(
0
)
try
:
jbody
=
json
.
load
(
self
.
REQUEST
.
stdin
)
except
Exception
:
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
{
'error'
:
'Data is not json object.'
}))
return
self
.
REQUEST
.
response
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
if
person
is
None
:
transaction
.
abort
()
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Currenty logged in user %r has no Person document.'
%
self
.
getPortalObject
().
getAuthenticatedMember
())
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
'There is system issue, please try again later.'
}))
return
self
.
REQUEST
.
response
instance_path
=
'/'
.
join
(
self
.
REQUEST
[
'traverse_subpath'
][:
-
1
])
error_dict
=
{}
if
'log'
not
in
jbody
:
error_dict
[
'log'
]
=
"Missing."
elif
not
isinstance
(
jbody
[
'log'
],
unicode
):
error_dict
[
'log'
]
=
'Not a string.'
else
:
log
=
str
(
jbody
[
'log'
])
if
error_dict
:
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
error_dict
))
return
self
.
REQUEST
.
response
try
:
software_instance
=
self
.
restrictedTraverse
(
instance_path
)
if
getattr
(
software_instance
,
'getPortalType'
,
None
)
is
None
or
\
software_instance
.
getPortalType
()
not
in
(
'Software Instance'
,
'Slave Instance'
):
raise
WrongRequest
(
'%r is not an instance'
%
instance_path
)
except
WrongRequest
:
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while trying to find instance:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
404
)
except
(
Unauthorized
,
KeyError
):
self
.
REQUEST
.
response
.
setStatus
(
404
)
except
Exception
:
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while trying to find instance:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
'There is system issue, please try again later.'
}))
else
:
try
:
software_instance
.
reportComputerPartitionBang
(
comment
=
log
)
except
Exception
:
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while trying to generate instance dict:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
'There is system issue, please try again later.'
}))
else
:
self
.
REQUEST
.
response
.
setStatus
(
204
)
return
self
.
REQUEST
.
response
@
requireHeader
({
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
})
def
__request
(
self
):
...
...
@@ -230,6 +297,9 @@ class InstancePublisher(GenericPublisher):
def
__call__
(
self
):
"""Instance GET/POST support"""
if
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'POST'
:
if
self
.
REQUEST
[
'traverse_subpath'
][
-
1
]
==
'bang'
:
self
.
__bang
()
else
:
self
.
__request
()
elif
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'GET'
and
\
self
.
REQUEST
[
'traverse_subpath'
]:
...
...
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