cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1772
Views
3
Helpful
4
Replies

leafref to allocated pw-id using resource-manager bundle

jjgrinwis
Level 1
Level 1

Hi,

doing some tests with the resource manager package.

It's all working fine and ID allocted for a newly provisioned l2vpn service.

admin@ncs> show resource-pools id-pool pw-id

NAME   ID         ERROR  ID 

------------------------------

pw-id  testtest2  -      101

But is there a way to point from our service back to this id as operational data.

I can lookup the ID using normal xpath:

$ ncs_cmd -c "xe /ralloc:resource-pools/id-pool[name='pw-id']/allocation[id='testtest2']/response/id"

XPATH_TRACE: exists("/ralloc:resource-pools/id-pool{pw-id}") = true

XPATH_TRACE: exists("/ralloc:resource-pools/id-pool{pw-id}/allocation{testtest2}") = true

XPATH_TRACE: get_elem("/ralloc:resource-pools/id-pool{pw-id}/allocation{testtest2}/response/id") = 101

101


So can we do something like this:


admin@ncs> show services l2vpn pw-id      

           PW

NAME       ID

---------------

testtest2  - 

Where it then will return the selected PW ID.

tried YANG code below to point back to our id but that doesn't seem to work

leaf id-pool {

        tailf:info "provide pool to get vpn-ids from";

        type leafref {

          path "/ralloc:resource-pools/idalloc:id-pool/idalloc:name";

        }

        mandatory true;

      }

      leaf pw-id {

        tailf:info "unique l2vpn pw id";

        type leafref {

          // we can't use static names in leafref so need to configure id-pool to get id

          path "/ralloc:resource-pools/idalloc:id-pool[idalloc:name=current()/../id-pool]/idalloc:allocation[idalloc:id=current()/../name]/idalloc:response/idalloc:id";

          }

        config false;

      }

Regards,

John

1 Accepted Solution

Accepted Solutions

frjansso
Cisco Employee
Cisco Employee

AFAIK you cannot do this through the YANG. What I usually do is that I add something like the below to my service code. Please note that I'm allocating VLANs for pairs of devices in my example.

Svc code:

  v = self.svc.allocations.vlan.create([d1, d2])

  v.vlan = vlan

Svc YANG:

    container allocations {

      config false;

      tailf:cdb-oper {

        tailf:persistent true;

      }

      list vlan {

        key "device-1 device-2";

        leaf device-1 {

          type string;

        }

        leaf device-2 {

          type string;

        }

        leaf vlan {

          type uint16 {

            range 0..4096;

          }

        }

      }

    }

And in the CLI:

admin@mdp> show nni allocations

DOMAIN      DEVICE 1           DEVICE 2          VLAN

-------------------------------------------------------

dom   d1 d2 1000

          d1 d3 1001

View solution in original post

4 Replies 4

frjansso
Cisco Employee
Cisco Employee

AFAIK you cannot do this through the YANG. What I usually do is that I add something like the below to my service code. Please note that I'm allocating VLANs for pairs of devices in my example.

Svc code:

  v = self.svc.allocations.vlan.create([d1, d2])

  v.vlan = vlan

Svc YANG:

    container allocations {

      config false;

      tailf:cdb-oper {

        tailf:persistent true;

      }

      list vlan {

        key "device-1 device-2";

        leaf device-1 {

          type string;

        }

        leaf device-2 {

          type string;

        }

        leaf vlan {

          type uint16 {

            range 0..4096;

          }

        }

      }

    }

And in the CLI:

admin@mdp> show nni allocations

DOMAIN      DEVICE 1           DEVICE 2          VLAN

-------------------------------------------------------

dom   d1 d2 1000

          d1 d3 1001

thanx for the answer.

I'm now just writing the selected pw-id as operational data of the service:

---

with ncs.maapi.single_write_trans(tctx.username, 'system', db=ncs.OPERATIONAL) as t:

            t.set_elem(pw_id, path)

            t.apply()

            self.log.info('pw-id added as operational data to model')

---

admin@ncs> show services l2vpn pw-id

      PW 

NAME   ID 

------------

test1  100 

test2  101

rogaglia
Cisco Employee
Cisco Employee

Hi all,

I just want to point-out that the semantic of what you are proposing here is a little bit more complex. Your code stores as operational data the assigned id-values at the time of the last execution of the service create(). This may not be the same as the current allocation from the resource manager as the service could be "out-of-sync".

If what you need is the current allocation value for that service instance without copying any value, you should be able to use the tailf:link extension as long as you can compose the target path (like if the pool and allocation name is well-know for your service model). Another option would be via a data provider.

Roque

tailf:link target

This statement specifies that the data node should be implemented as a link to another data node, called the target data node. This means that whenever the node is modified, the system modifies the target data node instead, and whenever the data node is read, the system returns the value of target data node.

Note that if the data node is a leaf, the target node MUST also be a leaf, and if the data node is a leaf-list, the target node MUST also be a leaf-list.

Note that the type of the data node MUST be the same as the target data node. Currently the compiler cannot check this.

The argument is an XPath absolute location path. If the target lies within lists, all keys must be specified. A key either has a value, or is a reference to a key in the path of the source node, using the function current() as starting point for an XPath location path. For example:

  /a/b[k1='paul'][k2=current()/../k]/c

The link statement can be used in: leaf and leaf-list.

The following substatements can be used: 

tailf:inherit-set-hook This statement specifies that a 'tailf:set-hook' statement should survive through symlinks. If set to true a set hook gets called as soon as the value is set via a symlink but also during commit. The normal behaviour is to only call the set hook during commit time.

hmm,good one.

tested with tailf:link, that's working fine:

---

import resource-allocator {

   prefix ralloc;

}

import id-allocator {

   prefix idalloc;

}

leaf pw-id {

        description "id_allocator script will use resource-manager to reserve id in pw-id id-pool. We link to result using tailf:link extension";

        tailf:link "/ralloc:resource-pools/idalloc:id-pool[idalloc:name='pw-id']/idalloc:allocation[idalloc:id=current()/../name]/idalloc:response/idalloc:id";

        type uint32;

}

---

admin@ncs> show services l2vpn pw-id

          PW  

NAME      ID  

---------------

blabla    101 

testtest  100


admin@ncs> show resource-pools id-pool pw-id

NAME   ID        ERROR  ID  

-----------------------------

pw-id  blabla    -      101 

       testtest  -      100