add copyright to files in testAPI
[releng.git] / utils / test / result_collection_api / opnfv_testapi / resources / pod_models.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.tornado_swagger import swagger
10
11 # name: name of the POD e.g. zte-1
12 # mode: metal or virtual
13 # details: any detail
14 # role: ci-pod or community-pod or single-node
15
16
17 @swagger.model()
18 class PodCreateRequest(object):
19     def __init__(self, name, mode='', details='', role=""):
20         self.name = name
21         self.mode = mode
22         self.details = details
23         self.role = role
24
25     def format(self):
26         return {
27             "name": self.name,
28             "mode": self.mode,
29             "details": self.details,
30             "role": self.role,
31         }
32
33
34 @swagger.model()
35 class Pod(PodCreateRequest):
36     def __init__(self,
37                  name='', mode='', details='',
38                  role="", _id='', create_date=''):
39         super(Pod, self).__init__(name, mode, details, role)
40         self._id = _id
41         self.creation_date = create_date
42
43     @staticmethod
44     def from_dict(pod_dict):
45         if pod_dict is None:
46             return None
47
48         p = Pod()
49         p._id = pod_dict.get('_id')
50         p.creation_date = str(pod_dict.get('creation_date'))
51         p.name = pod_dict.get('name')
52         p.mode = pod_dict.get('mode')
53         p.details = pod_dict.get('details')
54         p.role = pod_dict.get('role')
55         return p
56
57     def format(self):
58         f = super(Pod, self).format()
59         f['creation_date'] = str(self.creation_date)
60         return f
61
62     def format_http(self):
63         f = self.format()
64         f['_id'] = str(self._id)
65         return f
66
67
68 @swagger.model()
69 class Pods(object):
70     """
71         @property pods:
72         @ptype pods: C{list} of L{Pod}
73     """
74     def __init__(self):
75         self.pods = list()
76
77     @staticmethod
78     def from_dict(res_dict):
79         if res_dict is None:
80             return None
81
82         res = Pods()
83         for pod in res_dict.get('pods'):
84             res.pods.append(Pod.from_dict(pod))
85         return res