cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
515
Views
1
Helpful
3
Replies

ydk.errors.YInvalidArgumentError: Path is invalid: Cisco-IOS-XE-nativ

Hamed Fazel
Spotlight
Spotlight

Hi

I am trying just to config a loop back interface by YDK in 9300 switch . I followed samples but got errors and don't know how to follow it and fix it . this my code :

 

 

from ydk.models.Cisco_IOS_XE_native import Cisco_IOS_XE_native as xe_native
from ydk.errors import YServiceProviderError
provider = NetconfServiceProvider(address='192.168.2.2',
                                    port=830,
                                    username='###',
                                    password='###',
                                    protocol='ssh')
crud = CRUDService()

native = xe_native.Native()  # create object
loopback = native.interface.Loopback()
loopback.name = 0
loopback.description = "PRIMARY ROUTER LOOPBACK"
loopback.ip.address.primary.address = "172.16.255.1"
loopback.ip.address.primary.mask = "255.255.255.255"
native.interface.loopback.append(loopback)

# read data from NETCONF device
native = crud.create(provider, native)
 # process object data
exit()

 

 

after running the code I get bellow error:

 

 

 line 68, in <module>
    native = crud.create(provider, native)
  File "/usr/local/lib/python3.10/dist-packages/ydk/errors/error_handler.py", line 103, in helper
    return func(self, provider, entity, *args, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/ydk/services/crud_service.py", line 49, in create
    return _crud_update(provider, entity, self._crud.create)
  File "/usr/local/lib/python3.10/dist-packages/ydk/services/crud_service.py", line 69, in _crud_update
    with _handle_error():
  File "/usr/lib/python3.10/contextlib.py", line 153, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.10/dist-packages/ydk/errors/error_handler.py", line 73, in handle_runtime_error
    raise _exc
ydk.errors.YInvalidArgumentError:  Path is invalid: Cisco-IOS-XE-native:native

 

 

the library generated by ydk-gen.

 

 

3 Replies 3

I dont have a way to test this right now, try this

from ydk.models.Cisco_IOS_XE_native import Cisco_IOS_XE_native as xe_native
from ydk.errors import YServiceProviderError

provider = NetconfServiceProvider(address='192.168.2.2',
                                    port=830,
                                    username='###',
                                    password='###',
                                    protocol='ssh')
crud = CRUDService()

native = xe_native.Native()  # create object

# Define the path to the Loopback interface configuration
loopback_path = "/native/interface/Loopback[name='0']"  # Replace '0' with your desired loopback number

# Create the Loopback object with desired configuration
loopback = xe_native.Loopback()
loopback.name = "0"  # Replace with your desired loopback number
loopback.description = "PRIMARY ROUTER LOOPBACK"
loopback.ip.address.primary.address = "172.16.255.1"
loopback.ip.address.primary.mask = "255.255.255.255"

# Update the Loopback configuration at the specified path
crud.create(provider, path=loopback_path, data=loopback)

exit()

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io

thank you for your reply.

I tried that.

crud.create() just get two arguments so it generates error again.

@Hamed Fazel got it thanks, my mistake. Try this, this passes the native.interface to the crud.create() method instead of native. Please check this i am not able to run this locally right now.

from ydk.models.Cisco_IOS_XE_native import Cisco_IOS_XE_native as xe_native
from ydk.providers import NetconfServiceProvider
from ydk.services import CRUDService

# create a netconf provider
provider = NetconfServiceProvider(address='192.168.2.2',
                                    port=830,
                                    username='###',
                                    password='###',
                                    protocol='ssh')

# create a crud service
crud = CRUDService()

# create a native object
native = xe_native.Native()

# create a loopback interface
loopback = xe_native.Interface.Loopback()
loopback.name = 'Loopback0'  # note: name should be a string
loopback.description = "PRIMARY ROUTER LOOPBACK"

# create an ip address
ip_address = xe_native.Interface.Loopback.Ip.Address()
ip_address.primary.address = '172.16.255.1'
ip_address.primary.mask = '255.255.255.255'

# add the ip address to the loopback interface
loopback.ip.address.append(ip_address)

# add the loopback interface to the native object
native.interface.loopback.append(loopback)

# create the configuration on the device
crud.create(provider, native.interface)

# close the provider
provider.close()

 

Please mark this as helpful or solution accepted to help others
Connect with me https://bigevilbeard.github.io