1 from tornado import gen
2 from tornado.web import HTTPError, asynchronous
4 from tornado_swagger_ui.tornado_swagger import swagger
5 from handlers import GenericApiHandler
6 from common.constants import HTTP_BAD_REQUEST, HTTP_FORBIDDEN
7 from pod_models import Pod
10 class PodCLHandler(GenericApiHandler):
12 super(PodCLHandler, self).initialize()
14 @swagger.operation(nickname='list-all')
17 @description: list all PODs
18 @return 200: list all pods, empty list is no pod exist
21 self._list('pods', Pod)
25 @swagger.operation(nickname='create')
28 @description: Create a POD
29 @param body: pod information to be created
30 @type body: L{PodCreateRequest}
32 @return 200: pod is created.
34 @raise 403: already exists as a pod
35 @raise 400: bad request
37 if self.json_args is None:
38 raise HTTPError(HTTP_BAD_REQUEST, 'no payload')
40 pod = Pod.from_dict(self.json_args)
42 if name is None or name == '':
43 raise HTTPError(HTTP_BAD_REQUEST, 'pod name missing')
45 the_pod = yield self.db.pods.find_one({'name': name})
46 if the_pod is not None:
47 raise HTTPError(HTTP_FORBIDDEN,
48 "{} already exists as a pod".format(
49 self.json_args.get("name")))
50 self._create('pods', pod, name)
53 class PodGURHandler(GenericApiHandler):
55 super(PodGURHandler, self).initialize()
57 @swagger.operation(nickname='get-one')
58 def get(self, pod_name=None):
60 @description: Get a single pod by pod_name
61 @return 200: pod exist
62 @raise 404: pod not exist
66 query["name"] = pod_name
67 self._get_one('pods', Pod, query)
71 def delete(self, pod_name):
74 # check for an existing pod to be deleted
75 mongo_dict = yield self.db.pods.find_one(
77 pod = TestProject.pod(mongo_dict)
79 raise HTTPError(HTTP_NOT_FOUND,
80 "{} could not be found as a pod to be deleted"
83 # just delete it, or maybe save it elsewhere in a future
84 res = yield self.db.projects.remove(
87 self.finish_request(answer)