1 from opnfv_testapi.tornado_swagger import swagger
2 from handlers import GenericApiHandler
3 from pod_models import Pod
4 from opnfv_testapi.common.constants import HTTP_FORBIDDEN
7 class GenericPodHandler(GenericApiHandler):
8 def __init__(self, application, request, **kwargs):
9 super(GenericPodHandler, self).__init__(application, request, **kwargs)
14 class PodCLHandler(GenericPodHandler):
15 @swagger.operation(nickname='list-all')
18 @description: list all pods
19 @return 200: list all pods, empty list is no pod exist
24 @swagger.operation(nickname='create')
27 @description: create a pod
28 @param body: pod to be created
29 @type body: L{PodCreateRequest}
32 @return 200: pod is created.
33 @raise 403: pod already exists
34 @raise 400: body or name not provided
37 return {'name': data.name}
40 message = '{} already exists as a pod'.format(data.name)
41 return HTTP_FORBIDDEN, message
43 miss_checks = ['name']
44 db_checks = [(self.table, False, query, error)]
45 self._create(miss_checks, db_checks)
48 class PodGURHandler(GenericPodHandler):
49 @swagger.operation(nickname='get-one')
50 def get(self, pod_name):
52 @description: get a single pod by pod_name
54 @return 200: pod exist
55 @raise 404: pod not exist
58 query['name'] = pod_name
61 def delete(self, pod_name):
64 # check for an existing pod to be deleted
65 mongo_dict = yield self.db.pods.find_one(
67 pod = TestProject.pod(mongo_dict)
69 raise HTTPError(HTTP_NOT_FOUND,
70 "{} could not be found as a pod to be deleted"
73 # just delete it, or maybe save it elsewhere in a future
74 res = yield self.db.projects.remove(
77 self.finish_request(answer)