cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
685
Views
0
Helpful
0
Replies

Select container using XPath expressions in template

gusmb
Level 1
Level 1

Hello,

 

I have the following config

 

 

admin@ncs% show provisioning base-config | display xpath 
/provisioning/base:base-config[zone='AMER']/region/AMER/country/US/dns/name-servers [ 1.1.1.1 1.1.1.2 ]
/provisioning/base:base-config[zone='APAC']/region/APAC/country/SG/dns/name-servers [ 2.2.2.1 2.2.2.2 ]
/provisioning/base:base-config[zone='EMEA']/region/EMEA/country/UK/dns/name-servers [ 3.3.3.1 3.3.3.2 ]
[ok][2020-07-27 12:15:20]

I want to configure a CDB template that selects the right DNS servers based on variables $REGION and $COUNTRY. I tried the following

 

 

 

admin@ncs% show devices template TM-BASE-DNS              
config {
    junos:configuration {
        system {
            name-server "{/provisioning/base:base-config[zone=$REGION]/region/node()/country/node()/dns/name-servers}";
        }
    }
}
[ok][2020-07-27 12:23:59]

 

 

admin@ncs% request devices device junos1 apply-template template-name TM-BASE-DNS variable { name REGION value 'AMER' } variable { name COUNTRY value 'US' }                        
apply-template-result {
    device junos1
    result ok
}
[ok][2020-07-27 12:15:03]

[edit]

 

admin@ncs% commit dry-run 
cli {
    local-node {
        data  devices {
                  device junos1 {
                      config {
                          junos:configuration {
                              system {
             +                    # first
             +                    name-server 1.1.1.1;
             +                    name-server 1.1.1.2;
                              }
                          }
                      }
                  }
              }
    }
}
[ok][2020-07-27 12:15:05]

 

This template works but with node() it just selects any random container. Instead, I would like to select the specific container that matches the name $REGION and the country container that matches the name given in $COUNTRY

 

I have tried the following and multiple combinations of this one using XPATH functions:

 

admin@ncs% show devices template TM-BASE-DNS 
config {
    junos:configuration {
        system {
            name-server "{/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers}";
        }
    }
}
[ok][2020-07-27 12:29:34]

However it always fails with an XPATH expression error:

 

 

admin@ncs% request devices device junos1 apply-template template-name TM-BASE-DNS variable { name REGION value 'AMER' } variable { name COUNTRY value 'US' }                                            
Error: Compilation of XPATH expression '/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers' at 'devices template TM-BASE-DNS config configuration system name-server "{/provisioning/base:base-config[zone=$REGION]/region/node()/country/contains($current,$REGION)/dns/name-servers}"' failed with result: XPath syntax error
[error][2020-07-27 12:32:01]

 

 

Does anyone know how would the XPATH expression works in this case? It works nicely when selecting nodes from a list, but I haven't figured it out for selecting a container...

 

Thanks

 

 

0 Replies 0
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 NSO Developer community: