cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2460
Views
11
Helpful
2
Replies

CliTemplates/Apache Velocity Template Language - split function

carl.simpson2
Level 1
Level 1

Hi,

Can anyone provide a sample Cisco Prime CliTemplate making use of split?

I'm looking to feed in a variable containing a /48 IPv6 prefix and then use parts of it in various sections of the device configuration.

So for example I'd like to take '2001:DB8::/48' split on say '::'

Giving me '2001:DB8' in a variable which I can append '::/64' to use on an interface.

I've tried the examples shown here but it breaks the template in Prime: apache - Using velocity split() to split a string into an array doesnt seem to work - Stack Overflow

Taken from the link about, should something like the below work (Giving me 'This')?

#set ($myString = “This|is|my|dummy|text”)

#set ($myArray = $myString.split("\|"))

$myArray[0]


Thanks,


Carl

1 Accepted Solution

Accepted Solutions

Spencer Zier
Cisco Employee
Cisco Employee

Carl,

Based on what you're after, I think the CLI content that you're looking for is more like this

#set ( $ipv6_64subnet = $ipv6_string.split("::")[0].concat("::/64") )

do_work $ipv6_64subnet

I've put that in an XML payload that you can POST to v1/op/cliTemplateConfiguration/upload.  It worked as expected on my 3.1.5 (dev build of the 3.1.5 patch) server when deployed via either the API or GUI.

<?xml version="1.0" ?>

<cliTemplate>

  <content>#set ( $ipv6_64subnet = $ipv6_string.split("::")[0].concat("::/64") )

do_work $ipv6_64subnet</content>

  <description>carl_test</description>

  <deviceType>Routers</deviceType>

  <name>carl_test_api</name>

  <variables>

<variable>

<description>IPv6 String</description>

<displayLabel>IPv6 String</displayLabel>

<name>ipv6_string</name>

<required>true</required>

<type>String</type>

</variable>

</variables>

</cliTemplate>

View solution in original post

2 Replies 2

Spencer Zier
Cisco Employee
Cisco Employee

Carl,

Based on what you're after, I think the CLI content that you're looking for is more like this

#set ( $ipv6_64subnet = $ipv6_string.split("::")[0].concat("::/64") )

do_work $ipv6_64subnet

I've put that in an XML payload that you can POST to v1/op/cliTemplateConfiguration/upload.  It worked as expected on my 3.1.5 (dev build of the 3.1.5 patch) server when deployed via either the API or GUI.

<?xml version="1.0" ?>

<cliTemplate>

  <content>#set ( $ipv6_64subnet = $ipv6_string.split("::")[0].concat("::/64") )

do_work $ipv6_64subnet</content>

  <description>carl_test</description>

  <deviceType>Routers</deviceType>

  <name>carl_test_api</name>

  <variables>

<variable>

<description>IPv6 String</description>

<displayLabel>IPv6 String</displayLabel>

<name>ipv6_string</name>

<required>true</required>

<type>String</type>

</variable>

</variables>

</cliTemplate>

Hi Spencer,

That works for me, thanks very much.

Carl

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: