Ask Your Question
0

Can I create a custom field in yang

asked 2015-06-19 14:59:44 -0700

shrenik gravatar image

updated 2015-06-22 07:59:44 -0700

I wanted to know if we could define a custom field or attribute in one of the elements leaf,list etc. For eg: Is this possible? How can we define such fields if its possible.

model Animal{

 leaf FROG{
  type String;
  species "amphibian";     // Custom field species which has a value "amphibian"
 }
}
edit retag flag offensive close merge delete

Comments

custom as in configurable??

Ashwini_Mhatre ( 2015-06-21 22:34:00 -0700 )edit

by custom I meant adding my own attribute. I have edited my example, and basically I want to parse this model and add the characteristic "amphibian" to the leaf element frog. Something of the sort of "if-feature" in yang.

shrenik ( 2015-06-22 07:53:24 -0700 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-06-22 12:24:43 -0700

updated 2015-06-22 12:25:58 -0700

I don't think it's possible without changing yangtools. One thing you could try is to create an enum:

typedef species {
  type enumeration {
    enum "amphibian" {
      value 1;
      description
        "The animal gives birth to other animals.";
    }
    enum "reptile" {
      value 2;
      description
        "The animal lay eggs.";
    }
  }
  description
  "This variable indicates the type of animal.";

}

then use that in animal:

leaf frog {
  type species;
  config false;
  mandatory true;
}

Then you would have to set the type of the animal in your code. That's one way of doing things, maybe you could also go with "choice".

edit flag offensive delete publish link more

Comments

Thanks but I don't want to add complexity by defining a typedef. Choice would restrict my usage since I need things to be of two cases, so choice isn't suitable for me.Is there way to add comments except using the "description tag"?

shrenik ( 2015-06-22 14:17:26 -0700 )edit
Login/Signup to Answer

Question Tools

Follow
1 follower

Stats

Asked: 2015-06-19 14:59:44 -0700

Seen: 165 times

Last updated: Jun 22 '15