11-14-2024 11:12 AM
Hello Everyone,
I need assistance with the Vmanager API, I need to reattach a device that in CLI mode to an existing template. I have used multiple API calls such as https://vmanage-ip-address/dataservice/template/device/config/attachfeature and /attachcli. These calls are being processed by the vmanager but is not moving the device to said template. Can anyone assist with the proper process or calls needed to reattach a device to an existing template?
Thank you!
11-14-2024 11:13 AM
If possible, can someone provide the API calls needed/script example to reattach a device to a template.
11-14-2024 11:20 PM - edited 11-15-2024 03:04 AM
/dataservice/template/device/config/attachfeature is the correct endpoint and should work. What response are you getting, and what is the result of the "attach action"? If you can post vManage version, example requests and/or code it would help a lot in assisting you with this.
11-15-2024 02:42 AM
@wolfcaptain2002 can you share the code, do you get any error messages in the UI?
11-18-2024 03:07 PM
Hello, sorry for the late reply; I did not see the email response. My code may be messy since I'm only testing to see if it works, but here are the code snippets, as requested. I used the examples provided on the SDWAN API Documentation. I have received no errors, just a status response.
Thank you again!
def Attach_Template(Template_ID):
URL = f'https://{vmanage}/dataservice/template/device/config/attachcli'
headers = {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': f'{Token}',
'Cookie': f'JSESSIONID={Cookie}'
}
data = {"deviceTemplateList":[
{
"templateId":f"{Template_ID}",
"cliType": "device",
"device":[
{
"csv-status":f"{INPUT_VARS['data'][0]['csv-status']}",
"csv-deviceId":f"{INPUT_VARS['data'][0]['csv-deviceId']}",
"csv-deviceIP":f"{INPUT_VARS['data'][0]['csv-deviceIP']}",
"csv-host-name":f"{INPUT_VARS['data'][0]['csv-host-name']}",
"//system/host-name":f"{INPUT_VARS['data'][0]['//system/host-name']}",
"//system/system-ip":f"{INPUT_VARS['data'][0]['//system/system-ip']}",
"//system/site-id":f"{INPUT_VARS['data'][0]['//system/site-id']}",
"csv-templateId":"41f6a440-c5cc-4cc6-9ca1-af18e332a781",
"selected":"true"
}
],
"isEdited":'false',
"isMasterEdited":'false'
}
]
}
response = requests.post(URL, headers=headers, verify=False,data=json.dumps(data))
response = json.loads(response.text)
print(response)
Monitor_URL = f'https://{vmanage}/dataservice/device/action/status/{response["id"]}'
Monitor_Response = requests.get(Monitor_URL,headers=headers,verify=False)
Monitor_Response = json.loads(Monitor_Response.text)
Feature_URL = f'https://{vmanage}/dataservice/template/device/config/attachfeature'
FEATURE_response = requests.post(Feature_URL, headers=headers, verify=False,data=json.dumps(data))
FEATURE_response = json.loads(FEATURE_response.text)
print(FEATURE_response)
11-19-2024 02:21 AM
@wolfcaptain2002 try this version, it has some of the things removed to make this simple and it follow the API document. Let me know if you see any difference in behavior. Also, could you share what response you get from this too.
I would expect to see 'failed' in the UI if this wasnt correct.
def attach_template(template_id, device_id):
URL = f'https://{vmanage}/dataservice/template/device/config/attachcli'
headers = {
'Content-Type': 'application/json',
'X-XSRF-TOKEN': f'{Token}',
'Cookie': f'JSESSIONID={Cookie}'
}
# Simplified data structure matching API documentation
data = {
"deviceTemplateList": [{
"templateId": template_id,
"device": [{
"csv-status": "complete",
"csv-deviceId": device_id,
"csv-deviceIP": "-",
"csv-host-name": "-",
"csv-templateId": template_id
}],
"isEdited": False
}]
}
# Make the attachment request
response = requests.post(URL, headers=headers, verify=False, data=json.dumps(data))
response_data = response.json()
print("Attachment response:", response_data)
if 'id' in response_data:
# Monitor the task status
monitor_url = f'https://{vmanage}/dataservice/device/action/status/{response_data["id"]}'
for _ in range(30): # Check status for up to 5 minutes
monitor_response = requests.get(monitor_url, headers=headers, verify=False)
status = monitor_response.json()
print("Status:", status)
if status.get('status') == 'Success':
return True
elif status.get('status') in ['Failure', 'Failed']:
print("Failed:", status.get('message', 'No error message'))
return False
time.sleep(10)
return False
11-26-2024 11:55 AM - edited 11-26-2024 10:22 PM
Hello @bigevilbeard,
Thank you for the code snippet. I have also used the structure mentioned in the API Documentation before. Sorry for the long delay in responses here is the output that you wanted and sadly the template is still not attaching. Looks like it is just repeating.
Thank you!
11-27-2024 02:00 AM
Interesting. Your logs indicate a failure in the configuration push process, despite the validation being successful and it seems template passes the test, that suggests the issue is not with the template.
The null entry is interesting but does show much I would expect something here maybe showing an error.
11-27-2024 08:46 AM
The environment I’m using is the Sandbox I wonder if this is the reason… could be a bug?
11-27-2024 08:56 AM
@wolfcaptain2002 can you share your entire script and template, would like to try this - Please correct me here, you have downloaded template from one of the devices and are attempting to upload this to another device and this is on the reservation sandbox?
Thanks!
11-27-2024 09:38 AM
Hello @bigevilbeard,
Currently all the script does is detaching and trying to re-attach a template I have not edited the template on a configuration stand point. The Sandbox that I'm using SD-WAN 20.12. I will provide the template configurations here shortly. Thank you for your help so far.
Template ID = 2c30ea87-42d8-40b4-b2ae-5ba8c33005ce
11-27-2024 05:22 PM
Hello @bigevilbeard,
This is the full script that im using you can find the template and the feature templates in the Cisco SD-WAN 20.12 Sandbox Im looking forward to your response.
Thanks
11-28-2024 02:19 AM
Thanks, i will reserve the sandbox and give this a try
11-28-2024 09:09 AM
@wolfcaptain2002 i spent a few hours on this, and even with the whole csv template in json this fails, the UI does not show why. I am looking to see if i can use a log/tail on the cli to see why, it is very odd. I captured the raw json via developer tools attached as working.text file.
The python code will output the entire steps and re-try after 10 seconds, max attempts is 30. I am checking with a few folks on this as it is very odd indeed.
11-28-2024 03:54 PM - edited 11-28-2024 04:19 PM
Hello @wolfcaptain2002, @bigevilbeard,
I have attached a working version of the script. The issue was that this required the use of the /attachfeature endpoint instead of the /attachcli endpoint as this is a feature template based device template. What I find weird is that this didn't throw a 400 error, it got through validation and that there were no useful error messages in the UI. The only useful log entry I was able to find is the following line in the vmanage-server-deviceconfig-template.log file:
28-Nov-2024 23:20:59,697 UTC ERROR [] [] [TemplateRollbackManager] (Process device action - Push CLI Template Configuration) || ConfigTemplateType is null. Returning without finalizing..
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide