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
Labels
Merge Requests
19
Merge Requests
19
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos.core
Commits
fc7d38f6
Commit
fc7d38f6
authored
May 04, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement GET on instance/id and instance/id/certificate.
parent
03149c28
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
1 deletion
+68
-1
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+68
-1
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
fc7d38f6
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
from
Acquisition
import
Implicit
from
Acquisition
import
Implicit
from
Products.ERP5Type.Tool.BaseTool
import
BaseTool
from
Products.ERP5Type.Tool.BaseTool
import
BaseTool
from
AccessControl
import
ClassSecurityInfo
,
getSecurityManager
from
AccessControl
import
ClassSecurityInfo
,
getSecurityManager
,
Unauthorized
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
...
@@ -39,6 +39,9 @@ import xml_marshaller
...
@@ -39,6 +39,9 @@ import xml_marshaller
import
json
import
json
import
transaction
import
transaction
class
WrongRequest
(
Exception
):
pass
def
requireHeader
(
header_dict
):
def
requireHeader
(
header_dict
):
def
outer
(
fn
):
def
outer
(
fn
):
def
wrapperRequireHeader
(
self
,
*
args
,
**
kwargs
):
def
wrapperRequireHeader
(
self
,
*
args
,
**
kwargs
):
...
@@ -162,11 +165,75 @@ class InstancePublisher(GenericPublisher):
...
@@ -162,11 +165,75 @@ class InstancePublisher(GenericPublisher):
response
.
setBody
(
json
.
dumps
({
'status'
:
'processing'
}))
response
.
setBody
(
json
.
dumps
({
'status'
:
'processing'
}))
return
response
return
response
@
requireHeader
({
'Accept'
:
'application/json'
})
def
__instance_info
(
self
):
certificate
=
False
if
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
()
}
else
:
d
=
{
"title"
:
software_instance
.
getTitle
(),
"status"
:
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
(),
"children_list"
:
[
q
.
absolute_url
()
for
q
in
\
software_instance
.
getPredecessorValueList
()],
"partition"
:
{
# not ready yet
"public_ip"
:
[],
"private_ip"
:
[],
"tap_interface"
:
""
,
}
}
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
(
200
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
d
))
return
self
.
REQUEST
.
response
@
responseSupport
()
@
responseSupport
()
def
__call__
(
self
):
def
__call__
(
self
):
"""Instance GET/POST support"""
"""Instance GET/POST support"""
if
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'POST'
:
if
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'POST'
:
self
.
__request
()
self
.
__request
()
elif
self
.
REQUEST
[
'REQUEST_METHOD'
]
==
'GET'
and
\
self
.
REQUEST
[
'traverse_subpath'
]:
self
.
__instance_info
()
class
VifibRestApiV1Tool
(
BaseTool
):
class
VifibRestApiV1Tool
(
BaseTool
):
...
...
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