cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1846
Views
2
Helpful
3
Replies

interface no shutdown

yitung
Cisco Employee
Cisco Employee

May I know how to "no shutdown" the interface??

I can only find the interface_configuration.shutdown=empty() to explicitly shutdown the interface but can't find a function to explicitly no shutdown the interface.

Many Thanks!

1 Accepted Solution

Accepted Solutions

einarnn
Cisco Employee
Cisco Employee

Assuming you have the Cisco_IOS_XR_ifmgr_cfg module imported as xr_ifmgr_cfg, this fragment of code shows how to do this:

from ydk.types import DELETE


if __name__ == "__main__":

    provider = NetconfServiceProvider(...)

    crud = CRUDService()

    interface_configurations = xr_ifmgr_cfg.InterfaceConfigurations()

    interface_configuration = interface_configurations.InterfaceConfiguration()

    interface_configuration.active = "act"

    interface_configuration.interface_name = "GigabitEthernet0/0/0/0"

    interface_configuration.shutdown = DELETE()

    interface_configurations.interface_configuration.append(interface_configuration)

    # delete configuration on NETCONF device

    crud.update(provider, interface_configurations)

The important points to note are:

  • The import of the special type "DELETE"
  • The use of the special type "DELETE", an instance of which is assigned to "interface_configuration.shutdown".
  • Using "crud.update" to update the field inside the object.

Cheers,

Einar

View solution in original post

3 Replies 3

einarnn
Cisco Employee
Cisco Employee

Assuming you have the Cisco_IOS_XR_ifmgr_cfg module imported as xr_ifmgr_cfg, this fragment of code shows how to do this:

from ydk.types import DELETE


if __name__ == "__main__":

    provider = NetconfServiceProvider(...)

    crud = CRUDService()

    interface_configurations = xr_ifmgr_cfg.InterfaceConfigurations()

    interface_configuration = interface_configurations.InterfaceConfiguration()

    interface_configuration.active = "act"

    interface_configuration.interface_name = "GigabitEthernet0/0/0/0"

    interface_configuration.shutdown = DELETE()

    interface_configurations.interface_configuration.append(interface_configuration)

    # delete configuration on NETCONF device

    crud.update(provider, interface_configurations)

The important points to note are:

  • The import of the special type "DELETE"
  • The use of the special type "DELETE", an instance of which is assigned to "interface_configuration.shutdown".
  • Using "crud.update" to update the field inside the object.

Cheers,

Einar

Hi Einar,

    It works when the interface is "admin shutdown". However, if the interface is up, I can't use this method.

It causes me an additional step to check the interface status first before issuing this.

   Is it possible to "no shutdown" the interface without query the interface status??

Many Thanks!!

======================================

ydk.errors.YPYServiceProviderError: Server rejected request.

        error-type: application

        error-tag: data-missing

        error-severity: error

        error-path: ns1:interface-configurations/ns1:interface-configuration[active = 'act' and interface-name = 'GigabitEthernet0/0/0/0']/ns1:shutdown

Right now, I'm afraid that no, you can't do what you want with the YDK. This is because of how we map operations through to the underlying netconf protocol. DELETE maps to operation='delete' in netconf, which requires that the data to be deleted exists, or an error is generated. Netconf can do this, with operation='remove', but this is not supported today. It would be a fairly simple enhancement if you want to try patching this. You would need to:

            elif isinstance(value, REMOVE) and not is_filter:

                xc = 'urn:ietf:params:xml:ns:netconf:base:1.0'

                member_elem.set('{' + xc + '}operation', 'remove')

Feel free to either http://cs.co/ydk-gen and try this out, or submit an issue. Hope this helps!


Cheers,


Einar