forked from solidfire/solidfire-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
223 lines (184 loc) · 6.29 KB
/
models.py
File metadata and controls
223 lines (184 loc) · 6.29 KB
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
219
220
221
222
223
"""
Module contains user defined objects directly implemented to map to the Element
API.
"""
from __future__ import unicode_literals
from __future__ import absolute_import
from solidfire.common import model as data_model
AUTO_GENERATE_SECRET = "AUTO-GENERATE-CHAP-SECRET"
class CHAPSecret(data_model.DataObject):
"""
A representation of the CHAP Secret
:param secret: [required] A 12 - 16 character string.
:type start: str
"""
secret = data_model.property(
"secret", str,
array=False, optional=False,
documentation="A 12 - 16 character string."
)
def __init__(self, **kwargs):
data_model.DataObject.__init__(self, **kwargs)
@staticmethod
def auto_generate():
"""
Used in 'AddAccount' and 'ModifyAccount' to cause a CHAP Secret to be
auto generated by the cluster.
"""
chap = CHAPSecret()
chap.secret = AUTO_GENERATE_SECRET
return chap
@classmethod
def custom_extract(cls, data):
"""
Deserialize the property from json.
:param data: the data to be converted.
:return: the extracted data.
"""
chap = CHAPSecret()
chap.secret = data
return chap
def custom_to_json(self):
"""
Custom json serialize logic
:return:
"""
if self.secret == AUTO_GENERATE_SECRET:
return None
else:
return self.secret
class Weekday:
"""
A better representation of the Weekday. Used in the DaysOfWeekFrequency
class.
"""
Sunday = ('Sunday', 0)
Monday = ('Monday', 1)
Tuesday = ('Tuesday', 2)
Wednesday = ('Wednesday', 3)
Thursday = ('Thursday', 4)
Friday = ('Friday', 5)
Saturday = ('Saturday', 6)
all_weekdays = [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday,
Saturday]
@staticmethod
def from_id(weekday_id):
for weekday in Weekday.all_weekdays:
if weekday[1] == weekday_id:
return weekday
raise AttributeError
@staticmethod
def from_name(weekday_name):
for weekday in Weekday.all_weekdays:
if weekday[0] == weekday_name:
return weekday
raise AttributeError
class Frequency(data_model.DataObject):
"""
Abstract class used to determine the frequency of a Schedule.
"""
def __init__(self, **kwargs):
data_model.DataObject.__init__(self, **kwargs)
class TimeIntervalFrequency(Frequency):
"""
Use this class when setting the frequency of a Schedule to Time Interval.
Time Interval schedules trigger after the specified interval of time has
passed.
:param minutes: The minutes that will elapse before the next snapshot is
created.
Valid values are: 0 - 59. Default is 0.
:type minutes: int
:param hours: The hours that will elapse before the next snapshot is
created.
Valid values 0 - 24. Default is 0.
:type hours: int
:param days: The days that will elapse before the next snapshot is created.
Default is 0.
:type days: int
"""
minutes = data_model.property(
"minutes", int,
array=False, optional=False,
documentation="Number of minutes between snapshots. "
"Valid values are: 0 - 59"
)
hours = data_model.property(
"hours", int,
array=False, optional=False,
documentation="Number of hours between snapshots. "
"Valid values are: 0 - 24"
)
days = data_model.property(
"days", int,
array=False, optional=False,
documentation="Number of days between snapshots."
)
class DaysOfWeekFrequency(Frequency):
"""
Use this class when setting the frequency of a Schedule to Days Of Week.
Days of week schedules trigger on the weekdays and time specified.
:param minutes: The minutes within the hour the snapshot will be created
on the set weekdays.
Valid values are: 0 - 59. Default is 0.
:type minutes: int
:param The hour of the day the next snapshot will be created on the set
weekdays.
Valid values are: 0 - 24. Default is 0
:type hours: int
:param weekdays: The days of the week a snapshot will be created on.
:type weekdays: int
"""
minutes = data_model.property(
"minutes", int,
array=False, optional=False,
documentation="Minute of hour the snapshot is to be created. "
"Valid values are: 0 - 59"
)
hours = data_model.property(
"hours", int,
array=False, optional=False,
documentation="Hour of day the snapshot is to be created. "
"Valid values are: 0 - 24"
)
weekdays = data_model.property(
"weekdays", Weekday,
array=True, optional=False,
documentation="Days of the week the snapshot is to be created. "
"Valid values are: "
"Weekday - 1 - 7 (Sunday - Saturday)."
)
class DaysOfMonthFrequency(Frequency):
"""
Use this class when setting the frequency of a Schedule to Days Of Month.
Days of month schedules trigger on the monthdays and time specified.
:param minutes: The minutes within the hour the snapshot will be created
on the set weekdays.
Valid values are: 0 - 59. Default is 0.
:type minutes: int
:param The hour of the day the next snapshot will be created on the set
weekdays.
Valid values are: 0 - 24. Default is 0
:type hours: int
:param monthdays: An array of the days of the month a snapshot will be
created on.
Valid values are: 1 - 31
:type monthdays: int
"""
minutes = data_model.property(
"minutes", int,
array=False, optional=False,
documentation="Minute of hour the snapshot is to be created. "
"Valid values are: 0 - 59"
)
hours = data_model.property(
"hours", int,
array=False, optional=False,
documentation="Hour of day the snapshot is to be created. "
"Valid values are: 0 - 24"
)
monthdays = data_model.property(
"monthdays", int,
array=True, optional=False,
documentation="Days of the month the snapshot is to be created. "
"Valid values are: 1 - 31"
)