You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a small script to add all of the templates to a node on Convoy automatically, replace the VMID's with your template ID's and names with your template names
And replace your API key with an API key and Convoy URL with your actual Convoy URL
importrequestsimportjson# Prompt user for node IDnode_id=input("Enter node ID: ")
convoy_url="vps.advinservers.com"api_key="XXXXX"# URL for the GET requestget_url=f"https://{convoy_url}/api/application/nodes/{node_id}/template-groups"# URL for the POST requestpost_url=f"https://{convoy_url}/api/application/nodes/{node_id}/template-groups"# URL for the POST request to add templatetemplate_url=f"https://{convoy_url}/api/application/nodes/{node_id}/template-groups/"# Headers for all requestsheaders= {
"Authorization": f"Bearer {api_key}",
"Accept": "application/json",
"Content-Type": "application/json"
}
# GET request to fetch dataresponse=requests.get(get_url, headers=headers)
ifresponse.status_code==200:
data=response.json()
else:
print("Error fetching data")
# POST requests to add template groups and templatestemplate_groups= [
{
"name": "Ubuntu",
"templates": [
{
"name": "Ubuntu 18.04",
"vmid": 100000
},
{
"name": "Ubuntu 20.04",
"vmid": 100001
},
{
"name": "Ubuntu 22.04",
"vmid": 100002
}
]
},
{
"name": "Debian",
"templates": [
{
"name": "Debian 11",
"vmid": 110000
}
]
},
{
"name": "CentOS",
"templates": [
{
"name": "CentOS 7",
"vmid": 120000
}
]
},
{
"name": "AlmaLinux",
"templates": [
{
"name": "AlmaLinux 8",
"vmid": 130000
}
]
},
{
"name": "RockyLinux",
"templates": [
{
"name": "RockyLinux 8",
"vmid": 140000
}
]
},
{
"name": "Windows",
"templates": [
{
"name": "Windows Server 2012R2 (Read Docs)",
"vmid": 150000
},
{
"name": "Windows Server 2019R2 (Read Docs)",
"vmid": 150001
},
{
"name": "Windows Server 2022 (Read Docs)",
"vmid": 150002
}
]
},
]
forgroupintemplate_groups:
# Submit POST request to add template groupform_data= {
"hidden": False,
"name": group['name']
}
# Encode form data as JSONjson_data=json.dumps(form_data)
response=requests.post(post_url, headers=headers, data=json_data)
ifresponse.status_code==200:
data=response.json()
print(f"Added template group '{group['name']}' with UUID: {data['data']['uuid']}")
# Submit POST requests to add templatesfortemplateingroup['templates']:
template_data= {
"hidden": False,
"name": template['name'],
"vmid": template['vmid']
}
# Encode template data as JSONjson_template_data=json.dumps(template_data)
template_url_with_uuid=f"{template_url}{data['data']['uuid']}/templates"template_response=requests.post(template_url_with_uuid, headers=headers, data=json_template_data)
iftemplate_response.status_code==200:
template_data=template_response.json()
print(f"Added template '{template['name']}' with UUID: {template_data['data']['uuid']} to template group '{group['name']}'")
else:
print(f"Error adding template '{template['name']}' to template group '{group['name']}'")
print(template_response.content)
else:
print(f"Error adding template group '{group['name']}'")
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This is a repost and wasn't created by me
Here's a small script to add all of the templates to a node on Convoy automatically, replace the VMID's with your template ID's and names with your template names
And replace your API key with an API key and Convoy URL with your actual Convoy URL
Beta Was this translation helpful? Give feedback.
All reactions