Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
108
Merge Requests
108
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos
Commits
4826d3f8
Commit
4826d3f8
authored
Apr 27, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace delete with request.
Delete is not in API, so implement request instead.
parent
e0ae42d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
16 deletions
+61
-16
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+61
-16
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
4826d3f8
...
@@ -34,6 +34,16 @@ from AccessControl import ClassSecurityInfo, getSecurityManager
...
@@ -34,6 +34,16 @@ from AccessControl import ClassSecurityInfo, getSecurityManager
from
Products.ERP5Type.Globals
import
InitializeClass
from
Products.ERP5Type.Globals
import
InitializeClass
from
Products.ERP5Type
import
Permissions
from
Products.ERP5Type
import
Permissions
from
ComputedAttribute
import
ComputedAttribute
from
ComputedAttribute
import
ComputedAttribute
from
zLOG
import
LOG
,
INFO
import
json
import
transaction
def
jsonResponse
(
fn
):
def
wrapper
(
self
,
*
args
,
**
kwargs
):
self
.
REQUEST
.
response
.
setHeader
(
'Content-Type'
,
'application/json'
)
return
fn
(
self
,
*
args
,
**
kwargs
)
wrapper
.
__doc__
=
fn
.
__doc__
return
wrapper
def
responseSupport
(
fn
):
def
responseSupport
(
fn
):
def
wrapper
(
self
,
*
args
,
**
kwargs
):
def
wrapper
(
self
,
*
args
,
**
kwargs
):
...
@@ -72,30 +82,65 @@ class GenericPublisher(Implicit):
...
@@ -72,30 +82,65 @@ class GenericPublisher(Implicit):
class
InstancePublisher
(
GenericPublisher
):
class
InstancePublisher
(
GenericPublisher
):
"""Instance publisher"""
"""Instance publisher"""
@
responseSupport
@
jsonResponse
def
DELETE
(
self
,
*
args
,
**
kwargs
):
def
__request
(
self
):
"""HTTP DELETE implementation"""
response
=
self
.
REQUEST
.
response
response
=
self
.
REQUEST
.
response
self
.
REQUEST
.
stdin
.
seek
(
0
)
try
:
try
:
instance_id
=
self
.
REQUEST
[
'traverse_subpath'
][
0
]
jbody
=
json
.
load
(
self
.
REQUEST
.
stdin
)
except
IndexError
:
except
Exception
:
response
.
setStatus
(
400
)
response
.
setStatus
(
400
)
response
.
setBody
(
json
.
dumps
({
'error'
:
'Data is not json object.'
}))
return
response
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
if
person
is
None
:
response
.
setStatus
(
404
)
response
.
setBody
(
json
.
dumps
({
'error'
:
'User does not exists.'
}))
request_dict
=
{}
error_dict
=
{}
for
k_j
,
k_i
in
(
(
'software_release'
,
'software_release'
),
(
'title'
,
'software_title'
),
(
'software_type'
,
'software_type'
),
(
'parameter'
,
'instance_xml'
),
(
'sla'
,
'sla_xml'
),
(
'slave'
,
'shared'
),
(
'status'
,
'state'
)
):
try
:
request_dict
[
k_i
]
=
jbody
[
k_j
]
except
KeyError
:
error_dict
[
k_j
]
=
'Missing.'
if
error_dict
:
response
.
setStatus
(
400
)
response
.
setBody
(
json
.
dumps
(
error_dict
))
return
response
try
:
person
.
requestSoftwareInstance
(
**
request_dict
)
except
Exception
:
transaction
.
abort
()
LOG
(
'VifibRestApiV1Tool'
,
INFO
,
'Problem with request.'
,
error
=
True
)
response
.
setStatus
(
500
)
response
.
setBody
(
json
.
dumps
({
'error'
:
'There is system issue, please try again later'
}))
return
response
return
response
portal
=
self
.
getPortalObject
()
person
=
portal
.
ERP5Site_getAuthenticatedMemberPersonValue
()
person
.
requestSoftwareInstance
(
software_release
=
''
,
software_title
=
instance_id
,
software_type
=
''
,
shared
=
''
,
instance_xml
=
''
,
sla_xml
=
''
,
state
=
'destroyed'
)
response
.
setStatus
(
202
)
response
.
setStatus
(
202
)
response
.
setBody
(
json
.
dumps
({
'status'
:
'processing'
}))
return
response
return
response
@
responseSupport
def
__call__
(
self
):
"""Instance GET/POST support"""
if
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'POST'
:
self
.
__request
()
class
VifibRestApiV1Tool
(
BaseTool
):
class
VifibRestApiV1Tool
(
BaseTool
):
"""SlapOS REST API V1 Tool"""
"""SlapOS REST API V1 Tool"""
...
...
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