Skip to content

Instantly share code, notes, and snippets.

@rssnyder
Created February 29, 2024 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rssnyder/fc913abe07a10f27f7124f5a98fbf941 to your computer and use it in GitHub Desktop.
Save rssnyder/fc913abe07a10f27f7124f5a98fbf941 to your computer and use it in GitHub Desktop.
python code to warm up an autostopping rule

environment vars

  • HARNESS_ACCOUNT_ID: your harness account id
  • HARNESS_PLATFORM_API_KEY: a harness api key with autostopping:read access at the all acccount level resources level

rule_id: the id of the autostopping rule image

warm_up_min: minutes to keep the instance up

source in the json payload is for auditing in the ui image

from os import getenv
from requests import post
if __name__ == "__main__":
rule_id = 33178
warm_up_min = 10
resp = post(
f'https://app.harness.io/gateway/lw/api/accounts/{getenv("HARNESS_ACCOUNT_ID")}/autostopping/rules/{rule_id}/warmup',
params={
"accountIdentifier": getenv("HARNESS_ACCOUNT_ID"),
"routingId": getenv("HARNESS_ACCOUNT_ID"),
},
headers={
"x-api-key": getenv("HARNESS_PLATFORM_API_KEY"),
},
json={
"idle_time_mins": warm_up_min,
"forced_trigger": True,
"source": "python",
},
)
resp.raise_for_status()
print(resp.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment