07-15-2021 12:40 AM
Hi Community,
I have created a device template that contains the default configuration for our branch SD-WAN routers.
Once a new site is deployed I would like to clone this device template so it becomes a new device template for a specific router.
We have a lot of specific customizations for each site which prevents us from having one single DT for everything.
I have found an API call for cloning a feature template but I can't really find a similar API call for cloning a device template.
Has anyone figured this out?
Regards
Jeppe
10-31-2022 04:02 PM - edited 10-31-2022 04:03 PM
Hi. Iam in a same situation as you. Did you find a solution to do this
11-01-2022 12:53 AM - edited 11-01-2022 12:55 AM
Hi Tahir.
Yes I did - sort of....
There is an API function for duplicating a Feature Template but as you probably found out this doesn't exist for a Device Template.
I ended up solving this using a specific template and a bunch of API calls:
1) I created a "Master"-template with all the correct settings which I will then duplicate. You need the assigned Template ID later
2) I read the configuration of the MASTER-template using https://[vManageUrl]/dataservice/template/device/object/[masterTemplateId] (GET-requerst)
This will give you the full configuration of the Device Template as JSON. This output will contain some info that you need to delete and you'll probably also have to add/modify some of the values to fit your environment. In my case I had to delete templateId, deviceRole, draftMode,templateClass to make it work. You also need to modify the templateName to the name of your new Device Template
3) I then create a new device template using the configuration retrieved from the master template
https://[vManageUrl]/dataservice/template/device/feature (POST-requerst) with the config from 2) as body
Now you have a new template which is a copy of the existing Master Template and the API will return the templateId of the newly created template. You need this when you are going to assign the template to a device
4) I then assign the new template to a specific device by using the https://[vManageUrl]/dataservice/template/device/config/attachfeature (POST-requerst) providing the details in the body together with the provided templateId from 3)
It's not pretty but it works. It took me a lot of time to make it work as the error messages returned could include more details on what went wrong.
I used Postman a lot in this process and the browser inspector to see what vManage actually did in the background
I hope this helps
Regards
Jeppe
11-01-2022 01:01 AM
Thanks so much . I’ll give this a try
11-01-2022 01:52 AM
Hi Tahir
Please remember to Accept as Solution if it works for you.
Regards
Jeppe
11-01-2022 11:35 AM
Thanks so so much this worked for me..
What i did is
I need a token to run this POST request. To get the token i ran (GET)https://{{vmanage}}:{{port}}/dataservice/client/token
Thanks so much Jeppe
08-19-2024 08:23 AM
Hi,
I used the GET API call to fetch the feature templates but it seems like the templates created by using the configuration group workflow doesn't appear in the output. Any chance someone found a way to get that data extracted as well?
11-08-2022 12:54 PM - edited 11-08-2022 01:01 PM
Python script for clone Device Template
from vmanage.api.authentication import Authentication
vmanage_host = "vmange_ip"
vmanage_username = "username"
vmanage_password = "Password"
auth = Authentication(host=vmanage_host, user=vmanage_username, password=vmanage_password).login()
def Get_Device_Template(temp_name,NewTemplate):
from vmanage.api.device_templates import DeviceTemplates
vmanage_DeviceTemplates = DeviceTemplates(auth, vmanage_host)
Dev_Temp_list = vmanage_DeviceTemplates.get_device_template_list()
for templet_data in Dev_Temp_list:
try:
if templet_data['templateName'] == temp_name:
templet_data.pop("templateId")
templet_data["templateName"] = NewTemplate
templet_data["templateDescription"] = NewTemplate
return templet_data
except Exception as e:
print (e)
def Create_Device_Template(templet_data):
from vmanage.api.device_templates import DeviceTemplates
vmanage_DeviceTemplates = DeviceTemplates(auth, vmanage_host)
try:
Dev_Temp_list = vmanage_DeviceTemplates.add_device_template(templet_data)
print (Dev_Temp_list['status_code'])
print (Dev_Temp_list['json'])
except Exception as e:
print (e)
NewTemplate = "API-TEMPNAME-ISR1"
ExistingTemplateName = "BRANCH-SMALL-ISR"
templet_data = Get_Device_Template(ExistingTemplateName,NewTemplate)
Create_Device_Template(templet_data)
12-30-2022 03:05 PM
You can try Sastre. It does an excellent job.
The Sastre-Pro version with all the bells and whistles is avaliable on Cisco Store, while hte public-version with limited capability is avaliable to Github
12-30-2022 05:03 PM - edited 12-30-2022 05:04 PM
Hi. Thanks I did try this. And it’s very good for backup/restore everything. Very good for lab environment .
but how do you copy a device template any idea ?
12-30-2022 10:42 PM
To copy any template just specify the 'template_device' or template_feature' as the case may be:
syntax: sdwan --verbose backup template_device
And to restore:
syntax: sdwan --verbose restore all --workdir <my_custom_directory>
Unless have have set you credentials using the script, you will need to specify your username , password, and vManage Mgmt IP in the command.
01-03-2023 12:32 AM
Thanks. this will copy a template from one Vmanage and restore it to the secondary Vmanage. If you want to clone a device template.
Let's say I have a device template called "Small_Branch_001" and i want to clone this to "Small_Branch_002" how will i do that with
syntax: sdwan ???
01-03-2023 07:46 AM
Well, if I understand your ask properly, you do not need an API to do that for you.
From vManage you can simply make a copy of the device template "Small_Branch_001" and name the new one "Small_Branch_002" - this will be the fastest way, unless there are lots of templates to clone.
On the flip side, I believe the Pro version of Sastre will allow you to list out all the device template, from where you can decide to copy/rename a specific one as desired. - I have to test this myself though.
Hope I answered your question.
01-04-2023 02:06 AM
Thanks for your reply. I know that I can copy/clone from vmange, but since I making a script to do automation I need to copy a device template via code.
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