]>
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 module
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
20 lambda x
: x
.id == self
.request_id
,
21 module
.instance
.requests
26 return {'message': 'Unknown request id "%s"' % str(self
.request_id
)}
32 @expose(template
='json')
35 def delete(self
, **kwargs
):
37 Remove the request id from the database
39 for index
in range(len(module
.instance
.requests
)):
40 if module
.instance
.requests
[index
].id == self
.request_id
:
41 return module
.instance
.requests
.pop(index
)
43 # Failed to find the job to cancel
45 return {'message': 'No such request id'}
49 class Request(RestController
):
50 @expose(template
='json')
53 def get(self
, **kwargs
):
55 List all the available requests
57 return module
.instance
.requests
60 @expose(template
='json')
63 def delete(self
, **kwargs
):
65 Remove all the finished requests
67 num_requests
= len(module
.instance
.requests
)
69 module
.instance
.requests
= filter(
70 lambda x
: not x
.is_finished(),
71 module
.instance
.requests
74 # Return the job statistics
76 'cleaned': num_requests
- len(module
.instance
.requests
),
77 'remaining': len(module
.instance
.requests
),
81 @expose(template
='json')
83 def post(self
, **kwargs
):
85 Pass through method to create any request
87 return module
.instance
.submit_request([[request
.json
]], **kwargs
)
91 def _lookup(self
, request_id
, *remainder
):
92 return RequestId(request_id
), remainder