pyangbind
pyangbind copied to clipboard
TypeError when trying to append openconfig ethernet interface instance to interfaces
I have converted openconfig yang models with pyangbind.
Now trying to append an ethernet interface to a list of interfaces I get this error:
>>> from oc.interfaces import interfaces
>>> from oc.interfaces.interface import interface
>>> myifaces = interfaces()
>>> this_interface = interface()
>>> this_interface.name = "TenGigabitEthernet1/1"
>>> this_interface.config.type = "ethernetCsmacd"
>>> this_interface.ethernet.switched_vlan.config.interface_mode = "TRUNK"
>>> this_interface.ethernet.switched_vlan.config.trunk_vlans.append(2)
>>> myifaces.interface.append(this_interface)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-9-45bde45282d4> in <module>()
----> 1 myifaces.interface.append(this_interface)
/opt/virtual_environments/oc/lib/python2.7/site-packages/pyangbind/lib/yangtypes.pyc in append(self, *args, **kwargs)
1070 raise AttributeError("%s object has no attribute append" % base_type)
1071 self._set()
-> 1072 super(YANGBaseClass, self).append(*args, **kwargs)
1073
1074 def pop(self, *args, **kwargs):
/opt/virtual_environments/oc/lib/python2.7/site-packages/pyangbind/lib/yangtypes.pyc in append(self, obj)
714
715 def append(self, obj):
--> 716 self.__set(_k=self._extract_key(obj), _v=obj)
717
718 def _new_item(self):
/opt/virtual_environments/oc/lib/python2.7/site-packages/pyangbind/lib/yangtypes.pyc in __set(self, *args, **kwargs)
644 extmethods=self._parent._extmethods,
645 load=True,
--> 646 extensions=extensions)
647
648 if keydict is not None:
/opt/virtual_environments/oc/lib/python2.7/site-packages/pyangbind/lib/yangtypes.pyc in YANGDynClass(*args, **kwargs)
1131 return self._cpresent
1132
-> 1133 return YANGBaseClass(*args, **kwargs)
1134
1135
/opt/virtual_environments/oc/lib/python2.7/site-packages/pyangbind/lib/yangtypes.pyc in __init__(self, *args, **kwargs)
1008 except Exception as e:
1009 raise TypeError("couldn't generate dynamic type -> %s -> %s"
-> 1010 % (type(e), e))
1011
1012 def _changed(self):
TypeError: couldn't generate dynamic type -> <type 'exceptions.ValueError'> -> {'error-string': 'ethernet must be of a type compatible with container', 'generated-type': 'YANGDynClass(base=ethernet.ethernet, is_container=\'container\', yang_name="ethernet", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, extensions=None, namespace=\'http://openconfig.net/yang/interfaces/ethernet\', defining_module=\'openconfig-if-ethernet\', yang_type=\'container\', is_config=True)', 'defined-type': 'container'}
This only happens with interfaces that have trunk_vlans attribute set. If trunk_vlans is not set, stuff seems to work fine.