oc-cdtapi 3.21.8__py3-none-any.whl → 3.23.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- oc_cdtapi/ForemanAPI.py +115 -0
- {oc_cdtapi-3.21.8.dist-info → oc_cdtapi-3.23.4.dist-info}/METADATA +1 -1
- {oc_cdtapi-3.21.8.dist-info → oc_cdtapi-3.23.4.dist-info}/RECORD +7 -7
- {oc_cdtapi-3.21.8.data → oc_cdtapi-3.23.4.data}/scripts/nexus.py +0 -0
- {oc_cdtapi-3.21.8.dist-info → oc_cdtapi-3.23.4.dist-info}/WHEEL +0 -0
- {oc_cdtapi-3.21.8.dist-info → oc_cdtapi-3.23.4.dist-info}/licenses/LICENSE +0 -0
- {oc_cdtapi-3.21.8.dist-info → oc_cdtapi-3.23.4.dist-info}/top_level.txt +0 -0
oc_cdtapi/ForemanAPI.py
CHANGED
|
@@ -2,6 +2,8 @@ import json
|
|
|
2
2
|
import logging
|
|
3
3
|
import posixpath
|
|
4
4
|
import re
|
|
5
|
+
import time
|
|
6
|
+
from time import sleep
|
|
5
7
|
|
|
6
8
|
from oc_cdtapi.API import HttpAPI, HttpAPIError
|
|
7
9
|
from collections import namedtuple, defaultdict
|
|
@@ -1177,6 +1179,25 @@ class ForemanAPI(HttpAPI):
|
|
|
1177
1179
|
logging.debug('Passing to get_host_uuid_v1')
|
|
1178
1180
|
return self.get_host_uuid_v1(hostname)
|
|
1179
1181
|
|
|
1182
|
+
def get_host_disk_size(self, hostname):
|
|
1183
|
+
"""
|
|
1184
|
+
:param hostname: str
|
|
1185
|
+
:return: int
|
|
1186
|
+
"""
|
|
1187
|
+
logging.debug('Reached get_host_disk_size')
|
|
1188
|
+
response = self.get(posixpath.join("hosts", hostname, "vm_compute_attributes"))
|
|
1189
|
+
data = response.json()
|
|
1190
|
+
try:
|
|
1191
|
+
volumes = data.get("volumes_attributes", {})
|
|
1192
|
+
volume = volumes.get("0") or volumes.get(0)
|
|
1193
|
+
if volume and "size_gb" in volume:
|
|
1194
|
+
return int(volume["size_gb"])
|
|
1195
|
+
logging.error('Could not find size_gb in vm_compute_attributes for [%s]' % hostname)
|
|
1196
|
+
return None
|
|
1197
|
+
except (KeyError, ValueError, TypeError) as e:
|
|
1198
|
+
logging.error('Error parsing disk size for [%s]: %s' % (hostname, e))
|
|
1199
|
+
return None
|
|
1200
|
+
|
|
1180
1201
|
def get_all_users(self):
|
|
1181
1202
|
"""
|
|
1182
1203
|
:return: list
|
|
@@ -1225,3 +1246,97 @@ class ForemanAPI(HttpAPI):
|
|
|
1225
1246
|
pl['host'] = {}
|
|
1226
1247
|
pl['host']['owner_id'] = owner_id
|
|
1227
1248
|
self.update_host(hostname, pl)
|
|
1249
|
+
|
|
1250
|
+
def get_job_template_id(self, template_name):
|
|
1251
|
+
"""
|
|
1252
|
+
Get template ID by name. Cache results to avoid repeated API calls.
|
|
1253
|
+
:param template_name: str
|
|
1254
|
+
:return template_id: int
|
|
1255
|
+
"""
|
|
1256
|
+
logging.debug('Reached get_job_template_id')
|
|
1257
|
+
if not hasattr(self, '_template_cache'):
|
|
1258
|
+
self._template_cache = {}
|
|
1259
|
+
|
|
1260
|
+
if template_name in self._template_cache:
|
|
1261
|
+
return self._template_cache[template_name]
|
|
1262
|
+
|
|
1263
|
+
response = self.get(posixpath.join("job_templates"), params={'per_page': 'all'})
|
|
1264
|
+
templates = response.json()["results"]
|
|
1265
|
+
|
|
1266
|
+
for job in templates:
|
|
1267
|
+
self._template_cache[job["name"]] = job["id"]
|
|
1268
|
+
|
|
1269
|
+
template_id = self._template_cache.get(template_name)
|
|
1270
|
+
if not template_id:
|
|
1271
|
+
raise ForemanAPIError(f"Job template '{template_name}' not found")
|
|
1272
|
+
|
|
1273
|
+
logging.debug(f"Template id for [{template_name}] is [{template_id}]")
|
|
1274
|
+
return template_id
|
|
1275
|
+
|
|
1276
|
+
def send_job_invocation(self, task_name, vm_name, **inputs):
|
|
1277
|
+
"""
|
|
1278
|
+
Send a job invocation for a specific task and VM.
|
|
1279
|
+
:param task_name: str
|
|
1280
|
+
:param vm_name: str
|
|
1281
|
+
:param **inputs: kwargs
|
|
1282
|
+
:return job_id
|
|
1283
|
+
"""
|
|
1284
|
+
logging.debug('Reached send_job_invocation')
|
|
1285
|
+
task_configs = {
|
|
1286
|
+
"resize_partition": {
|
|
1287
|
+
"template_name": "Run \"cdt-resize-partition\" role CDT",
|
|
1288
|
+
"description": "Partition Resizing"
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
config = task_configs.get(task_name)
|
|
1293
|
+
if not config:
|
|
1294
|
+
raise ForemanAPIError(f"Unknown task: {task_name}")
|
|
1295
|
+
|
|
1296
|
+
logging.debug(f"config for [{task_name}] is [{config}]")
|
|
1297
|
+
|
|
1298
|
+
template_id = self.get_job_template_id(config["template_name"])
|
|
1299
|
+
|
|
1300
|
+
payload = {
|
|
1301
|
+
"job_invocation": {
|
|
1302
|
+
"job_template_id": template_id,
|
|
1303
|
+
"targeting_type": "static_query",
|
|
1304
|
+
"search_query": f'name = "{vm_name}"',
|
|
1305
|
+
"description_format": config["description"],
|
|
1306
|
+
"inputs": inputs,
|
|
1307
|
+
"ansible": {
|
|
1308
|
+
"tags": "",
|
|
1309
|
+
"tags_flag": "include"
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
logging.debug(f"About to send job invocations with following request [{payload}]")
|
|
1315
|
+
response = self.post(
|
|
1316
|
+
posixpath.join("job_invocations"),
|
|
1317
|
+
headers=self.headers,
|
|
1318
|
+
json=payload
|
|
1319
|
+
)
|
|
1320
|
+
|
|
1321
|
+
return response.json()["id"]
|
|
1322
|
+
|
|
1323
|
+
def is_job_invocation_success(self, job_id, timeout=300, poll_interval=5):
|
|
1324
|
+
"""
|
|
1325
|
+
Get a job status by given id.
|
|
1326
|
+
:param job_id: str
|
|
1327
|
+
:param timeout: int
|
|
1328
|
+
:param poll_interval: int
|
|
1329
|
+
:return status: bool
|
|
1330
|
+
"""
|
|
1331
|
+
start_time = time.time()
|
|
1332
|
+
while True:
|
|
1333
|
+
if time.time() - start_time > timeout:
|
|
1334
|
+
raise ForemanAPIError(f"Job {job_id} timed out after {timeout} seconds")
|
|
1335
|
+
response = self.get(posixpath.join("job_invocations", str(job_id)))
|
|
1336
|
+
is_pending = bool(response.json().get("pending", False))
|
|
1337
|
+
if not is_pending:
|
|
1338
|
+
break
|
|
1339
|
+
logging.debug(f"job still pending, sleeping for {poll_interval} second")
|
|
1340
|
+
sleep(poll_interval)
|
|
1341
|
+
|
|
1342
|
+
return bool(response.json().get("succeeded", False))
|
|
@@ -3,7 +3,7 @@ oc_cdtapi/Dbsm2API.py,sha256=WDBst1dCAmDVU9d9Ogzwp2nkjtKZ4thU2xG4sAPI_Nk,9963
|
|
|
3
3
|
oc_cdtapi/DevPIAPI.py,sha256=9WND9ld66eHmC5qoLJq3KDYSoO-pP69UqOQsGZNLZYg,1835
|
|
4
4
|
oc_cdtapi/DmsAPI.py,sha256=eNFdwQLhCbPvHB5SUtP4QcZZtSdjkgt_Cxn3oQ3iJ5s,15605
|
|
5
5
|
oc_cdtapi/DmsGetverAPI.py,sha256=ZPU4HlF59fngKu5mSFhtss3rlBuduffDOSm_y3XWrxk,15556
|
|
6
|
-
oc_cdtapi/ForemanAPI.py,sha256=
|
|
6
|
+
oc_cdtapi/ForemanAPI.py,sha256=oL_OdUgRL_7z9te83lmLarInDaKWW1_rjwXaWTZajIY,48401
|
|
7
7
|
oc_cdtapi/JenkinsAPI.py,sha256=lZ8pe3a4eb_6h53JE7QLuzOSlu7Sqatc9PQwWhio9Vg,15748
|
|
8
8
|
oc_cdtapi/NexusAPI.py,sha256=uU12GtHvKlWorFaPAnFcQ5AGEc94MZ5SdmfM2Pw3F7A,26122
|
|
9
9
|
oc_cdtapi/PgAPI.py,sha256=URSz7qu-Ir7AOj0jI3ucTXn2PM-nC96nmPZI746OLjA,14356
|
|
@@ -12,9 +12,9 @@ oc_cdtapi/RundeckAPI.py,sha256=O3LmcFaHSz8UqeUyIHTTEMJncDD191Utd-iZaeJay2s,24243
|
|
|
12
12
|
oc_cdtapi/TestServer.py,sha256=HV97UWg2IK4gOYAp9yaMdwFUWsw9v66MxyZdI3qQctA,2715
|
|
13
13
|
oc_cdtapi/VaultAPI.py,sha256=P-x_PsWe_S0mGUKTCmR1KhUjdfs7GmyaltjGQcnWj_s,2967
|
|
14
14
|
oc_cdtapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
15
|
-
oc_cdtapi-3.
|
|
16
|
-
oc_cdtapi-3.
|
|
17
|
-
oc_cdtapi-3.
|
|
18
|
-
oc_cdtapi-3.
|
|
19
|
-
oc_cdtapi-3.
|
|
20
|
-
oc_cdtapi-3.
|
|
15
|
+
oc_cdtapi-3.23.4.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
|
|
16
|
+
oc_cdtapi-3.23.4.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
17
|
+
oc_cdtapi-3.23.4.dist-info/METADATA,sha256=vm9AmaXHNBtw1DznVmDF9PLEfIDC1xn0bNrxE-mV0uU,504
|
|
18
|
+
oc_cdtapi-3.23.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
oc_cdtapi-3.23.4.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
|
|
20
|
+
oc_cdtapi-3.23.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|