cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1186
Views
0
Helpful
4
Replies

Can't set leaf-based attribute value using YLeaf instance

aligang1988
Level 4
Level 4

HI !

Here  http://ydk.cisco.com/py/docs/api/types.html#ydk.types.YLeaf   found information,that such class as YLeaf actually exists within ydk.
Semantics of YLeaf is to be a reflection of yang-leaf data-type within YDK.

I decided to perform some test
1. In this  piece of code value of leaf-meaning attribute is set using str-type object (set_leaf_using_str_type_object.py). This approach   is proven to be functional, simple and demonstrated in all examples I just can remember, but has one drawback. yfilter is not applicable

2.  Here  i tried to set  value of leaf-meaning attribute  using YLeaf-type object (set_leaf_using_yleaf_type_object.py). But execution failes with:

root@YDK072:~/trash# python set_leaf_using_yleaf_type_object.py

Traceback (most recent call last):

  File "set_leaf_using_yleaf_type_object.py", line 28, in <module>

    ge000.name = leaf_instance

  File "/usr/local/lib/python2.7/dist-packages/ydk/models/junos/configuration.py", line 1203298, in __setattr__

    self._perform_setattr(Configuration.Interfaces.Interface, ['name', 'apply_groups', 'apply_groups_except', 'description', 'disable', 'passive_monitor_mode', 'no_keepalives', 'traps', 'no_traps', 'interface_mib', 'no_interface_mib', 'accounting_profile', 'per_unit_scheduler', 'no_per_unit_scheduler', 'shared_scheduler', 'l2tp_maximum_session', 'schedulers', 'dce', 'vlan_tagging', 'stacked_vlan_tagging', 'flexible_vlan_tagging', 'native_vlan_id', 'speed', 'mtu', 'link_mode', 'encapsulation', 'mac', 'shared_interface', 'gratuitous_arp_reply', 'no_gratuitous_arp_reply', 'no_gratuitous_arp_request', 'no_no_gratuitous_arp_request'], name, value)

  File "/usr/local/lib/python2.7/dist-packages/ydk/types/py_types.py", line 416, in _perform_setattr

    super(Entity, self).__setattr__(name, value)

  File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__

    self.gen.throw(type, value, traceback)

  File "/usr/local/lib/python2.7/dist-packages/ydk/errors/error_handler.py", line 95, in handle_type_error

    _raise(_exc)

  File "/usr/local/lib/python2.7/dist-packages/ydk/errors/error_handler.py", line 56, in _raise

    raise exc

ydk.errors.YModelError: set(): incompatible function arguments. The following argument types are supported:

    1. (self: ydk_.types.YLeaf, value: int) -> None

    2. (self: ydk_.types.YLeaf, value: int) -> None

    3. (self: ydk_.types.YLeaf, value: int) -> None

    4. (self: ydk_.types.YLeaf, value: int) -> None

    5. (self: ydk_.types.YLeaf, value: int) -> None

    6. (self: ydk_.types.YLeaf, value: int) -> None

    7. (self: ydk_.types.YLeaf, value: float) -> None

    8. (self: ydk_.types.YLeaf, value: ydk_.types.Empty) -> None

    9. (self: ydk_.types.YLeaf, value: ydk_.types.Identity) -> None

    10. (self: ydk_.types.YLeaf, value: ydk_.types.Bits) -> None

    11. (self: ydk_.types.YLeaf, value: unicode) -> None

    12. (self: ydk_.types.YLeaf, value: ydk_.types.Enum.YLeaf) -> None

    13. (self: ydk_.types.YLeaf, value: ydk_.types.Decimal64) -> None

Q: Is it expected behavior, that  YLeaf type object  can not be used as value for leaf-meaning attribute ?
    Is there any other options to define netconf operation (replace,delete, etc) for leaf data-structure  ?

Thanks !

1 Accepted Solution

Accepted Solutions

Hi,

Any of the YFilter options can be used with leafs.

Following the above example, something like the below should work

# Set a dummy value to the leaf
cdp.timer = 5
# Assign YFilter.replace to the 'timer' leaf
cdp.timer = YFilter.replace

View solution in original post

4 Replies 4

abhirame
Cisco Employee
Cisco Employee

Please refer to the developer guide which has some example for this. You may want to use YFilter for netconf operations. YLeaf is just used internally to represent leafs and is not intended to be used by end user

http://ydk.cisco.com/py/docs/api/filters.html

http://ydk.cisco.com/py/docs/guides/crud_guide.html

Is my understanding right, that currently leaf value may be assigned with delete/remove nc:operation tag only?


In this case  leaf_like  object attributes  are assigned  with YFilter class object, as it explained here http://ydk.cisco.com/py/docs/guides/crud_guide.html#deleting-a-leaf ?

Another type of operations (such as create, merge, replace ) may not be specified  directly for leaf_like attribute, because it based on standard python datatypes (int,bool, str), which have no .yfilter attribute. Such operation tags only may be inherited from parent configuration block (list, leaf-list, container), which are based on ydk specific datatypes and have .yfilter attribute.

Hi,

Any of the YFilter options can be used with leafs.

Following the above example, something like the below should work

# Set a dummy value to the leaf
cdp.timer = 5
# Assign YFilter.replace to the 'timer' leaf
cdp.timer = YFilter.replace

Yes, it works in the way you previously explained !
Thanks !

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: