]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/restful/api/request.py
1 from pecan
import expose
, request
, response
2 from pecan
.rest
import RestController
4 from restful
import context
5 from restful
.decorators
import auth
, lock
, paginate
8 class RequestId(RestController
):
9 def __init__(self
, request_id
):
10 self
.request_id
= request_id
13 @expose(template
='json')
15 def get(self
, **kwargs
):
17 Show the information for the request id
19 request
= [x
for x
in context
.instance
.requests
20 if x
.id == self
.request_id
]
23 return {'message': 'Unknown request id "{}"'.format(self
.request_id
)}
27 @expose(template
='json')
30 def delete(self
, **kwargs
):
32 Remove the request id from the database
34 for index
in range(len(context
.instance
.requests
)):
35 if context
.instance
.requests
[index
].id == self
.request_id
:
36 return context
.instance
.requests
.pop(index
)
38 # Failed to find the job to cancel
40 return {'message': 'No such request id'}
44 class Request(RestController
):
45 @expose(template
='json')
48 def get(self
, **kwargs
):
50 List all the available requests
52 return context
.instance
.requests
55 @expose(template
='json')
58 def delete(self
, **kwargs
):
60 Remove all the finished requests
62 num_requests
= len(context
.instance
.requests
)
64 context
.instance
.requests
= [x
for x
in context
.instance
.requests
65 if not x
.is_finished()]
66 remaining
= len(context
.instance
.requests
)
67 # Return the job statistics
69 'cleaned': num_requests
- remaining
,
70 'remaining': remaining
,
74 @expose(template
='json')
76 def post(self
, **kwargs
):
78 Pass through method to create any request
80 if isinstance(request
.json
, list):
81 if all(isinstance(element
, list) for element
in request
.json
):
82 return context
.instance
.submit_request(request
.json
, **kwargs
)
84 # The request.json has wrong format
86 return {'message': 'The request format should be [[{c1},{c2}]]'}
88 return context
.instance
.submit_request([[request
.json
]], **kwargs
)
92 def _lookup(self
, request_id
, *remainder
):
93 return RequestId(request_id
), remainder