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

deref of instance-identifier failing

grundler
Level 1
Level 1

For context, I'm working on two services: a VLAN service to assign IDs to edge ports, and another to manage edge ports themselves.  The problem I am trying to solve is that I need to be able to associate a physical port on a device with exactly one VLAN service instance, and I don't want to have to manually remove the interface from another VLAN service instance if it's been previously assigned. 

 

The way I've been trying to implement this is by having an 'allocating-service' leaf in my port service that is of type instance-identifier.   When any service wants to associate a port with itself, it can check the port service for the instance it wants to manage and see if another service has already set the 'allocating-service' leaf.  The port model looks like this:

 

list port {
key "device iftype hwid";
leaf device { type leafref { path "/ncs:devices/ncs:device/ncs:name"; } } leaf iftype { type enumeration { enum "GigE"; enum "TenGigE"; enum "TwentyFiveGigE"; enum "FortyGigE"; enum "HundredGigE"; } mandatory true; } leaf hwid { tailf:info "Hardware identifier for the interace, e.g '1/1/2'"; type string { pattern "[0-9]/((5[0-4]|[1-4][0-9]|[0-9]))(/((5[0-4]|[1-4][0-9]|[0-9])))*"; } mandatory true; } leaf allocating-service { type instance-identifier; } }

 I am able to set the instance identifier in my code without an issue.  The problem I'm running into is using that instance-identifier in my service code/templates to remove the port from the service instance referred to by the allocating-service leaf.  I was unable find a way in the python API to get a maagic object from the instance-identifier, so I'm trying to use a template to remove the port from the service pointed to by the instance-identifier:

 

<config-template xmlns="http://tail-f.com/ns/config/1.0">
  <services xmlns="http://tail-f.com/ns/ncs">
    <?save-context ctx?>

    <port xmlns="http://example.com/ifconfig" tags="delete">
      <device>{device}</device>
      <iftype>{iftype}</iftype>
      <hwid>{hwid}</hwid>
    </port>

    <?set-context-node {deref(allocating-service)}?>
    <network xmlns="http://example.com/network">
      <name>{../../name}</name>
      <distribution-zone>
        <name>{name}</name>
        <?switch-context ctx?>
        <switchport tags="delete">
          <device>{device}</device>
          <iftype>{iftype}</iftype>
          <hwid>{hwid}</hwid>
        </switchport>
      </distribution-zone>
    </network>

  </services>
</config-template>

Applying this template fails, however, because when I attempt to deref the instance-identifier, it evaluates to an empty node:

 

admin@ncs% commit dry-run | debug template
Evaluating "device" (from file "delete-phy-template.xml", line 6)
Context node: /services/net:network[name='V-BLDGA-USER']/distribution-zone[name='BLDGA']/switchport[device='ca-BLDGA-1'][iftype='GigE'][hwid='1/17']
Result:
For /services/net:network[name='V-BLDGA-USER']/distribution-zone[name='BLDGA']/switchport[device='ca-BLDGA-1'][iftype='GigE'][hwid='1/17'], it evaluates to "ca-BLDGA-1"
Evaluating "iftype" (from file "delete-phy-template.xml", line 7)
Context node: /services/net:network[name='V-BLDGA-USER']/distribution-zone[name='BLDGA']/switchport[device='ca-BLDGA-1'][iftype='GigE'][hwid='1/17']
Result:
For /services/net:network[name='V-BLDGA-USER']/distribution-zone[name='BLDGA']/switchport[device='ca-BLDGA-1'][iftype='GigE'][hwid='1/17'], it evaluates to "GigE"
Evaluating "hwid" (from file "delete-phy-template.xml", line 8)
Context node: /services/net:network[name='V-BLDGA-USER']/distribution-zone[name='BLDGA']/switchport[device='ca-BLDGA-1'][iftype='GigE'][hwid='1/17']
Result:
For /services/net:network[name='V-BLDGA-USER']/distribution-zone[name='BLDGA']/switchport[device='ca-BLDGA-1'][iftype='GigE'][hwid='1/17'], it evaluates to "1/17"
Operation 'delete' on node: /services/ifc:phy[device='ca-BLDGA-1'][iftype='GigE'][hwid='1/17'] (from file "delete-phy-template.xml", line 8)
Processing instruction 'set-context-node': changing XPath current context node, evaluating (from file "delete-phy-template.xml", line 11)
Evaluating "deref(allocating-service)" (from file "delete-phy-template.xml", line 11)
Context node: /services/net:network[name='V-BLDGA-USER']/distribution-zone[name='BLDGA']/switchport[device='ca-BLDGA-1'][iftype='GigE'][hwid='1/17']
Result: empty node
Aborted: Python cb_create error. Unknown error (66): delete-phy-template.xml:11: The target node for processing instruction 'set-context-node' does not exist.
[error][2021-05-02 11:12:19]

 

I am assuming the instance identifier itself is valid since I'm able to set it in the first place.  Am I using deref incorrectly here?  Is there some other pattern in NSO/YANG I can use to ensure that a single physical resource is only associated with one service instance?  Thank you in advance for any advice/suggestions, and please let me know if I can provide additional data/context.

0 Replies 0