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
Łukasz Nowak
slapos.core
Commits
03bc7006
Commit
03bc7006
authored
May 10, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support instance PUT.
parent
60b7e90d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
3 deletions
+44
-3
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+44
-3
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
03bc7006
...
...
@@ -68,7 +68,9 @@ def requireHeader(header_dict):
return
wrapperRequireHeader
return
outer
def
requireJson
(
json_dict
):
def
requireJson
(
json_dict
,
optional_key_list
=
None
):
if
optional_key_list
is
None
:
optional_key_list
=
[]
def
outer
(
fn
):
def
wrapperRequireJson
(
self
,
*
args
,
**
kwargs
):
self
.
REQUEST
.
stdin
.
seek
(
0
)
...
...
@@ -83,8 +85,9 @@ def requireJson(json_dict):
error_dict
=
{}
for
key
,
type_
in
json_dict
.
iteritems
():
if
key
not
in
self
.
jbody
:
error_dict
[
key
]
=
'Missing.'
elif
not
isinstance
(
self
.
jbody
[
key
],
type_
):
if
key
not
in
optional_key_list
:
error_dict
[
key
]
=
'Missing.'
elif
key
in
self
.
jbody
and
not
isinstance
(
self
.
jbody
[
key
],
type_
):
error_dict
[
key
]
=
'%s is not %s.'
%
(
type
(
self
.
jbody
[
key
]).
__name__
,
type_
.
__name__
)
if
error_dict
:
...
...
@@ -179,6 +182,44 @@ class GenericPublisher(Implicit):
class
InstancePublisher
(
GenericPublisher
):
"""Instance publisher"""
@
requireHeader
({
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
})
@
requireJson
(
dict
(
title
=
unicode
,
status
=
unicode
,
log
=
unicode
,
connection
=
dict
),
[
'title'
,
'status'
,
'log'
,
'connection'
])
@
extractInstance
def
PUT
(
self
):
"""Instance PUT support"""
d
=
{}
try
:
self
.
REQUEST
.
response
.
setStatus
(
204
)
software_instance
=
self
.
restrictedTraverse
(
self
.
software_instance_url
)
if
'title'
in
self
.
jbody
and
\
software_instance
.
getTitle
()
!=
self
.
jbody
[
'title'
]:
software_instance
.
setTitle
(
self
.
jbody
[
'title'
])
d
[
'title'
]
=
'Modified.'
self
.
REQUEST
.
response
.
setStatus
(
200
)
if
'connection'
in
self
.
jbody
:
xml
=
etreeXml
(
self
.
jbody
[
'connection'
])
if
xml
!=
software_instance
.
getConnectionXml
():
software_instance
.
setConnectionXml
(
xml
)
d
[
'connection'
]
=
'Modified.'
self
.
REQUEST
.
response
.
setStatus
(
200
)
except
Exception
:
transaction
.
abort
()
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while modifying:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
'There is system issue, please try again later.'
}))
else
:
if
d
:
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
d
))
return
self
.
REQUEST
.
response
@
requireHeader
({
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
})
@
requireJson
(
dict
(
log
=
unicode
))
...
...
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