clicon / clixon

YANG-based toolchain including NETCONF and RESTCONF interfaces and an interactive CLI
http://www.clicon.org/
Other
215 stars 72 forks source link

How can I get the transaction data's parent information?? #264

Closed jaeho9929 closed 2 years ago

jaeho9929 commented 3 years ago

Hello!

I trying to use clixon for interface setting for my base system. When I deleted an IP address for some specific interface (e.g. eth0), I could get transaction data like below.

Transaction print :
Transaction id: 0x2
Removed
=========
<ip:ipv4 xmlns:ip="urn:ietf:params:xml:ns:yang:ietf-ip">
   <ip:enabled>true</ip:enabled>
   <ip:forwarding>false</ip:forwarding>
   <ip:address>
      <ip:ip>20.40.60.0</ip:ip>
      <ip:prefix-length>24</ip:prefix-length>
   </ip:address>
</ip:ipv4>
Added
=========
Changed
=========

I couldn't set my base system only using this transaction data. Because I couldn't get information about which interface address has changed. Is there any method to get about a transaction's parent information? or, Is there any use-case or best practice for this case ??

Thank you.

olofhagsand commented 3 years ago

The validate callback has a transaction_data (td) parameter, you extract the vector of deleted objects using transaction_dvec() (see API in clixon_backend_transaction.h). Since this object is in the candidate db (eg before the delete), you can examine it in its context. The code below iterates over all deleted objects (x) and references its parent (xp):

int
main_validate(clicon_handle    h, 
          transaction_data td)
 {
    int    i;
    cxobj *x, *xp;

    for (i=0; i<transaction_dlen(td); i++){
    x = transaction_dvec(td)[i];
    xp = xml_parent(x);
    }
jaeho9929 commented 3 years ago

This gave me an idea. Thank you!, olofhagsand.