Merge "bugfix: E722 do not use bare except"
[releng.git] / utils / test / testapi / opnfv_testapi / handlers / pod_handlers.py
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.handlers import base_handlers
10 from opnfv_testapi.models import pod_models
11 from opnfv_testapi.tornado_swagger import swagger
12
13
14 class GenericPodHandler(base_handlers.GenericApiHandler):
15     def __init__(self, application, request, **kwargs):
16         super(GenericPodHandler, self).__init__(application, request, **kwargs)
17         self.table = 'pods'
18         self.table_cls = pod_models.Pod
19
20
21 class PodCLHandler(GenericPodHandler):
22     @swagger.operation(nickname='listAllPods')
23     def get(self):
24         """
25             @description: list all pods
26             @return 200: list all pods, empty list is no pod exist
27             @rtype: L{Pods}
28         """
29         self._list()
30
31     @swagger.operation(nickname='createPod')
32     def post(self):
33         """
34             @description: create a pod
35             @param body: pod to be created
36             @type body: L{PodCreateRequest}
37             @in body: body
38             @rtype: L{CreateResponse}
39             @return 200: pod is created.
40             @raise 403: pod already exists
41             @raise 400: body or name not provided
42         """
43         def query():
44             return {'name': self.json_args.get('name')}
45         miss_fields = ['name']
46         self._create(miss_fields=miss_fields, query=query)
47
48
49 class PodGURHandler(GenericPodHandler):
50     @swagger.operation(nickname='getPodByName')
51     def get(self, pod_name):
52         """
53             @description: get a single pod by pod_name
54             @rtype: L{Pod}
55             @return 200: pod exist
56             @raise 404: pod not exist
57         """
58         self._get_one(query={'name': pod_name})
59
60     def delete(self, pod_name):
61         """ Remove a POD
62
63         # check for an existing pod to be deleted
64         mongo_dict = yield self.db.pods.find_one(
65             {'name': pod_name})
66         pod = TestProject.pod(mongo_dict)
67         if pod is None:
68             raise HTTPError(HTTP_NOT_FOUND,
69                             "{} could not be found as a pod to be deleted"
70                             .format(pod_name))
71
72         # just delete it, or maybe save it elsewhere in a future
73         res = yield self.db.projects.remove(
74             {'name': pod_name})
75
76         self.finish_request(answer)
77         """
78         pass