01-31-2021 12:10 PM
hi,
not sure why CRUD service is very sensitive and can fail most of the time
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ifmgr_cfg
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ipv4_io_cfg
from ydk.providers import NetconfServiceProvider
from ydk.services import CRUDService
# create CRUD service
crud = CRUDService()
iface_configs = Cisco_IOS_XR_ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration()
iface_configs.interface_name = 'Loopback2'
iface_configs.description = 'Loopback'
primary = Cisco_IOS_XR_ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration.Ipv4Network.Addresses.Primary()
primary.address = '192.168.150.1'
primary.netmask = '255.255.255.0'
print(primary.address)
provider = NetconfServiceProvider(address="172.16.1.71",
port=830,
username="cisco",
password="cisco",
protocol="ssh")
res = crud.create(provider, iface_configs)
02-02-2021 09:57 AM
You erroneously use Model API. Specifically:
1. Each model must be built from top level node; in your case: Cisco_IOS_XR_ifmgr_cfg.InterfaceConfigurations().
2. Each list element after it is created must be added to the list; in your case:
all_ifcs = Cisco_IOS_XR_ifmgr_cfg.InterfaceConfigurations()
iface_configs = Cisco_IOS_XR_ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration()
iface_configs.interface_name = 'Loopback2'
...
all_ifcs.interface_configuration.add(iface_configs)
3. Keep in mind that all container and list node classes are initialized in the parent node classes automatically; in your case: list object all_ifcs.interface_configuration. These classes must be used in the model building when applicable.
Please get familiar with Developer Guide, which shows in multiple examples how to use CRUD service on various YANG model objects.
Also this repository contains tones of examples on how the CRUD operations are programmed.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide