oc-cdtapi 3.25.3__py3-none-any.whl → 3.26.2__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 CHANGED
@@ -11,7 +11,8 @@ from datetime import datetime, timedelta
11
11
  from packaging import version
12
12
 
13
13
  class ForemanAPIError(HttpAPIError):
14
- pass
14
+ def __str__(self):
15
+ return self.text
15
16
 
16
17
 
17
18
  class ForemanAPI(HttpAPI):
@@ -285,10 +286,10 @@ class ForemanAPI(HttpAPI):
285
286
  default_params.update(custom)
286
287
 
287
288
  if not default_params["is_owned_by"]:
288
- raise ForemanAPIError("The owner id is not specified")
289
+ raise ForemanAPIError(code=400, text="The owner id is not specified")
289
290
 
290
291
  if not default_params["name"]:
291
- raise ForemanAPIError("The hostname is not specified")
292
+ raise ForemanAPIError(code=400, text="The hostname is not specified")
292
293
 
293
294
  logging.debug("ForemanAPI is about to send the following payload:")
294
295
  logging.debug(default_params)
@@ -343,10 +344,10 @@ class ForemanAPI(HttpAPI):
343
344
  default_params.update(custom)
344
345
 
345
346
  if not default_params["is_owned_by"]:
346
- raise ForemanAPIError("The owner id is not specified")
347
+ raise ForemanAPIError(code=400, text="The owner id is not specified")
347
348
 
348
349
  if not default_params["name"]:
349
- raise ForemanAPIError("The hostname is not specified")
350
+ raise ForemanAPIError(code=400, text="The hostname is not specified")
350
351
 
351
352
  if not default_params.get('hostgroup_id'):
352
353
  hostgroup = self.get_hostgroup_id('stands')
@@ -628,7 +629,7 @@ class ForemanAPI(HttpAPI):
628
629
  """
629
630
  logging.debug('Reached override_smart_class_v1')
630
631
  request = self.post(posixpath.join("smart_class_parameters", str(scid),
631
- "override_values"), headers=self.headers, data=params)
632
+ "override_values"), headers=self.headers, data=params)
632
633
 
633
634
  def override_smart_class_v2(self, scid, params):
634
635
  """
@@ -699,7 +700,8 @@ class ForemanAPI(HttpAPI):
699
700
  """
700
701
  logging.debug('Reached add_puppet_class_to_host_v2')
701
702
  logging.debug('Params to be sent: %s' % params)
702
- response = self.post(posixpath.join('foreman_puppet', 'api', 'hosts', hostname, 'puppetclass_ids'), headers=self.headers, data=params)
703
+ response = self.post(posixpath.join('foreman_puppet', 'api', 'hosts', hostname, 'puppetclass_ids'),
704
+ headers=self.headers, data=params)
703
705
 
704
706
  def get_subnets(self):
705
707
  """
@@ -804,7 +806,7 @@ class ForemanAPI(HttpAPI):
804
806
  actions = ["start", "stop"]
805
807
 
806
808
  if action not in actions:
807
- raise ForemanAPIError("500 - Incorrect power action was provided")
809
+ raise ForemanAPIError(code=500, text="Incorrect power action was provided")
808
810
 
809
811
  params = json.dumps({"power_action": action})
810
812
  request = self.put(posixpath.join("hosts", hostname, "power"), headers=self.headers, data=params)
@@ -816,7 +818,7 @@ class ForemanAPI(HttpAPI):
816
818
  logging.debug('Reached host_power_v2')
817
819
  actions = ["on", "off"]
818
820
  if action not in actions:
819
- raise ForemanAPIError("500 - Incorrect power action was provided")
821
+ raise ForemanAPIError(code=500, text="Incorrect power action was provided")
820
822
  params = json.dumps({"power_action": action})
821
823
  request = self.put(posixpath.join('hosts', hostname, "power"), headers=self.headers, data=params)
822
824
  if not request.status_code == 200:
@@ -876,7 +878,7 @@ class ForemanAPI(HttpAPI):
876
878
 
877
879
  for hostgroup in hostgroups:
878
880
  if hostgroup.get("name") == hostgroup_name:
879
- return hostgroup.get ('id')
881
+ return hostgroup.get('id')
880
882
 
881
883
  logging.debug("Hostgroup [%s] not found, returning None" % hostgroup_name)
882
884
  return None
@@ -1061,7 +1063,7 @@ class ForemanAPI(HttpAPI):
1061
1063
  """
1062
1064
  logging.debug('Reached get_flavor_id_v1')
1063
1065
  flavors_list = self.get(posixpath.join("compute_resources", str(compute_resource_id),
1064
- "available_flavors")).json()["results"]
1066
+ "available_flavors")).json()["results"]
1065
1067
 
1066
1068
  try:
1067
1069
  flavor_id = next(flavor["id"] for flavor in flavors_list if flavor["name"] == flavor_name)
@@ -1230,11 +1232,10 @@ class ForemanAPI(HttpAPI):
1230
1232
  owner_type = 'Usergroup'
1231
1233
 
1232
1234
  if not owner_id:
1233
- raise ForemanAPIError(f"The owner [{owner}] is not found")
1235
+ raise ForemanAPIError(code=404, text=f"The owner [{owner}] is not found")
1234
1236
 
1235
1237
  self.update_host(hostname, {"host": {"owner_id": owner_id, "owner_type": owner_type}})
1236
1238
 
1237
-
1238
1239
  def set_host_owner_id(self, hostname, owner_id):
1239
1240
  """
