<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I get default value for a leaf? in Tools</title>
    <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4148903#M1588</link>
    <description>&lt;P&gt;Sure, I totally agree with you. I shared the code in case someone gets blocked because of this and needs a quick workaround until we get YDK supporting default values. I was thinking to look into YDK/pyang to propose a proper PR for this purpose, but I'm getting busy on other things so no promise.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Sep 2020 07:04:43 GMT</pubDate>
    <dc:creator>vadigreg</dc:creator>
    <dc:date>2020-09-10T07:04:43Z</dc:date>
    <item>
      <title>How do I get default value for a leaf?</title>
      <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147422#M1581</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;as per subject, I'd like to know what's the default value of a leaf as per YANG definition. In example:&lt;/P&gt;
&lt;PRE&gt;leaf my-leaf {
  type my-cfg:my-leaf-type;
  default "this-is-the-default-value";
  description "whatever";
}&lt;/PRE&gt;
&lt;P&gt;I'd like to recover&amp;nbsp;"this-is-the-default-value" string using the python APIs. I expected something like:&lt;/P&gt;
&lt;PRE&gt;My-Model.my_cfg.my_leaf.get_default_value()&lt;/PRE&gt;
&lt;P&gt;Thanks for the help.&lt;/P&gt;
&lt;P&gt;Val&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 17:15:28 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147422#M1581</guid>
      <dc:creator>vadigreg</dc:creator>
      <dc:date>2020-09-07T17:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get default value for a leaf?</title>
      <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147541#M1582</link>
      <description>&lt;P&gt;You can refer to YDK python API document.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Sep 2020 23:08:23 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147541#M1582</guid>
      <dc:creator>Jacky_hotel_california</dc:creator>
      <dc:date>2020-09-07T23:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get default value for a leaf?</title>
      <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147569#M1583</link>
      <description>&lt;P&gt;module.container.list.leaf&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 01:14:06 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147569#M1583</guid>
      <dc:creator>Jacky_hotel_california</dc:creator>
      <dc:date>2020-09-08T01:14:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get default value for a leaf?</title>
      <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147692#M1584</link>
      <description>&lt;P&gt;Hello thanks for the reply, but I can't find anything useful.&lt;/P&gt;
&lt;P&gt;In the autogenerated code I can see something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;.. attribute:: broadcast_ssid&lt;BR /&gt;&lt;BR /&gt;broadcast SSID on a WLAN&lt;BR /&gt;**type**\: bool&lt;BR /&gt;&lt;BR /&gt;**default value**\: true&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I need something to recover the default value programmatically.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 08:23:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147692#M1584</guid>
      <dc:creator>vadigreg</dc:creator>
      <dc:date>2020-09-08T08:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get default value for a leaf?</title>
      <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147871#M1585</link>
      <description>&lt;P&gt;The leaf default values are available in the underlying Libyang library, but not exposed to YDK classes and API. New development is needed to add this feature. At this point I don't see any workaround and suggest you to open enhancement request in ydk-gen GitHub.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Sep 2020 14:09:19 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147871#M1585</guid>
      <dc:creator>yangorelik</dc:creator>
      <dc:date>2020-09-08T14:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get default value for a leaf?</title>
      <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147898#M1586</link>
      <description>&lt;P&gt;Hi Yan,&lt;/P&gt;
&lt;P&gt;I'll create the request on GitHub. In the meantime I'm using the following workaround:&lt;/P&gt;
&lt;DIV&gt;
&lt;PRE&gt;def get_yang_default_value(yang_def, name):
    doc = re.sub(r'^[\s\S]*?\.\. attribute::', '.. attribute::', yang_def.__doc__)
    if doc is not None:
        for part in doc.split(".. attribute:: "):
            lines = part.splitlines()
            if len(lines) &amp;gt; 0 and lines[0].replace(" (key)", "") == name:
                for line in lines:
                    if "**default value**\: " in line:
                        matches = re.match(r'[\s\S]*?\*\*default value\*\*\\: (.*)', line)
                        if matches is not None and len(matches.groups()) == 1:
                            return matches.group(1)
                return None
        raise ValueError(name)
    raise ValueError(yang_def)
&lt;/PRE&gt;
&lt;DIV&gt;&lt;SPAN style="font-family: inherit;"&gt;this you can call like:&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;DIV&gt;
&lt;PRE&gt;default_value = get_yang_default_value(Cisco_IOS_XE_wireless_wlan_cfg.WlanCfgData.WlanCfgEntries.WlanCfgEntry, "wep_key_format")&lt;/PRE&gt;
&lt;P&gt;Extra logic is needed to also cast to the right type.&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 08 Sep 2020 15:01:54 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4147898#M1586</guid>
      <dc:creator>vadigreg</dc:creator>
      <dc:date>2020-09-08T15:01:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get default value for a leaf?</title>
      <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4148722#M1587</link>
      <description>&lt;P&gt;This approach maybe good for your specific task, but it is not acceptable from the YDK as generic. The reason - the node name can appear multiple times in different branches of the model tree. Simple examples are nodes with name "state", "config", "data" etc. There is no need to "invent wheels". We just have to employ currently available and stable libyang API and expose it to YDK API.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Sep 2020 22:37:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4148722#M1587</guid>
      <dc:creator>yangorelik</dc:creator>
      <dc:date>2020-09-09T22:37:41Z</dc:date>
    </item>
    <item>
      <title>Re: How do I get default value for a leaf?</title>
      <link>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4148903#M1588</link>
      <description>&lt;P&gt;Sure, I totally agree with you. I shared the code in case someone gets blocked because of this and needs a quick workaround until we get YDK supporting default values. I was thinking to look into YDK/pyang to propose a proper PR for this purpose, but I'm getting busy on other things so no promise.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Sep 2020 07:04:43 GMT</pubDate>
      <guid>https://community.cisco.com/t5/tools/how-do-i-get-default-value-for-a-leaf/m-p/4148903#M1588</guid>
      <dc:creator>vadigreg</dc:creator>
      <dc:date>2020-09-10T07:04:43Z</dc:date>
    </item>
  </channel>
</rss>

