oc-cdtapi 3.25.1__py3-none-any.whl → 3.26.1__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
@@ -1359,16 +1359,54 @@ class ForemanAPI(HttpAPI):
1359
1359
  """
1360
1360
  Get a parameter value by given parameter_name.
1361
1361
  :param hostname: str
1362
- :param parameter_name: int
1363
- :return value: str
1362
+ :param parameter_name: str or list/tuple - Single parameter name or list/tuple of parameter names
1363
+ :return: dict or None - Dict of {name: value} for found parameters, None if none found
1364
1364
  """
1365
1365
  host_info = self.get_host_info(hostname=hostname)
1366
1366
  host_parameters = host_info.get("parameters")
1367
1367
  if not host_parameters:
1368
1368
  return None
1369
1369
 
1370
- for host_parameter in host_parameters:
1371
- if host_parameter["name"] == parameter_name:
1372
- return host_parameter["value"]
1370
+ result = {}
1371
+ if isinstance(parameter_name, str):
1372
+ for host_parameter in host_parameters:
1373
+ if host_parameter["name"] == parameter_name:
1374
+ result[host_parameter["name"]] = host_parameter["value"]
1375
+ return result
1376
+ return None
1377
+
1378
+ elif isinstance(parameter_name, (list, tuple)):
1379
+ param_set = set(parameter_name)
1380
+ for host_parameter in host_parameters:
1381
+ if host_parameter["name"] in param_set:
1382
+ result[host_parameter["name"]] = host_parameter["value"]
1383
+ return result if result else None
1384
+
1385
+ return None
1386
+
1387
+ def set_parameter_value(self, hostname, parameter_name, parameter_value, auto_create=False):
1388
+ """
1389
+ Set a parameter value by given parameter_name and parameter_value.
1390
+ Also, auto_create option will automatically create the parameter if not appear.
1391
+ :param hostname: str
1392
+ :param parameter_name: str
1393
+ :param parameter_value: str
1394
+ :param auto_create: bool
1395
+ """
1396
+ logging.debug('Reached set_parameter_value')
1397
+ payload = {
1398
+ "parameter": {
1399
+ "name": parameter_name,
1400
+ "value": parameter_value
1401
+ }
1402
+ }
1403
+
1404
+ if self.get_parameter_value(hostname=hostname, parameter_name=parameter_name) is None:
1405
+ logging.debug(f"parameter {parameter_name} is not created yet")
1406
+ if auto_create:
1407
+ logging.debug(f"creating parameter {parameter_name}")
1408
+ self.post(posixpath.join("hosts", hostname, "parameters"), headers=self.headers, json=payload)
1409
+ return
1373
1410
 
1374
- return None
1411
+ logging.debug(f"updating {parameter_name}")
1412
+ self.put(posixpath.join("hosts", hostname, "parameters", parameter_name), headers=self.headers, json=payload)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oc-cdtapi
3
- Version: 3.25.1
3
+ Version: 3.26.1
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=3LJLDhLNengLlXd3xTrD0qMCNXkyQzGceo8bZUkaOfo,49299
6
+ oc_cdtapi/ForemanAPI.py,sha256=kKzYKnh3aEL5OsJgXXiVe0dRw-kj-LXqIG03Oz61qcI,51123
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.1.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
16
- oc_cdtapi-3.25.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
- oc_cdtapi-3.25.1.dist-info/METADATA,sha256=53G7CjWRyKUzemodn7tNyujoaOAqRraGjLK-v_Avz9Q,504
18
- oc_cdtapi-3.25.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
- oc_cdtapi-3.25.1.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
20
- oc_cdtapi-3.25.1.dist-info/RECORD,,
15
+ oc_cdtapi-3.26.1.data/scripts/nexus.py,sha256=4teqZ_KtCSrwHDJVgA7lkreteod4Xt5XJFZNbwb7E6E,6858
16
+ oc_cdtapi-3.26.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
17
+ oc_cdtapi-3.26.1.dist-info/METADATA,sha256=sWydrThH2AFpyQA_eRTzJ5cxbMqcIpC4cxKHSMsHP8o,504
18
+ oc_cdtapi-3.26.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
19
+ oc_cdtapi-3.26.1.dist-info/top_level.txt,sha256=d4-5-D-0CSeSXYuLCP7-nIFCpjkfmJr-Y_muzds8iVU,10
20
+ oc_cdtapi-3.26.1.dist-info/RECORD,,