get_target_id(public_api_client, target_name):
"""
Description
-----------
To get the target id of a given chipset.
Args
----
public_api_client: QDC api client object.
target_name: Name of the chipset.
Returns
-------
int: ID of the given chipset.
None: In case of failure.
Usages
------
target = "SC8280XP"
target_id = qdc_api.get_target_id(public_api_client, target)
"""
target_id = None
targets_response = targets_get.sync_detailed(client=_get_client_with_new_trace_header(public_api_client), page_size=200)
if targets_response.status_code == 200:
print(
f"Target list: Received {len(targets_response.parsed.data)} of {targets_response.parsed.total} targets (page {targets_response.parsed.page_number})")
for target in targets_response.parsed.data:
print(
f'TargetId: {target.target_id}, ChipsetName: {target.chipset_name}, ChipsetMarketingName: {target.chipset_marketing_name}, 'f'ChipsetPlatform {target.chipset_platform_name}, ChipsetCategory: {target.chipset_category}, OS: {target.os}, 'f'OSVersion: {target.os_version}, State: {target.state}')
if target.chipset_name == target_name:
target_id = target.target_id
else:
print(
f"Get list of targets failed with error code {targets_response.status_code} {targets_response.content.decode('utf-8')}")
if target_id is not None:
print(f"Target id for {target_name} is {target_id}")
return target_id
else:
print(f"Cannot find target for {target_name}, exit.")
return None