1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
from opnfv_testapi.models import base_models
from opnfv_testapi.tornado_swagger import swagger
def list_default(value):
return value if value else list()
def dict_default(value):
return value if value else dict()
@swagger.model()
class ScenarioTI(base_models.ModelBase):
def __init__(self, date=None, status='silver'):
self.date = date
self.status = status
def __eq__(self, other):
return (self.date == other.date and
self.status == other.status)
def __ne__(self, other):
return not self.__eq__(other)
@swagger.model()
class ScenarioScore(base_models.ModelBase):
def __init__(self, date=None, score='0'):
self.date = date
self.score = score
def __eq__(self, other):
return (self.date == other.date and
self.score == other.score)
def __ne__(self, other):
return not self.__eq__(other)
@swagger.model()
class ScenarioProject(base_models.ModelBase):
"""
@property customs:
@ptype customs: C{list} of L{string}
@property scores:
@ptype scores: C{list} of L{ScenarioScore}
@property trust_indicators:
@ptype trust_indicators: C{list} of L{ScenarioTI}
"""
def __init__(self,
project='',
customs=None,
scores=None,
trust_indicators=None):
self.project = project
self.customs = list_default(customs)
self.scores = list_default(scores)
self.trust_indicators = list_default(trust_indicators)
@staticmethod
def attr_parser():
return {'scores': ScenarioScore,
'trust_indicators': ScenarioTI}
def __eq__(self, other):
return (self.project == other.project and
self._customs_eq(other) and
self._scores_eq(other) and
self._ti_eq(other))
def __ne__(self, other):
return not self.__eq__(other)
def _customs_eq(self, other):
return set(self.customs) == set(other.customs)
def _scores_eq(self, other):
return self.scores == other.scores
def _ti_eq(self, other):
return self.trust_indicators == other.trust_indicators
@swagger.model()
class ScenarioVersion(base_models.ModelBase):
"""
@property projects:
@ptype projects: C{list} of L{ScenarioProject}
"""
def __init__(self, owner=None, version=None, projects=None):
self.owner = owner
self.version = version
self.projects = list_default(projects)
@staticmethod
def attr_parser():
return {'projects': ScenarioProject}
def __eq__(self, other):
return (self.version == other.version and
self.owner == other.owner and
self._projects_eq(other))
def __ne__(self, other):
return not self.__eq__(other)
def _projects_eq(self, other):
for s_project in self.projects:
for o_project in other.projects:
if s_project.project == o_project.project:
if s_project != o_project:
return False
return True
@swagger.model()
class ScenarioInstaller(base_models.ModelBase):
"""
@property versions:
@ptype versions: C{list} of L{ScenarioVersion}
"""
def __init__(self, installer=None, versions=None):
self.installer = installer
self.versions = list_default(versions)
@staticmethod
def attr_parser():
return {'versions': ScenarioVersion}
def __eq__(self, other):
return (self.installer == other.installer and self._versions_eq(other))
def __ne__(self, other):
return not self.__eq__(other)
def _versions_eq(self, other):
for s_version in self.versions:
for o_version in other.versions:
if s_version.version == o_version.version:
if s_version != o_version:
return False
return True
@swagger.model()
class ScenarioCreateRequest(base_models.ModelBase):
"""
@property installers:
@ptype installers: C{list} of L{ScenarioInstaller}
"""
def __init__(self, name='', installers=None):
self.name = name
self.installers = list_default(installers)
@staticmethod
def attr_parser():
return {'installers': ScenarioInstaller}
@swagger.model()
class ScenarioChangeOwnerRequest(base_models.ModelBase):
def __init__(self, owner=None):
self.owner = owner
@swagger.model()
class ScenarioUpdateRequest(base_models.ModelBase):
def __init__(self, name=None):
self.name = name
@swagger.model()
class Scenario(base_models.ModelBase):
"""
@property installers:
@ptype installers: C{list} of L{ScenarioInstaller}
"""
def __init__(self, name='', create_date='', _id='', installers=None):
self.name = name
self._id = _id
self.creation_date = create_date
self.installers = list_default(installers)
@staticmethod
def attr_parser():
return {'installers': ScenarioInstaller}
def __ne__(self, other):
return not self.__eq__(other)
def __eq__(self, other):
return (self.name == other.name and self._installers_eq(other))
def _installers_eq(self, other):
for s_install in self.installers:
for o_install in other.installers:
if s_install.installer == o_install.installer:
if s_install != o_install:
return False
return True
@swagger.model()
class Scenarios(base_models.ModelBase):
"""
@property scenarios:
@ptype scenarios: C{list} of L{Scenario}
"""
def __init__(self):
self.scenarios = list()
@staticmethod
def attr_parser():
return {'scenarios': Scenario}
|