def get_resources(agent: str, use_client: str, auth: tuple) -> int:
json_payload = {
"script": f":SET &maxJob# = GET_UC_SETTING(\"WORKLOAD_MAX_JOB\", \"{agent}\", \"\")\n:PRINT \"Max JOB resources: &maxJob#\""
}
response = post_api(f"/ae/api/v1/{use_client}/scripts", json.dumps(json_payload), auth, "agent")
# post_api now returns a requests.Response on success or None on failure
if response is None:
logging.error(f"POST to /scripts failed for client {use_client} when checking resources for agent {agent}.")
return -1
if not hasattr(response, "json"):
logging.error("post_api did not return a Response object with .json(); cannot parse run_id")
return -1
try:
data = response.json()
except ValueError:
logging.error("Response body was not valid JSON")
return -1
run_id = data.get("run_id")
if not run_id:
logging.error(f"No run_id returned from script execution for agent {agent}. Response: %s", json.dumps(data))
return -1
response = get_api(f"/ae/api/v1/{use_client}/executions/{run_id}/reports/ACT", auth)
if response and "data" in response:
line = response["data"][0].get("content", "")
if "Max JOB resources:" in line:
parts = line.split(":")
if len(parts) == 4:
try:
value = int(parts[3].strip())
return value
except ValueError:
logging.error(f"Failed to convert resource value to int: {parts[3].strip()}")
return -1