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 ##############################################################################
10 from opnfv_testapi.tornado_swagger import swagger
14 class GenericPodHandler(handlers.GenericApiHandler):
15 def __init__(self, application, request, **kwargs):
16 super(GenericPodHandler, self).__init__(application, request, **kwargs)
18 self.table_cls = pod_models.Pod
21 class PodCLHandler(GenericPodHandler):
22 @swagger.operation(nickname='listAllPods')
25 @description: list all pods
26 @return 200: list all pods, empty list is no pod exist
31 @swagger.operation(nickname='createPod')
34 @description: create a pod
35 @param body: pod to be created
36 @type body: L{PodCreateRequest}
38 @rtype: L{CreateResponse}
39 @return 200: pod is created.
40 @raise 403: pod already exists
41 @raise 400: body or name not provided
44 return {'name': self.json_args.get('name')}
45 miss_fields = ['name']
46 self._create(miss_fields=miss_fields, query=query)
49 class PodGURHandler(GenericPodHandler):
50 @swagger.operation(nickname='getPodByName')
51 def get(self, pod_name):
53 @description: get a single pod by pod_name
55 @return 200: pod exist
56 @raise 404: pod not exist
58 self._get_one(query={'name': pod_name})
60 def delete(self, pod_name):
63 # check for an existing pod to be deleted
64 mongo_dict = yield self.db.pods.find_one(
66 pod = TestProject.pod(mongo_dict)
68 raise HTTPError(HTTP_NOT_FOUND,
69 "{} could not be found as a pod to be deleted"
72 # just delete it, or maybe save it elsewhere in a future
73 res = yield self.db.projects.remove(
76 self.finish_request(answer)