02-05-2023 09:15 PM - edited 02-05-2023 09:19 PM
Hi Folks,
I'm trying to delete a QOS policy from an interface so that I can replace it in a separate netconf commit. It seems to be getting the better of me. I can delete the QOS policy using Yang Suite and tried to determine what the code should look like, but no avail.
I've tried a number of levels using YFilter.delete or Empty() under the QOS options.
Here is the config i'm trying:
import os
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.types import Empty
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ifmgr_cfg as xr_intf
from ydk.filters import YFilter
import logging
log = logging.getLogger('ydk')
log.setLevel(logging.INFO)
handler = logging.StreamHandler()
log.addHandler(handler)
formatter = logging.Formatter(("%(asctime)s - %(name)s - %(levelname)s - %(message)s"))
handler.setFormatter(formatter)
log.addHandler(handler)
device_netconf = NetconfServiceProvider(address='10.30.1.11', port=830, username='test', password='cisco123', protocol='ssh')
crud_service = CRUDService()
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.output = YFilter.delete
Interface.interface_configuration.append(interface_configuration_instance)
crud_service.update(device_netconf,Interface)
Looking at the rpc xml it is sending, i'm reaching a point where it is engaging the right QOS portion, but yeah, no service-policy delete.
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0"><edit-config xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<target>
<candidate/>
</target>
<config><interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="merge">
<interface-configuration>
<active>act</active>
<interface-name>GigabitEthernet0/0/0/3.1499</interface-name>
<qos xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-qos-ma-cfg"/>
</interface-configuration>
</interface-configurations>
</config>
</edit-config>
</rpc>
Is there a better way to try and understand where and when to use Empty() or YFilter.delete and so on.
The config in bold is what i'm trying to delete.
interface GigabitEthernet0/0/0/3.1499
description Acme Labs - Brisbane - 200Mbps
service-policy input QOS-MANAGED-IN
service-policy output SHAPER-200M-OUT
vrf L3-100991-00
ipv4 address 172.31.175.1 255.255.255.252
encapsulation dot1q 1499
Regards,
Solved! Go to Solution.
02-06-2023 06:48 PM
Yan,
The article regarding crud_guide certainly helped. Thanks. I've managed to get the config working. This is the code i got down to.
To delete only service-policy output:
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.output.yfilter = YFilter.delete
Interface.interface_configuration.append(interface_configuration_instance)
crud_service.update(device_netconf, Interface)
To delete only service-policy input:
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.input.yfilter = YFilter.delete
Interface.interface_configuration.append(interface_configuration_instance)
crud_service.update(device_netconf, Interface)
and to delete both in and out:
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.yfilter = YFilter.delete
Interface.interface_configuration.append(interface_configuration_instance)
crud_service.update(device_netconf, Interface)
Appreciate the guidance.
02-05-2023 09:18 PM
according to Yang Suite, this is what i should be aiming for
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="101">
<edit-config>
<target>
<candidate/>
</target>
<config>
<interface-configurations xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ifmgr-cfg">
<interface-configuration>
<active>act</active>
<interface-name>GigabitEthernet0/0/0/3.1499</interface-name>
<qos xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-qos-ma-cfg">
<output xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0" nc:operation="delete"/>
</qos>
</interface-configuration>
</interface-configurations>
</config>
</edit-config>
</rpc>
02-06-2023 09:14 AM - edited 02-06-2023 09:25 AM
If I understand, that you want to delete all elements under list service-policy. The example of such operation is presented in the documentation here. In that example you first read the configuration and then using the read result delete all elements.
# Reaf config
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.output.service_policy.service_polict_name = YFilter.read
Interface.interface_configuration.append(interface_configuration_instance)
read_resilt = crud_service.read_config(device_netconf, Interface)
# Delete the list elements
interface_configuration_instance = read_resilt.interface_configuration[['GigabitEthernet0/0/0/3.1499', 'act']]
if len(interface_configuration_instance.qos.output.service_policy) > 0:
interface_configuration_instance.qos.output.service_policy = YFilter.delete
crud_service.read_config(device_netconf, read_result)
02-06-2023 06:30 PM
Thanks Yan,
Specific to the point, I really just want to remove the output policy, but I'm happy to remove both input and output policy if it makes it easier. There appears to be some issue with the code provided. I've managed to adjust it to work, which in principle appears close, but still not really removing the qos service-policies it seems.
When trying your config, I'm getting a key error as per below:
>>> interface_configuration_instance = read_resilt.interface_configuration[['GigabitEthernet0/0/0/3.1499', 'act']]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/dist-packages/ydk/types/py_types.py", line 795, in __getitem__
entity = self._entity_map[format(item)]
KeyError: "['GigabitEthernet0/0/0/3.1499', 'act']"
>>>
With the modified code as per below:
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.output.service_policy.service_policy_name = YFilter.read
Interface.interface_configuration.append(interface_configuration_instance)
read_result = crud_service.read_config(device_netconf, Interface)
interface_configuration_instance = read_result.interface_configuration[('act', 'GigabitEthernet0/0/0/3.1499')]
interface_configuration_instance.qos.output.service_policy.service_policy_name = YFilter.delete
crud_service.read_config(device_netconf, read_result)
crud_service.update(device_netconf, read_result)
interface_configuration_instance.qos = YFilter.delete
Interface.interface_configuration.append(interface_configuration_instance)
crud_service.read_config(device_netconf, read_result)
crud_service.update(device_netconf, Interface)
or
crud_service.update(device_netconf, read_result)
i'm getting a commit which applies config without a QOS policy, but i'm pretty sure i would need a commit that does instead.
no service-policy input
no service-policy output
I'm testing against an XRv9000 image running 6.5.1 for what it is worth.
Thanks..
02-06-2023 06:34 PM
Here is the output of the commit events and running config thereafter
RP/0/RP0/CPU0:XRV9000-LAB#RP/0/RP0/CPU0:Feb 7 02:27:37.636 UTC: netconf[1116]: %MGBL-CONFIG-6-DB_COMMIT : Configuration committed by user 'test'. Use 'show configuration commit changes 1000001689' to view the changes.
show configuration commit changes 1000001689
Tue Feb 7 02:27:41.725 UTC
Building configuration...
!! IOS XR Configuration version = 6.5.1
interface GigabitEthernet0/0/0/3.1499
description Acme Labs - Brisbane - 200Mbps
vrf L3-100991-00
ipv4 address 172.31.175.1 255.255.255.252
encapsulation dot1q 1499
!
end
RP/0/RP0/CPU0:XRV9000-LAB#sh run interface GigabitEthernet0/0/0/3.1499
Tue Feb 7 02:27:45.653 UTC
interface GigabitEthernet0/0/0/3.1499
description Acme Labs - Brisbane - 200Mbps
service-policy input QOS-MANAGED-IN
service-policy output SHAPER-200M-OUT
vrf L3-100991-00
ipv4 address 172.31.175.1 255.255.255.252
encapsulation dot1q 1499
!
02-06-2023 06:48 PM
Yan,
The article regarding crud_guide certainly helped. Thanks. I've managed to get the config working. This is the code i got down to.
To delete only service-policy output:
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.output.yfilter = YFilter.delete
Interface.interface_configuration.append(interface_configuration_instance)
crud_service.update(device_netconf, Interface)
To delete only service-policy input:
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.input.yfilter = YFilter.delete
Interface.interface_configuration.append(interface_configuration_instance)
crud_service.update(device_netconf, Interface)
and to delete both in and out:
Interface = xr_intf.InterfaceConfigurations()
interface_configuration_instance = Interface.InterfaceConfiguration()
interface_configuration_instance.interface_name = 'GigabitEthernet0/0/0/3.1499'
interface_configuration_instance.active = "act"
interface_configuration_instance.qos.yfilter = YFilter.delete
Interface.interface_configuration.append(interface_configuration_instance)
crud_service.update(device_netconf, Interface)
Appreciate the guidance.
02-07-2023 08:40 AM
I am glad you made it work. Good use case for the YDK users community!
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