cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3374
Views
3
Helpful
28
Replies

SDWAN VManager Moving a device to an existing Template

wolfcaptain2002
Level 1
Level 1

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!

28 Replies 28

wolfcaptain2002
Level 1
Level 1

If possible, can someone provide the API calls needed/script example to reattach a device to a template.

Torbjørn
VIP
VIP

/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.

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev

@wolfcaptain2002 can you share the code, do you get any error messages in the UI?

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

wolfcaptain2002
Level 1
Level 1

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)

 

@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

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

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!

 

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.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

The environment I’m using is the Sandbox I wonder if this is the reason… could be a bug? 

@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!

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

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

 

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

Thanks, i will reserve the sandbox and give this a try

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

@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.

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

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..

 

 

 

Happy to help! Please mark as helpful/solution if applicable.
Get in touch: https://torbjorn.dev