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