cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2322
Views
5
Helpful
13
Replies

How to clone a vManage Device Template using API

Pixelweb
Level 1
Level 1

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

13 Replies 13

TahirAli12881
Level 1
Level 1

Hi. Iam in a same situation as you. Did you find a solution to do this

 

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

 

Thanks so much . I’ll give this a try

Pixelweb
Level 1
Level 1

Hi Tahir 

Please remember to Accept as Solution if it works for you.

Regards

Jeppe

Thanks so so much this worked for me..

What i did is

  • To get list of all my templates using this API endpoint
    • (GET) https://{{vmanage}}:{{port}}/dataservice/template/device
    • searched for the template name i wanted to clone (copy the templateId).
  • Then i ran (GET) https://{{vmanage}}:{{port}}/dataservice/template/device/object/templateId
    • This gave me a json output. I just removed "templateId" from this output and used rest of it as input on my next API call
  • then i ran (POST) https://{{vmanage}}:{{port}}/dataservice/template/device/feature with the body (input from above step)

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

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?

TahirAli12881
Level 1
Level 1

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)

 

 

 

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

TahirAli12881
Level 1
Level 1

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 ?

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.

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

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.

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. 

Review Cisco Networking for a $25 gift card