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
Hardik Juneja
slapos.core
Commits
071b62c3
Commit
071b62c3
authored
May 09, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract instance in decorator.
parent
21cda2c5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
71 deletions
+63
-71
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+63
-71
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
071b62c3
...
...
@@ -111,6 +111,36 @@ def responseSupport(anonymous=False):
return
wrapperResponseSupport
return
outer
def
extractInstance
(
fn
):
def
wrapperExtractInstance
(
self
,
*
args
,
**
kwargs
):
if
not
self
.
REQUEST
[
'traverse_subpath'
]:
self
.
REQUEST
.
response
.
setStatus
(
404
)
return
self
.
REQUEST
.
response
instance_path
=
self
.
REQUEST
[
'traverse_subpath'
][:
2
]
try
:
self
.
software_instance
=
self
.
restrictedTraverse
(
instance_path
)
if
getattr
(
self
.
software_instance
,
'getPortalType'
,
None
)
is
None
or
\
self
.
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
:
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
):
@
responseSupport
(
True
)
def
OPTIONS
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -131,6 +161,7 @@ class InstancePublisher(GenericPublisher):
@
requireHeader
({
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
})
@
requireJson
(
dict
(
log
=
unicode
))
@
extractInstance
def
__bang
(
self
):
person
=
self
.
getPortalObject
().
ERP5Site_getAuthenticatedMemberPersonValue
()
if
person
is
None
:
...
...
@@ -142,28 +173,8 @@ class InstancePublisher(GenericPublisher):
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
])
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
=
self
.
jbody
[
'log'
])
self
.
software_instance
.
reportComputerPartitionBang
(
comment
=
self
.
jbody
[
'log'
])
except
Exception
:
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while trying to generate instance dict:'
,
error
=
True
)
...
...
@@ -230,49 +241,30 @@ class InstancePublisher(GenericPublisher):
return
response
@
requireHeader
({
'Accept'
:
'application/json'
})
@
extractInstance
def
__instance_info
(
self
):
certificate
=
False
if
self
.
REQUEST
[
'traverse_subpath'
][
-
1
]
==
'certificate'
:
if
self
.
REQUEST
[
'traverse_subpath'
]
and
self
.
REQUEST
[
'traverse_subpath'
][
-
1
]
==
'certificate'
:
certificate
=
True
self
.
REQUEST
[
'traverse_subpath'
]
=
self
.
REQUEST
[
'traverse_subpath'
][:
-
1
]
instance_path
=
'/'
.
join
(
self
.
REQUEST
[
'traverse_subpath'
])
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
:
if
certificate
:
d
=
{
"ssl_key"
:
software_instance
.
getSslKey
(),
"ssl_certificate"
:
software_instance
.
getSslCertificate
()
"ssl_key"
:
self
.
software_instance
.
getSslKey
(),
"ssl_certificate"
:
self
.
software_instance
.
getSslCertificate
()
}
else
:
d
=
{
"title"
:
software_instance
.
getTitle
(),
"status"
:
software_instance
.
getSlapState
(),
"title"
:
self
.
software_instance
.
getTitle
(),
"status"
:
self
.
software_instance
.
getSlapState
(),
"software_release"
:
""
,
# not ready yet
"software_type"
:
software_instance
.
getSourceReference
(),
"slave"
:
software_instance
.
getPortalType
()
==
'Slave Instance'
,
"connection"
:
software_instance
.
getConnectionXmlAsDict
(),
"parameter"
:
software_instance
.
getInstanceXmlAsDict
(),
"sla"
:
software_instance
.
getSlaXmlAsDict
(),
"software_type"
:
self
.
software_instance
.
getSourceReference
(),
"slave"
:
self
.
software_instance
.
getPortalType
()
==
'Slave Instance'
,
"connection"
:
self
.
software_instance
.
getConnectionXmlAsDict
(),
"parameter"
:
self
.
software_instance
.
getInstanceXmlAsDict
(),
"sla"
:
self
.
software_instance
.
getSlaXmlAsDict
(),
"children_list"
:
[
q
.
absolute_url
()
for
q
in
\
software_instance
.
getPredecessorValueList
()],
self
.
software_instance
.
getPredecessorValueList
()],
"partition"
:
{
# not ready yet
"public_ip"
:
[],
"private_ip"
:
[],
...
...
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