cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
443
Views
5
Helpful
11
Replies

Ydk-py CRUD service

Hello,

I would like to know if there is any possibility to send multiple entities (objects) in a single netconf create requests.  It may be not possible directly with CRUD but any we could do this with the netconf service method.

The idea is to not create multiple sessions with the router for sending different objects (e.g. BGP, ISIS etc.)

Thank

Everyone's tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Cisco Employee

Re: Ydk-py CRUD service

Yes. I just did a quick example of multiple interfaces added separately. You may call edit_config multiple times with objects from different places in the overall platform data model.

Cheers,

Einar

View solution in original post

11 REPLIES 11
Highlighted
Cisco Employee

Re: Ydk-py CRUD service

Muffadal,

Are you trying to avoid multiple transactions or do you really mean sessions? The NetconfServiceProvider session you create is already reused across multiple requests.

Cheers,

Einar

Highlighted

Re: Ydk-py CRUD service

yeah its actually multiple transactions and not sessions.

Highlighted
Cisco Employee

Re: Ydk-py CRUD service

Mufaddal,

I suggest you try something like:

from ydk.services import NetconfService

from ydk.services import Datastore

from ydk.providers import NetconfServiceProvider

from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ifmgr_cfg as ifmgr_cfg

# still need the service provider

session = NetconfServiceProvider(

    address='1.2.3.4',              # TODO insert your IP

    port=830,

    username='your_user',

    password='your_password',

    protocol='ssh')

# Initialize a NetconfService, rather than a CRUDService

nc = NetconfService()


# try creating a number of loopbacks in multiple edit-config operations

for index in xrange(100, 105):

    cr_lo = ifmgr_cfg.InterfaceConfigurations.InterfaceConfiguration()

    cr_lo.interface_virtual = Empty()

    cr_lo.interface_name = 'Loopback%d' % index

    cr_lo.description = 'Created Lo%d' % index

    cr_lo.active = 'act'

    cr_intf_configs = ifmgr_cfg.InterfaceConfigurations()

    cr_intf_configs.interface_configuration.append(cr_lo)

    nc.edit_config(

        session,

        Datastore.candidate,

        cr_intf_configs)

# now commit all the changes

nc.commit(session)

Cheers,

Einar

Highlighted

Re: Ydk-py CRUD service

Thanks Einar for the prompt response.

Can i add other objects (e.g. ISIS config) before doing the nc.commit(session)

Highlighted
Cisco Employee

Re: Ydk-py CRUD service

Yes. The commit can be performed after editing data from multiple models

Highlighted
Cisco Employee

Re: Ydk-py CRUD service

Yes. I just did a quick example of multiple interfaces added separately. You may call edit_config multiple times with objects from different places in the overall platform data model.

Cheers,

Einar

View solution in original post

Highlighted

Re: Ydk-py CRUD service

Thank you Einar and Abhirame, I will try this week.

I am just probably thinking out loud so I may not be phrasing it correctly, how does NetconfService handle transactions across multiple devices so that if a commit for a single device fails, it does not commit for the rest of the devices.

I am guessing this is something to do on top of ydk-py (possibly via return code) and not inside ydk-py.

Highlighted
Cisco Employee

Re: Ydk-py CRUD service

Correct, the YDK-Py doesn't coordinate transactions across devices. That is outside its current scope. If all the devices you are coordinating across support confirmed-commit, it is fairly simple to do a 2-phase-like sequence.

Cheers,

Einar

Highlighted

Re: Ydk-py CRUD service

Thanks Einar for the help

Highlighted
Cisco Employee

Re: Ydk-py CRUD service

Note that the example above has multiple operations (RPCs) in a single transaction using NetconfService.  With the CRUDService, each create operation is a transaction.  If you're interested in sending data for multiple models in a single operation, take a look at these issue and give them a +1:

CRUD service should handle multiple objects · Issue #121 · CiscoDevNet/ydk-gen · GitHub

NETCONF service should handle multiple objects · Issue #123 · CiscoDevNet/ydk-gen · GitHub

Highlighted

Re: Ydk-py CRUD service

Thanks Santiago, will check out them.