-
Notifications
You must be signed in to change notification settings - Fork 0
/
afcmd.py
418 lines (366 loc) · 11.9 KB
/
afcmd.py
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import cgruconfig
import afnetwork
class Block:
'''
Block class for block manipulation
'''
p_percentage = None
capacity = None
name = None
service = None
frames_per_task = None
time_done = None
job_id = None
tasks_num = None
block_num = None
p_progressbar = None
p_tasks_run_time = None
state = None
flags = None
p_tasks_skipped = None
frame_first = None
frame_last = None
st = None
frames_inc = None
p_tasks_done = None
time_started = None
class State:
restart = 'restart'
skip = 'skip'
def __init__(self, data):
'''
Constructor
'''
self.p_percentage = data.get('p_percentage', 0)
self.capacity = data.get('capacity', 0)
self.name = data.get('name')
self.service = data.get('service')
self.frames_per_task = data.get('frames_per_task')
self.time_done = data.get('time_done')
self.job_id = data.get('job_id')
self.tasks_num = data.get('tasks_num')
self.block_num = data.get('block_num')
self.p_progressbar = data.get('p_progressbar')
self.p_tasks_run_time = data.get('p_tasks_run_time')
self.state = data.get('state', '')
self.flags = data.get('flags')
self.p_tasks_skipped = data.get('p_tasks_skipped')
self.frame_first = data.get('frame_first')
self.frame_last = data.get('frame_last')
self.st = data.get('st')
self.frames_inc = data.get('frames_inc')
self.p_tasks_done = data.get('p_tasks_done')
self.time_started = data.get('time_started')
def setState(self, state, taskIds=[], verbose=False):
action = 'action'
data = {'ids': [self.job_id],
'type': 'jobs',
'block_ids': [self.block_num],
'operation': {'type': state,
'task_ids': taskIds}}
output = _sendRequest(action, data, verbose)
return output
def restart(self, taskIds=[]):
self.setState(self.State.restart, taskIds=taskIds)
def skip(self, taskIds=[]):
self.setState(self.State.skip, taskIds=taskIds)
class Job:
'''
Job class for job manipulation
'''
id = None
project = None
blocks = []
name = None
st = None
state = None
priority = None
host_name = None
branch = None
time_creation = None
time_done = None
time_started = None
serial = None
user_name = None
max_running_tasks = None
max_running_tasks_per_host = None
depend_mask = ''
p_percentage = 0
class State:
restart = 'restart'
start = 'start'
pause = 'pause'
stop = 'stop'
skip = 'skip'
delete = 'delete'
def __init__(self, jobId, data=None):
'''
Constructor
'''
self.id = jobId
self.blocks = []
if data is not None:
self.fillInfo(data)
def fillInfo(self, data):
self.project = data.get('project')
self.name = data.get('name')
self.st = data.get('st')
self.state = data.get('state')
self.priority = data.get('priority')
self.host_name = data.get('host_name')
self.branch = data.get('branch')
self.time_creation = data.get('time_creation')
self.time_done = data.get('time_done')
self.time_started = data.get('time_started')
self.serial = data.get('serial')
self.user_name = data.get('user_name')
self.max_running_tasks = data.get('max_running_tasks', -1)
self.max_running_tasks_per_host = data.get('max_running_tasks_per_host', -1)
self.depend_mask = data.get('depend_mask', '')
self.fillBlocks(data['blocks'])
def fillBlocks(self, blocksData):
blocksProgress = 0
for blockData in blocksData:
block = Block(blockData)
if block.p_percentage is not None:
blocksProgress += block.p_percentage
self.blocks.append(block)
self.p_percentage = blocksProgress / len(blocksData)
def setState(self, jobState, verbose=False):
action = 'action'
data = {'ids': [self.id],
'type': 'jobs',
'operation': {'type': jobState}}
output = _sendRequest(action, data, verbose)
return output
def pause(self):
self.setJobState(self.State.pause)
def start(self):
self.setJobState(self.State.start)
def stop(self):
self.setJobState(self.State.stop)
def delete(self):
self.setJobState(self.State.delete)
def getProgress(self, verbose=False,):
action = 'get'
data = {'type': 'jobs',
'ids': [self.id],
'mode': 'progress'}
output = _sendRequest(action, data, verbose)
if output is not None:
if 'job_progress' in output:
return output['job_progress']
return None
class Render:
'''
Render class for render manipulation
'''
id = None
name = None
user_name = None
capacity_used = None
idle_time = None
time_launch = None
state = None
st = None
priority = None
time_update = None
time_register = None
netifs = []
task_start_finish_time = None
address = {}
host = None
busy_time = None
max_tasks = None
wol_idlesleep_time = None
capacity = None
power = None
def __init__(self, renderId, data=None):
'''
Constructor
'''
self.id = renderId
if data is not None:
self.fillRenderInfo(data)
def fillRenderInfo(self, data):
self.name = data.get('name')
self.user_name = data.get('user_name')
self.capacity_used = data.get('capacity_used')
self.idle_time = data.get('idle_time')
self.time_launch = data.get('time_launch')
self.state = data.get('state')
self.st = data.get('st')
self.priority = data.get('priority')
self.time_update = data.get('time_update')
self.time_register = data.get('time_register')
# self.netifs = []
self.task_start_finish_time = data.get('task_start_finish_time')
# self.address = {}
self.host = data.get('host')
self.busy_time = data.get('busy_time')
def setUserName(self, username, verbose=False):
action = 'action'
data = {'type': 'renders'}
data['mask'] = self.name
data['params'] = {'user_name': username}
output = _sendRequest(action, data, verbose)
return output
def setNimby(self, verbose=False):
action = 'action'
data = {'type': 'renders'}
data['mask'] = self.name
data['params'] = {'nimby': True}
output = _sendRequest(action, data, verbose)
return output
def setNIMBY(self, verbose=False):
action = 'action'
data = {'type': 'renders'}
data['mask'] = self.name
data['params'] = {'NIMBY': True}
output = _sendRequest(action, data, verbose)
return output
def setFree(self, verbose=False):
action = 'action'
data = {'type': 'renders'}
data['mask'] = self.name
data['params'] = {'nimby': False}
output = _sendRequest(action, data, verbose)
return output
def setFreeUnpause(self, verbose=False):
action = 'action'
data = {'type': 'renders'}
data['mask'] = self.name
data['params'] = {'nimby': False, 'paused': False}
output = _sendRequest(action, data, verbose)
return output
def ejectNotMyTasks(self, verbose=False):
action = 'action'
data = {'type': 'renders'}
data['mask'] = self.name
data['operation'] = {'type': 'eject_tasks_keep_my'}
output = _sendRequest(action, data, verbose)
return output
def exit(self, verbose=False):
action = 'action'
data = {'type': 'renders'}
data['mask'] = self.name
data['operation'] = {'type': 'exit'}
output = _sendRequest(action, data, verbose)
return output
def setServiceState(self, serviceName, enabled, verbose=False):
action = 'action'
data = {'type': 'renders'}
data['mask'] = self.name
data['operation'] = {'type': 'service', 'name': serviceName, 'enable': enabled}
output = _sendRequest(action, data, verbose)
return output
class Monitor():
'''
Monitor class for monitor registration
'''
class WatchType:
jobs = 'jobs'
renders = 'renders'
def __init__(self, verbose=False):
action = 'monitor'
data = {'engine': 'python'}
output = _sendRequest(action, data, verbose)
if output is not None:
self.id = output['monitor']['id']
else:
return None
def __del__(self, verbose=False):
action = 'action'
data = {'type': 'monitors',
'ids': [self.id],
'operation': {"type": "deregister"}}
_sendRequest(action, data, verbose, without_answer=True)
def changeUid(self, uid, verbose=False):
action = 'action'
data = {'type': 'monitors',
'ids': [self.id],
'operation': {"type": "watch",
"class": "perm",
"uid": uid}}
return _sendRequest(action, data, verbose)
def subscribe(self, classType, verbose=False):
action = 'action'
data = {'type': 'monitors',
'ids': [self.id],
'operation': {"type": "watch",
"class": classType,
"status": "subscribe"}}
return _sendRequest(action, data, verbose)
def events(self):
action = 'get'
data = {'type': 'monitors',
'ids': [self.id],
'mode': 'events'}
return _sendRequest(action, data)
def _sendRequest(action, requestData, verbose=False, without_answer=False):
"""Missing DocString
:param bool verbose:
:return:
"""
data = {'user_name': cgruconfig.VARS['USERNAME'],
"host_name": cgruconfig.VARS['HOSTNAME']}
data.update(requestData)
obj = {action: data}
# print(json.dumps(obj))
output = afnetwork.sendServer(json.dumps(obj), verbose, i_without_answer=without_answer)
if output[0] is True:
return output[1]
else:
return None
def getJobList(ids=None, full=False, verbose=False):
"""Missing DocString
:param bool verbose:
:return:
"""
action = 'get'
data = {'type': 'jobs'}
if ids is not None:
data['ids'] = ids
if full is True:
data['mode'] = 'full'
output = _sendRequest(action, data, verbose)
jobs = []
if output is not None:
if 'jobs' in output:
for jobData in output['jobs']:
job = Job(jobData['id'], jobData)
jobs.append(job)
return jobs
def getJob(jobId, full=False, verbose=False):
jobs = getJobList(ids=[jobId], full=full, verbose=verbose)
if len(jobs) > 0:
return jobs[0]
else:
return None
def getRenderList(mask=None, ids=None, verbose=False):
action = 'get'
data = {'type': 'renders'}
if mask is not None:
data['mask'] = mask
if ids is not None:
data['ids'] = ids
output = _sendRequest(action, data, verbose)
renders = []
if output is not None:
if 'renders' in output:
for renderData in output['renders']:
render = Render(renderData['id'], renderData)
renders.append(render)
return renders
def getRenderResources():
action = 'get'
data = {'type': 'renders',
'mode': 'resources'}
output = _sendRequest(action, data)
if output is not None:
if 'renders' in output:
return output['renders']
return None