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
Eric Zheng
slapos.core
Commits
b52627e3
Commit
b52627e3
authored
May 21, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make method more extensible.
parent
e9c91a5c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
37 deletions
+41
-37
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+41
-37
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
b52627e3
...
@@ -190,37 +190,41 @@ def responseSupport(anonymous=False):
...
@@ -190,37 +190,41 @@ def responseSupport(anonymous=False):
return
wrapperResponseSupport
return
wrapperResponseSupport
return
outer
return
outer
def
extractInstance
(
fn
):
def
extractDocument
(
portal_type
):
def
wrapperExtractInstance
(
self
,
*
args
,
**
kwargs
):
if
not
isinstance
(
portal_type
,
(
list
,
tuple
)):
if
not
self
.
REQUEST
[
'traverse_subpath'
]:
portal_type
=
[
portal_type
]
self
.
REQUEST
.
response
.
setStatus
(
404
)
def
outer
(
fn
):
def
wrapperExtractDocument
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
REQUEST
[
'traverse_subpath'
]:
self
.
REQUEST
.
response
.
setStatus
(
404
)
return
self
.
REQUEST
.
response
path
=
self
.
REQUEST
[
'traverse_subpath'
][:
2
]
try
:
document
=
self
.
getPortalObject
().
restrictedTraverse
(
path
)
if
getattr
(
document
,
'getPortalType'
,
None
)
is
None
or
\
document
.
getPortalType
()
not
in
portal_type
:
raise
WrongRequest
(
'%r is neiter of %s'
%
(
path
,
', '
.
join
(
portal_type
)))
self
.
document_url
=
document
.
getRelativeUrl
()
except
WrongRequest
:
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while trying to find document:'
,
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
(
jsonify
({
'error'
:
'There is system issue, please try again later.'
}))
else
:
self
.
REQUEST
[
'traverse_subpath'
]
=
self
.
REQUEST
[
'traverse_subpath'
][
2
:]
return
fn
(
self
,
*
args
,
**
kwargs
)
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
instance_path
=
self
.
REQUEST
[
'traverse_subpath'
][:
2
]
wrapperExtractDocument
.
__doc__
=
fn
.
__doc__
try
:
return
wrapperExtractDocument
software_instance
=
self
.
getPortalObject
().
restrictedTraverse
(
instance_path
)
return
outer
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
)
self
.
software_instance_url
=
software_instance
.
getRelativeUrl
()
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
(
jsonify
({
'error'
:
'There is system issue, please try again later.'
}))
else
:
self
.
REQUEST
[
'traverse_subpath'
]
=
self
.
REQUEST
[
'traverse_subpath'
][
2
:]
return
fn
(
self
,
*
args
,
**
kwargs
)
return
self
.
REQUEST
.
response
wrapperExtractInstance
.
__doc__
=
fn
.
__doc__
return
wrapperExtractInstance
class
GenericPublisher
(
Implicit
):
class
GenericPublisher
(
Implicit
):
@
responseSupport
(
True
)
@
responseSupport
(
True
)
...
@@ -246,13 +250,13 @@ class InstancePublisher(GenericPublisher):
...
@@ -246,13 +250,13 @@ class InstancePublisher(GenericPublisher):
title
=
(
unicode
,
encode_utf8
),
title
=
(
unicode
,
encode_utf8
),
connection
=
dict
connection
=
dict
),
[
'title'
,
'connection'
])
),
[
'title'
,
'connection'
])
@
extract
Instance
@
extract
Document
([
'Software Instance'
,
'Slave Instance'
])
def
PUT
(
self
):
def
PUT
(
self
):
"""Instance PUT support"""
"""Instance PUT support"""
d
=
{}
d
=
{}
try
:
try
:
self
.
REQUEST
.
response
.
setStatus
(
204
)
self
.
REQUEST
.
response
.
setStatus
(
204
)
software_instance
=
self
.
restrictedTraverse
(
self
.
software_instance
_url
)
software_instance
=
self
.
restrictedTraverse
(
self
.
document
_url
)
if
'title'
in
self
.
jbody
and
\
if
'title'
in
self
.
jbody
and
\
software_instance
.
getTitle
()
!=
self
.
jbody
[
'title'
]:
software_instance
.
getTitle
()
!=
self
.
jbody
[
'title'
]:
software_instance
.
setTitle
(
self
.
jbody
[
'title'
])
software_instance
.
setTitle
(
self
.
jbody
[
'title'
])
...
@@ -279,10 +283,10 @@ class InstancePublisher(GenericPublisher):
...
@@ -279,10 +283,10 @@ class InstancePublisher(GenericPublisher):
@
requireHeader
({
'Accept'
:
'application/json'
,
@
requireHeader
({
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
})
'Content-Type'
:
'application/json'
})
@
requireJson
(
dict
(
log
=
unicode
))
@
requireJson
(
dict
(
log
=
unicode
))
@
extract
Instance
@
extract
Document
([
'Software Instance'
,
'Slave Instance'
])
def
__bang
(
self
):
def
__bang
(
self
):
try
:
try
:
self
.
restrictedTraverse
(
self
.
software_instance
_url
self
.
restrictedTraverse
(
self
.
document
_url
).
reportComputerPartitionBang
(
comment
=
self
.
jbody
[
'log'
])
).
reportComputerPartitionBang
(
comment
=
self
.
jbody
[
'log'
])
except
Exception
:
except
Exception
:
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
...
@@ -340,11 +344,11 @@ class InstancePublisher(GenericPublisher):
...
@@ -340,11 +344,11 @@ class InstancePublisher(GenericPublisher):
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
@
requireHeader
({
'Accept'
:
'application/json'
})
@
requireHeader
({
'Accept'
:
'application/json'
})
@
extract
Instance
@
extract
Document
([
'Software Instance'
,
'Slave Instance'
])
@
supportModifiedSince
(
'
software_instance
_url'
)
@
supportModifiedSince
(
'
document
_url'
)
def
__instance_info
(
self
):
def
__instance_info
(
self
):
certificate
=
False
certificate
=
False
software_instance
=
self
.
restrictedTraverse
(
self
.
software_instance
_url
)
software_instance
=
self
.
restrictedTraverse
(
self
.
document
_url
)
if
self
.
REQUEST
[
'traverse_subpath'
]
and
self
.
REQUEST
[
if
self
.
REQUEST
[
'traverse_subpath'
]
and
self
.
REQUEST
[
'traverse_subpath'
][
-
1
]
==
'certificate'
:
'traverse_subpath'
][
-
1
]
==
'certificate'
:
certificate
=
True
certificate
=
True
...
...
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