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

L2VPN XML Data Parsing Problem

bjronmork
Level 1
Level 1

I am using below yang code to get list of interfaces for my selected PEs....

 

container ios-interfaces {
          when "/ncs:devices/ncs:device[ncs:name=current()/../device]/ncs:device-type/ncs:cli/ncs:ned-id='ios-id:cisco-ios'" {
            tailf:dependency "../device";
            tailf:dependency "/ncs:devices/ncs:device/ncs:device-type";
          }
          leaf intf-number {
            tailf:info "GigabitEthernet Interface ID";
            mandatory true;
            type leafref {
              path "deref(../../device)/../ncs:config/ios:interface/ios:GigabitEthernet/ios:name";
            }
          }
        }
container iosxr-interfaces {
          when "/ncs:devices/ncs:device[ncs:name=current()/../device]/ncs:device-type/ncs:cli/ncs:ned-id='cisco-ios-xr-id:cisco-ios-xr'" {
            tailf:dependency "../device";
            tailf:dependency "/ncs:devices/ncs:device/ncs:device-type";
          }
          leaf intf-number {
            tailf:info "GigabitEthernet Interface ID";
            mandatory true;
            type leafref {
              path "deref(../../device)/../ncs:config/cisco-ios-xr:interface/cisco-ios-xr:GigabitEthernet/cisco-ios-xr:id";
            }  }  }

 

below is the XML for getting interface details

 

    <device tags="nocreate">
      <name>{/link/device}</name>
      <config tags="merge">
        <interface xmlns="urn:ios">
          <GigabitEthernet tags="merge">
<!--         <name>0/0/1</name>     << if i hard-code 0/0/1 value; it works fine    -->
               <name tags="merge">{/intf-number}</name>
            <service>
              <instance tags="merge">
   

But if I use {intf-number} it gives me below error

 

Evaluating "intf-number" (from file "l2-vpls-template.xml", line 16)
Context node: /services/l2-vpls:mpls-l2-vpls[service-name='Service-01']/link[device='PE1']
Result: empty node - skipping siblings

Anyone pls suggest resolve this issue...

1 Accepted Solution

Accepted Solutions

Hi,

 

One of the trickiest aspects of working with XML templates in NSO is the context.

You can see on the debug output you have there that the context is changing depending on the last node being evaluated.

 

Not knowing your model, I can't tell where bridge-domain-id is located, but seems as it isn't located under the ios-interfaces container. You'd need to provide the right xpath expression to get from ios-interfaces to bridge-domain-id.

 

Sometimes you have to use relative path for that, and in that case, you need to know what the context will be at the time the expression is evaluated in order to provide the right expression.

 

Sometimes you can use absolute path in your expression and then you don't care about the current context.

 

In both cases, accessing nodes on a different path may change your context, so if for some reason you need the context kept, you can use {string(/something/outside/my/current/context)} to access something outside your current context, but still keep your context.

 

All in all, the questions you need to ask for a given XML line are:

 

1. What's my current context (you can see that on the debug output)?

2. Where do I need to get the next bit from, and how do I get there?

3. Do I care what the context would be after I get the next bit?

 

 

If you aren't able to make it work, share some more details about the model and about the template, and we can try and help.

View solution in original post

3 Replies 3

yfherzog
Cisco Employee
Cisco Employee

You're pointing to {/intf-number}.

'/' points to the service instance, which in your case is /services/l2-vpls:mpls-l2-vpls[service-name='Service-01'].

Your xpath statement should be relative to the current context (seen on the debug output) and should not container the '/'.

If I understand your model correctly, it should be something like this: {ios-interfaces/intf-number}

Thanks yfherzog,

I applied {ios-interfaces/intf-number}, which works fine; but somehow other values are not working now....debug of service is given below;

 

 

root@ncs(config)# commit dry-run | debug template l2-vpls-template
Evaluating "/link/device" (from file "l2-vpls-template.xml", line 7)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']
Result:
For /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1'], it evaluates to "PE1"
For /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2'], it evaluates to "PE2"
Operation 'nocreate' on node /devices/device[name='PE1'] (from file "l2-vpls-template.xml", line 7)
Node exists, continuing...
Operation 'nocreate' on node /devices/device[name='PE1']/config/ios:interface (from file "l2-vpls-template.xml", line 11)
Node exists, continuing...
Evaluating "ios-interfaces/intf-number" (from file "l2-vpls-template.xml", line 13)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1']
Result:
For /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1']/ios-interfaces, it evaluates to "0/0/1"
Operation 'merge' on existing node: /devices/device[name='PE1']/config/ios:interface/GigabitEthernet[name='0/0/1'] (from file "l2-vpls-template.xml", line 13)
Evaluating "bridge-domain-id" (from file "l2-vpls-template.xml", line 16)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1']/ios-interfaces
Result: empty node - skipping siblings
Evaluating "bridge-domain-id" (from file "l2-vpls-template.xml", line 48)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1']
Result: empty node - skipping siblings
Evaluating "vfi-context-name" (from file "l2-vpls-template.xml", line 64)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1']
Result: empty node - skipping siblings
Operation 'nocreate' on node /devices/device[name='PE2'] (from file "l2-vpls-template.xml", line 7)
Node exists, continuing...
Operation 'nocreate' on node /devices/device[name='PE2']/config/ios:interface (from file "l2-vpls-template.xml", line 11)
Node exists, continuing...
Evaluating "ios-interfaces/intf-number" (from file "l2-vpls-template.xml", line 13)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2']
Result:
For /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2']/ios-interfaces, it evaluates to "0/0/1"
Operation 'merge' on existing node: /devices/device[name='PE2']/config/ios:interface/GigabitEthernet[name='0/0/1'] (from file "l2-vpls-template.xml", line 13)
Evaluating "bridge-domain-id" (from file "l2-vpls-template.xml", line 16)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2']/ios-interfaces
Result: empty node - skipping siblings
Evaluating "bridge-domain-id" (from file "l2-vpls-template.xml", line 48)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2']
Result: empty node - skipping siblings
Evaluating "vfi-context-name" (from file "l2-vpls-template.xml", line 64)
Context node: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2']
Result: empty node - skipping siblings

 

