cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements
1584
Views
5
Helpful
4
Replies

How to apply a device template to a device when a character contains a special character like '!'?

Hi,

I have a device template which I am using to configure my device's password. Here the is the results:

 

admin@ncs(config)# devices device nexus apply-template template-name test variable { name pass value 'cisco' }
apply-template-result {
device nexus
result ok
}
admin@ncs(config)# commit dry-run outformat native
native {
device {
name nexus
data username admin password 0 cisco role network-admin
}
}
admin@ncs(config)# commit
Commit complete.

 

I confirm it works by ssh'ing to the real device with the new password.

 

Now when adding a special character, here is the result:

 

admin@ncs(config)# devices device nexus apply-template template-name test variable { name pass value 'cisco!123' }
-----------------------------------------------------------------------------------------------------------^
syntax error: expecting '}'

 

I know what is being sent is XPath logic per:

 

admin@ncs(config)# devices device nexus apply-template template-name test variable { name pass value ?
Possible completions:
<node set> - an XPath expression resulting in a node set
<number> - some integer or float number. This is an XPath number.
<quoted> - some text enclosed in single quotes. This is an XPath string.

 

Does anyone here know what value I need to insert between the single quotes that include a special character to make it work? Or is it not supported?

 

thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
ramkraja
Cisco Employee

'!' is a comment marker in the C-style CLI, so, of course you should escape that character in the C-style CLI in general, and especially in templates. So, use 'cisco\!23' as the value in the command.

If you try the same in the J-style CLI, it will work even without the escaping. But you can see the same problem in the J-style CLI, with the '#' character, since '#' denotes a comment in the J-style CLI. So, in J-style CLI, to configure a value with '#' character, you should escape it, like 'cisco\#123'

/Ram

View solution in original post

4 REPLIES 4
ramkraja
Cisco Employee

'!' is a comment marker in the C-style CLI, so, of course you should escape that character in the C-style CLI in general, and especially in templates. So, use 'cisco\!23' as the value in the command.

If you try the same in the J-style CLI, it will work even without the escaping. But you can see the same problem in the J-style CLI, with the '#' character, since '#' denotes a comment in the J-style CLI. So, in J-style CLI, to configure a value with '#' character, you should escape it, like 'cisco\#123'

/Ram

View solution in original post

Thank you so much! I made the mistake of assuming it had something to do with how XPath is configured, but of course it was as simple as utilizing a backslash within the text value.

Much appreciated.

I meet the same question but the another char "?", the question mask.

the device is F5 and I want to create a monitor, there is a parameter called "send", and its value is an url. In the following example, I simple the value "get ?"

Of cause, I use the escape character but the nso give the following error info:

 

<ERROR> 05-Mar-2020::23:06:14.602 NedComGenericBase Ned-Worker-Thread-0: - BigIP Error in prepare
com.tailf.ned.NedException: AddToTransaction:
Device Response:
create /ltm monitor http "sj-test" {  adaptive "disabled" defaults-from "http" destination "*:*" interval "5" ip-dscp "0" recv "none" recv-disable "none" send "get \?" time-until-up "0" timeout "16" } 
->
Command:
create /ltm monitor http "sj-test" {  adaptive "disabled" defaults-from "http" destination "*:*" interval "5" ip-dscp "0" recv "none" recv-disable "none" send "get \?" time-until-up "0" timeout "16" } 
        at com.tailf.packages.ned.bigip.BigIpNedGeneric.addToTransaction(BigIpNedGeneric.java:4816)
        at com.tailf.packages.ned.bigip.BigIpNedGeneric.addToTransaction(BigIpNedGeneric.java:4728)
        at com.tailf.packages.ned.bigip.BigIpNedGeneric.edit(BigIpNedGeneric.java:3537)
        at com.tailf.packages.ned.bigip.BigIpNedGeneric.prepare(BigIpNedGeneric.java:3100)
        at com.tailf.ned.NedWorker.dorun(NedWorker.java:1589)
        at com.tailf.ned.NedWorker.run(NedWorker.java:294)
<ERROR> 05-Mar-2020::23:06:14.603 NedComGenericBase Ned-Worker-Thread-0: - BigIP AddToTransaction:
Device Response:
create /ltm monitor http "sj-test" {  adaptive "disabled" defaults-from "http" destination "*:*" interval "5" ip-dscp "0" recv "none" recv-disable "none" send "get \?" time-until-up "0" timeout "16" } 
->
Command:
create /ltm monitor http "sj-test" {  adaptive "disabled" defaults-from "http" destination "*:*" interval "5" ip-dscp "0" recv "none" recv-disable "none" send "get \?" time-until-up "0" timeout "16" } 
<WARN> 05-Mar-2020::23:06:14.603 NedWorker Ned-Worker-Thread-0: - reporting error with illegal errorcode : 'AddToTransaction:
Device Response:
create /ltm monitor http "sj-test" {  adaptive "disabled" defaults-from "http" destination "*:*" interval "5" ip-dscp "0" recv "none" recv-disable "none" send "get \?" time-until-up "0" timeout "16" } 
->
Command:
create /ltm monitor http "sj-test" {  adaptive "disabled" defaults-from "http" destination "*:*" interval "5" ip-dscp "0" recv "none" recv-disable "none" send "get \?" time-until-up "0" timeout "16" } ', fallback to NED_EXTERNAL_ERROR



I define the "send" element in my Yang , use the:

module monitor {
...
import ietf-inet-types {
prefix inet;
}
...
leaf send {
type inet:uri;
}
}

 it seems can accept the vaule "Get \?" , but it still cannot accept the value "GET /HELLO/WORLD/cisco\?success\r\n"