-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobs.py
More file actions
132 lines (120 loc) · 5.57 KB
/
jobs.py
File metadata and controls
132 lines (120 loc) · 5.57 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
import requests
class JobsApi:
def __init__(self, provCtx):
self.provCtx = provCtx
def create(self, job_config):
response = requests.post(self.provCtx.api_endpoint('api/2.0/jobs/create'),
headers = self.provCtx.auth_headers(),
json = job_config)
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.create] status: {response.status_code},\ntext: {response.text}')
return None
def get(self, job_id):
response = requests.get(self.provCtx.api_endpoint('api/2.0/jobs/get'),
headers = self.provCtx.auth_headers(),
params={'job_id': job_id})
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.list] status: {response.status_code},\ntext: {response.text}')
return None
def update_policy(self, job_id, job_config):
response = requests.post(self.provCtx.api_endpoint('api/2.0/jobs/update'),
headers = self.provCtx.auth_headers(),
json={'job_id': job_id,
'new_settings': job_config})
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.list] status: {response.status_code},\ntext: {response.text}')
return None
def list(self):
response = requests.get(self.provCtx.api_endpoint('api/2.0/jobs/list'),
headers = self.provCtx.auth_headers())
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.list] status: {response.status_code},\ntext: {response.text}')
return None
def delete(self, job_id):
response = requests.post(self.provCtx.api_endpoint('api/2.0/jobs/delete'),
headers = self.provCtx.auth_headers(),
json = {
'job_id': job_id
})
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.delete] status: {response.status_code},\ntext: {response.text}')
return None
def reset(self, job_id, job_config):
response = requests.post(self.provCtx.api_endpoint('api/2.0/jobs/reset'),
headers = self.provCtx.auth_headers(),
json = {
'job_id': job_id,
'new_settings': job_config
})
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.reset] status: {response.status_code},\ntext: {response.text}')
return None
def run_now(self, job_id):
response = requests.post(self.provCtx.api_endpoint('api/2.0/jobs/run-now'),
headers = self.provCtx.auth_headers(),
json = {
'job_id': job_id
})
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.run-now] status: {response.status_code},\ntext: {response.text}')
return None
def runs_list(self, job_id, active_only=True, offset=0, limit=20):
if job_id is not None:
response = requests.get(self.provCtx.api_endpoint('api/2.0/jobs/runs/list'),
headers = self.provCtx.auth_headers(),
params = {
'job_id': job_id,
'active_only': True,
'completed_only': False,
'offset': 0,
'limit': limit
})
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.runs.list] status: {response.status_code},\ntext: {response.text}')
return None
else:
return None
def runs_cancel(self, run_id):
if run_id is not None:
response = requests.post(self.provCtx.api_endpoint('api/2.0/jobs/runs/cancel'),
headers = self.provCtx.auth_headers(),
json = {
'run_id': run_id,
})
if response.status_code == 200:
return True
else:
print(f'[jobs.runs.cancel] status: {response.status_code},\ntext: {response.text}')
return False
else:
return False
def runs_get(self, run_id):
if run_id is not None:
response = requests.get(self.provCtx.api_endpoint('api/2.0/jobs/runs/get'),
headers = self.provCtx.auth_headers(),
params = {
'run_id': run_id,
})
if response.status_code == 200:
return response.json()
else:
print(f'[jobs.runs.get] status: {response.status_code},\ntext: {response.text}')
return None
else:
return None