Subject: [netmod] Issue with Choice Statement inside a List Statement

From: "Jasmeet Bhatia (jasmbhat)" <[email-masked]>
Date: Mon, 3 Feb 2014 17:59:23 +0000

I am having issues defining a "choice" scenario inside a list statement. I can't find any examples on how to do this either. The pyang validator is giving me "error: the key "id" does not reference an existing leaf". Basically I am trying to create a list where a list of "YangCar" can contain either a "YangFordCar" or a "YangHondaCar". The key "id" of the YangCar list can't seem to find the reference to the leaf id used for the yang car. How do I resolve this?

container YangPersonList {
      list YangPerson {
         key id;
         uses YangPerson;
         container YangCarList {
            list YangCar {
//The following id
key id;
choice YangCar {
  case YangFordCar {
container YangFordCar{
             uses YangFordCar;
}
          }
  case YangHondaCar {
container YangHondaCar{
     uses YangHondaCar;
}
          }
       }
            }
         }
      }
   }

   grouping YangCar {
      reference
        "com.cisco.xmp.model.test.containment.YangCar";
      leaf id {
      mandatory true;
         type int64;
      }

         // Non-containment Associations
   }
   grouping YangHondaCar {
      reference
        "com.cisco.xmp.model.test.containment.YangHondaCar";
      uses YangCar;
         // Non-containment Associations
   }
   grouping YangFordCar {
      reference
        "com.cisco.xmp.model.test.containment.YangFordCar";
      uses YangCar;
         // Non-containment Associations
   }

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 04 Feb 2014 10:10:47 +0100

Hi,

> container YangPersonList {

The key leaf has to be a child of the list node, so either remove this container (and the one in the other case) or move the definition of "id" out of the choice.

Lada

> _______________________________________________
> netmod mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod

-- 
Ladislav Lhotka, CZ.NIC Labs
PGP Key ID: E74E8C0C

---

From: Ladislav Lhotka <[email-masked]>
Date: Tue, 4 Feb 2014 10:13:50 +0100

> The key leaf has to be a child of the list node, so either remove this container (and the one in the other case) or move the definition of "id" out of the choice.

Actually only the latter works here because “id” cannot be defined twice in both cases.

Lada

---

From: "Jasmeet Bhatia (jasmbhat)" <[email-masked]>
Date: Thu, 6 Feb 2014 04:38:39 +0000

Thanks ...that helps!

Sent from Jasmeet's iPhone

> On Feb 4, 2014, at 1:14 AM, "Ladislav Lhotka" <[email-masked]> wrote:
> 
>