xpath also not give right paths information..portion of xpath result is given below;

 

 2019-04-09T08:01:04.454 xpath: exists(/devices/device[name='PE1']) = true
 2019-04-09T08:01:04.455 xpath: exists(/devices/device[name='PE1']/device-type/cli) = true
 2019-04-09T08:01:04.456 xpath: get_elem(/devices/device[name='PE1']/device-type/cli/ned-id) = ios-id:cisco-ios
 2019-04-09T08:01:04.457 xpath: result: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1']/ios-interfaces: true [0.004 sec]
 2019-04-09T08:01:04.464 xpath: template l2-vpls-template: match: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1']/ios-interfaces/intf-number
 2019-04-09T08:01:04.465 xpath: template l2-vpls-template: result: one node [0.013 sec]
 2019-04-09T08:01:04.468 xpath: template l2-vpls-template: evaluating: bridge-domain-id
 2019-04-09T08:01:04.468 xpath: template l2-vpls-template: result: no nodes [0.000 sec] 2019-04-09T08:01:04.469 xpath: template l2-vpls-template: evaluating: bridge-domain-id
 2019-04-09T08:01:04.469 xpath: template l2-vpls-template: result: no nodes [0.000 sec]
 2019-04-09T08:01:04.470 xpath: template l2-vpls-template: evaluating: vfi-context-name
 2019-04-09T08:01:04.470 xpath: template l2-vpls-template: result: no nodes [0.000 sec]
 2019-04-09T08:01:04.472 xpath: template l2-vpls-template: evaluating: ios-interfaces/intf-number
 2019-04-09T08:01:04.473 xpath: evaluating: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2']/ios-interfaces: /ncs:devices/ncs:device[ncs:name=current()/../device]/ncs:device-type/ncs:cli/ncs:ned-id='ios-id:cisco-ios'
 2019-04-09T08:01:04.475 xpath: exists(/devices/device[name='PE2']) = true
 2019-04-09T08:01:04.476 xpath: exists(/devices/device[name='PE2']/device-type/cli) = true
 2019-04-09T08:01:04.478 xpath: get_elem(/devices/device[name='PE2']/device-type/cli/ned-id) = ios-id:cisco-ios
 2019-04-09T08:01:04.479 xpath: result: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2']/ios-interfaces: true [0.005 sec]
 2019-04-09T08:01:04.485 xpath: template l2-vpls-template: match: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE2']/ios-interfaces/intf-number
 2019-04-09T08:01:04.486 xpath: template l2-vpls-template: result: one node [0.013 sec]
 2019-04-09T08:01:04.488 xpath: template l2-vpls-template: evaluating: bridge-domain-id
 2019-04-09T08:01:04.488 xpath: template l2-vpls-template: result: no nodes [0.000 sec]
 2019-04-09T08:01:04.489 xpath: template l2-vpls-template: evaluating: bridge-domain-id
 2019-04-09T08:01:04.489 xpath: template l2-vpls-template: result: no nodes [0.000 sec]
 2019-04-09T08:01:04.490 xpath: template l2-vpls-template: evaluating: vfi-context-name
 2019-04-09T08:01:04.491 xpath: template l2-vpls-template: result: no nodes [0.000 sec]
 2019-04-09T08:01:04.501 xpath: evaluating: /services/l2-vpls:l2-vpls[service-name='Service01']/link[device='PE1']/ios-interfaces: /ncs:devices/ncs:device[ncs:name=current()/../device]/ncs:device-type/ncs:cli/ncs:ned-id='ios-id:cisco-ios'
 2019-04-09T08:01:04.503 xpath: exists(/devices/device[name='PE1']) = true

Please suggest..Thanks in advance for your support...

 

 

Hi,

 

One of the trickiest aspects of working with XML templates in NSO is the context.

You can see on the debug output you have there that the context is changing depending on the last node being evaluated.

 

Not knowing your model, I can't tell where bridge-domain-id is located, but seems as it isn't located under the ios-interfaces container. You'd need to provide the right xpath expression to get from ios-interfaces to bridge-domain-id.

 

Sometimes you have to use relative path for that, and in that case, you need to know what the context will be at the time the expression is evaluated in order to provide the right expression.

 

Sometimes you can use absolute path in your expression and then you don't care about the current context.

 

In both cases, accessing nodes on a different path may change your context, so if for some reason you need the context kept, you can use {string(/something/outside/my/current/context)} to access something outside your current context, but still keep your context.

 

All in all, the questions you need to ask for a given XML line are:

 

1. What's my current context (you can see that on the debug output)?

2. Where do I need to get the next bit from, and how do I get there?

3. Do I care what the context would be after I get the next bit?

 

 

If you aren't able to make it work, share some more details about the model and about the template, and we can try and help.

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: