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 ##############################################################################
9 from opnfv_testapi.tornado_swagger import swagger
10 from handlers import GenericApiHandler
11 from pod_models import Pod
12 from opnfv_testapi.common.constants import HTTP_FORBIDDEN
15 class GenericPodHandler(GenericApiHandler):
16 def __init__(self, application, request, **kwargs):
17 super(GenericPodHandler, self).__init__(application, request, **kwargs)
22 class PodCLHandler(GenericPodHandler):
23 @swagger.operation(nickname='list-all')
26 @description: list all pods
27 @return 200: list all pods, empty list is no pod exist
32 @swagger.operation(nickname='create')
35 @description: create a pod
36 @param body: pod to be created
37 @type body: L{PodCreateRequest}
40 @return 200: pod is created.
41 @raise 403: pod already exists
42 @raise 400: body or name not provided
45 return {'name': data.name}
48 message = '{} already exists as a pod'.format(data.name)
49 return HTTP_FORBIDDEN, message
51 miss_checks = ['name']
52 db_checks = [(self.table, False, query, error)]
53 self._create(miss_checks, db_checks)
56 class PodGURHandler(GenericPodHandler):
57 @swagger.operation(nickname='get-one')
58 def get(self, pod_name):
60 @description: get a single pod by pod_name
62 @return 200: pod exist
63 @raise 404: pod not exist
66 query['name'] = pod_name
69 def delete(self, pod_name):
72 # check for an existing pod to be deleted
73 mongo_dict = yield self.db.pods.find_one(
75 pod = TestProject.pod(mongo_dict)
77 raise HTTPError(HTTP_NOT_FOUND,
78 "{} could not be found as a pod to be deleted"
81 # just delete it, or maybe save it elsewhere in a future
82 res = yield self.db.projects.remove(
85 self.finish_request(answer)