Merge "Fix "Illegal option -o pipefail" problem and correct the parser path."
[releng.git] / utils / test / result_collection_api / resources / pod_handlers.py
1 from tornado import gen
2 from tornado.web import asynchronous
3
4 from tornado_swagger_ui.tornado_swagger import swagger
5 from handlers import GenericApiHandler
6 from pod_models import Pod
7
8
9 class GenericPodHandler(GenericApiHandler):
10     def __init__(self, application, request, **kwargs):
11         super(GenericPodHandler, self).__init__(application, request, **kwargs)
12         self.table = 'pods'
13         self.table_cls = Pod
14
15
16 class PodCLHandler(GenericPodHandler):
17     @swagger.operation(nickname='list-all')
18     def get(self):
19         """
20             @description: list all pods
21             @return 200: list all pods, empty list is no pod exist
22             @rtype: L{Pods}
23         """
24         self._list()
25
26     @gen.coroutine
27     @swagger.operation(nickname='create')
28     def post(self):
29         """
30             @description: create a pod
31             @param body: pod to be created
32             @type body: L{PodCreateRequest}
33             @in body: body
34             @rtype: L{Pod}
35             @return 200: pod is created.
36             @raise 403: pod already exists
37             @raise 400: post without body
38         """
39         self._create('{} already exists as a {}')
40
41
42 class PodGURHandler(GenericPodHandler):
43     @swagger.operation(nickname='get-one')
44     def get(self, pod_name):
45         """
46             @description: get a single pod by pod_name
47             @rtype: L{Pod}
48             @return 200: pod exist
49             @raise 404: pod not exist
50         """
51         query = dict()
52         query['name'] = pod_name
53         self._get_one(query)
54
55     @asynchronous
56     @gen.coroutine
57     def delete(self, pod_name):
58         """ Remove a POD
59
60         # check for an existing pod to be deleted
61         mongo_dict = yield self.db.pods.find_one(
62             {'name': pod_name})
63         pod = TestProject.pod(mongo_dict)
64         if pod is None:
65             raise HTTPError(HTTP_NOT_FOUND,
66                             "{} could not be found as a pod to be deleted"
67                             .format(pod_name))
68
69         # just delete it, or maybe save it elsewhere in a future
70         res = yield self.db.projects.remove(
71             {'name': pod_name})
72
73         self.finish_request(answer)
74         """
75         pass