How to delete all dependent nodes if target node is deleted

Hi Team,

I have below yang model ,

 container vrf {
      description
        "VRF commands";
      // vrf definition *
      list definition {
        description
          "VRF definition mode";
        tailf:cli-mode-name "config-vrf";
        key "name";
        leaf name {
          description
            "WORD;;VRF name";
          tailf:cli-suppress-range;
          type string;
        }

 list voice-vrf {
            description
              "voice vrf id";
            tailf:cli-mode-name "cfg-media-addr-vrf";
            key vrfname;
            leaf vrfname {
              description
                "WORD;;VRF name";
              tailf:cli-suppress-range;
              must "/ios:native/ios:vrf/ios:definition[ios:name=current()] {
                error-message "VRF must be created 1st, deleted last";
              }
              type string;
            }

Now , I want the following things ,

  1. During creation of voice-vrf it should check if vrf definition exists (which is achieved through must statement)
  2. During delete of vrf definition , it should delete references of all dependent nodes also. (how to achieve this??)

Currently ,When I am trying to delete “vrf definition vrf1” , it is not allowing me as voice-vrf vrf1 exist .

ubuntu-xenial(config)# no vrf definition vrf1
ubuntu-xenial(config)# commit
Aborted: ‘voice-vrf’ (value “vrf1”): VRF must be created 1st, deleted last

You may want to replace your must statement with a leafref type - it’s
equivalent, but may perform a bit better and better describes the idea. As for
automatic deletion, you can either:

  • create a transaction hook on the list definition that deletes the voice-vrf instance that points to it;
  • create instead an action (or a CLI command) that would delete the definition and the voice-vrf instance.

The advantage of the second option is that while the operator has pretty much the same mechanisms available as with the hook, there is no “automatic reconfiguration” going behind the scenes; this may become important when your device is managed by an automatic management system.