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.common import message
13 from opnfv_testapi.tornado_swagger import swagger
17 class GenericPodHandler(handlers.GenericApiHandler):
18 def __init__(self, application, request, **kwargs):
19 super(GenericPodHandler, self).__init__(application, request, **kwargs)
21 self.table_cls = pod_models.Pod
24 class PodCLHandler(GenericPodHandler):
25 @swagger.operation(nickname='listAllPods')
28 @description: list all pods
29 @return 200: list all pods, empty list is no pod exist
34 @swagger.operation(nickname='createPod')
37 @description: create a pod
38 @param body: pod to be created
39 @type body: L{PodCreateRequest}
41 @rtype: L{CreateResponse}
42 @return 200: pod is created.
43 @raise 403: pod already exists
44 @raise 400: body or name not provided
47 return {'name': data.name}
50 return httplib.FORBIDDEN, message.exist('pod', data.name)
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)