1240
1241
  Change host owner_id
@@ -1282,7 +1283,7 @@ class ForemanAPI(HttpAPI):
1282
1283
 
1283
1284
  template_id = self._template_cache.get(template_name)
1284
1285
  if not template_id:
1285
- raise ForemanAPIError(f"Job template '{template_name}' not found")
1286
+ raise ForemanAPIError(code=404, text=f"Job template '{template_name}' not found")
1286
1287
 
1287
1288
  logging.debug(f"Template id for [{template_name}] is [{template_id}]")
1288
1289
  return template_id
@@ -1305,7 +1306,7 @@ class ForemanAPI(HttpAPI):
1305
1306
 
1306
1307
  config = task_configs.get(task_name)
1307
1308
  if not config:
1308
- raise ForemanAPIError(f"Unknown task: {task_name}")
1309
+ raise ForemanAPIError(code=404, text=f"Unknown task: {task_name}")
1309
1310
 
1310
1311
  logging.debug(f"config for [{task_name}] is [{config}]")
1311
1312
 
@@ -1345,7 +1346,7 @@ class ForemanAPI(HttpAPI):
1345
1346
  start_time = time.time()
1346
1347
  while True:
1347
1348
  if time.time() - start_time > timeout:
1348
- raise ForemanAPIError(f"Job {job_id} timed out after {timeout} seconds")
1349
+ raise ForemanAPIError(code=500, text=f"Job {job_id} timed out after {timeout} seconds")
1349
1350
  response = self.get(posixpath.join("job_invocations", str(job_id)))
1350
1351
  is_pending = bool(response.json().get("pending", False))
1351
1352
  if not is_pending:
@@ -1359,18 +1360,28 @@ class ForemanAPI(HttpAPI):
1359
1360
  """
1360
1361
  Get a parameter value by given parameter_name.
1361
1362
  :param hostname: str
1362
- :param parameter_name: str
1363
- :return value: str
1363
+ :param parameter_name: str or list/tuple - Single parameter name or list/tuple of parameter names
1364
+ :return: dict or None - Dict of {name: value} for found parameters, None if none found
1364
1365
  """
1365
- logging.debug('Reached get_parameter_value')
1366
1366
  host_info = self.get_host_info(hostname=hostname)
1367
1367
  host_parameters = host_info.get("parameters")
1368
1368
  if not host_parameters:
1369
1369
  return None
1370
1370
 
1371
- for host_parameter in host_parameters:
1372
- if host_parameter["name"] == parameter_name:
1373
- return host_parameter["value"]
1371
+ result = {}
1372
+ if isinstance(parameter_name, str):
1373
+ for host_parameter in host_parameters:
1374
+ if host_parameter["name"] == parameter_name:
1375
+ result[host_parameter["name"]] = host_parameter["value"]
1376
+ return result
1377
+ return None
1378
+
1379
+ elif isinstance(parameter_name, (list, tuple)):
1380
+ param_set = set(parameter_name)
1381
+ for host_parameter in host_parameters:
1382
+ if host_parameter["name"] in param_set:
1383
+ result[host_parameter["name"]] = host_parameter["value"]
1384
+ return result if result else None
1374
1385
 
1375
1386
  return None
1376
1387
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oc-cdtapi
3
- Version: 3.25.3
3
+ Version: 3.26.2
4
4
  Summary: Custom Development python API libraries
5
5
  License: Apache2.0
6
6
  Requires-Python: >=3.6
@@ -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=8mMia9tIqKNCJ9yHzOnMgQaBmcH2IIacuS-IW2Wwy68,50546
6
+ oc_cdtapi/ForemanAPI.py,sha256=blS0E2fyF2cgdnIT5itTrLExWRODBRzaOhAG35QnKN0,51393
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.25.3.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
16
- oc_cdtapi-3.25.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
- oc_cdtapi-3.25.3.dist-info/METADATA,sha256=twFTNRNuw7V4yMHbtY5ylWFh6CnKMRwaP2L7IwKNK7Y,504
18
- oc_cdtapi-3.25.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- oc_cdtapi-3.25.3.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
20
- oc_cdtapi-3.25.3.dist-info/RECORD,,
15
+ oc_cdtapi-3.26.2.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
16
+ oc_cdtapi-3.26.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
+ oc_cdtapi-3.26.2.dist-info/METADATA,sha256=633OzwA9vkGtpD5kA4ebTHVzrLL12isuJXUb2gSWxgc,504
18
+ oc_cdtapi-3.26.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ oc_cdtapi-3.26.2.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
20
+ oc_cdtapi-3.26.2.dist-info/RECORD,,