1 ##############################################################################
2 # Copyright (c) 2015 Orange
3 # guyrodrigue.koffi@orange.com / koffirodrigue@gmail.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
12 from opnfv_testapi.tornado_swagger import swagger
16 class GenericPodHandler(handlers.GenericApiHandler):
17 def __init__(self, application, request, **kwargs):
18 super(GenericPodHandler, self).__init__(application, request, **kwargs)
20 self.table_cls = pod_models.Pod
23 class PodCLHandler(GenericPodHandler):
24 @swagger.operation(nickname='listAllPods')
27 @description: list all pods
28 @return 200: list all pods, empty list is no pod exist
33 @swagger.operation(nickname='createPod')
36 @description: create a pod
37 @param body: pod to be created
38 @type body: L{PodCreateRequest}
40 @rtype: L{CreateResponse}
41 @return 200: pod is created.
42 @raise 403: pod already exists
43 @raise 400: body or name not provided
46 return {'name': data.name}
49 message = '{} already exists as a pod'.format(data.name)
50 return httplib.FORBIDDEN, message
52 miss_checks = ['name']
53 db_checks = [(self.table, False, query, error)]
54 self._create(miss_checks, db_checks)
57 class PodGURHandler(GenericPodHandler):
58 @swagger.operation(nickname='getPodByName')
59 def get(self, pod_name):
61 @description: get a single pod by pod_name
63 @return 200: pod exist
64 @raise 404: pod not exist
67 query['name'] = pod_name
70 def delete(self, pod_name):
73 # check for an existing pod to be deleted
74 mongo_dict = yield self.db.pods.find_one(
76 pod = TestProject.pod(mongo_dict)
78 raise HTTPError(HTTP_NOT_FOUND,
79 "{} could not be found as a pod to be deleted"
82 # just delete it, or maybe save it elsewhere in a future
83 res = yield self.db.projects.remove(
86 self.finish_request(answer)