cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
726
Views
5
Helpful
1
Replies

CRUD service issues

Mawaheb Kabbara
Cisco Employee
Cisco Employee

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)

 

1 Reply 1

yangorelik
Spotlight
Spotlight

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.

Yan Gorelik
YDK Solutions
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: