cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
806
Views
11
Helpful
2
Replies
Highlighted
Beginner

CliTemplates/Apache Velocity Template Language - split function

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
Cisco Employee

Re: CliTemplates/Apache Velocity Template Language - split function

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>

2 REPLIES
Cisco Employee

Re: CliTemplates/Apache Velocity Template Language - split function

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>

Beginner

Re: CliTemplates/Apache Velocity Template Language - split function

Hi Spencer,

That works for me, thanks very much.

Carl

Ask the Expert- DMVPN on Cisco routers