cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
158
Views
15
Helpful
2
Replies
Highlighted
Beginner

Using "Empty" type for configuration

Hi,

 

I'm trying to change admin status of an interface on a XE device (ASR920).

However running the code below does not seem to have any affect! It runs with no errors, but the interface status doesn't change.

Also if setting shutdown to Empty() brings the interface down, how can I bring it back up again?

import logging
import ydk.models.cisco_ios_xe.Cisco_IOS_XE_native as xe_native
from ydk.services.netconf_service import NetconfService, Datastore
from ydk.providers.netconf_provider import NetconfServiceProvider
from ydk.types import Empty


def enable_logging(level):
    log = logging.getLogger('ydk')
    log.setLevel(level)
    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    handler.setFormatter(formatter)
    log.addHandler(handler)


def shutdown(native):
    gigabitethernet = native.interface.GigabitEthernet()
    gigabitethernet.name = "0/0/7"
    gigabitethernet.shutdown = Empty()
    native.interface.gigabitethernet.append(gigabitethernet)


if __name__ == "__main__":
    enable_logging(logging.DEBUG)

    service = NetconfService()
    provider = NetconfServiceProvider(address="address",
                                      username="username",
                                      password="password")

    native = xe_native.Native()

    shutdown(native)

    service.edit_config(provider=provider, target=Datastore.running, config=native)

Attachment: DEBUG output from the logger 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Participant

In YANG model:

leaf shutdown {
   description
     "Shutdown the selected interface";
    type empty;
}

That means, if the leaf is set to Empty value (present), then interface is shut down; if the leaf is not present, then interface is up. This is basically repeats the CLI logic. Hence, if you want to bring interface up, you need delete leaf 'shutdown'.

import logging
import ydk.models.cisco_ios_xe.Cisco_IOS_XE_native as xe_native
from ydk.services.netconf_service import NetconfService, Datastore
from ydk.providers.netconf_provider import NetconfServiceProvider
from ydk.types import Empty


def enable_logging(level):
    log = logging.getLogger('ydk')
    log.setLevel(level)
    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    handler.setFormatter(formatter)
    log.addHandler(handler)


def down_up(provider, shutdown_value):
    gigabitethernet = native.interface.GigabitEthernet()
    gigabitethernet.name = "0/0/7"
    gigabitethernet.shutdown = shutdown_value
    native = xe_native.Native()
native.interface.gigabitethernet.append(gigabitethernet)

  service = NetconfService()
service.edit_config(provider=provider, target=Datastore.running, config=native) if __name__ == "__main__": enable_logging(logging.DEBUG) provider = NetconfServiceProvider(address="address", username="username", password="password") # Shutdown interface down_up(provider, Empty())
# Bring up interface
down_up(provider, YFilter.delete)

 

Yan Gorelik
YDK Solutions

View solution in original post

2 REPLIES 2
Highlighted
Participant

In YANG model:

leaf shutdown {
   description
     "Shutdown the selected interface";
    type empty;
}

That means, if the leaf is set to Empty value (present), then interface is shut down; if the leaf is not present, then interface is up. This is basically repeats the CLI logic. Hence, if you want to bring interface up, you need delete leaf 'shutdown'.

import logging
import ydk.models.cisco_ios_xe.Cisco_IOS_XE_native as xe_native
from ydk.services.netconf_service import NetconfService, Datastore
from ydk.providers.netconf_provider import NetconfServiceProvider
from ydk.types import Empty


def enable_logging(level):
    log = logging.getLogger('ydk')
    log.setLevel(level)
    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s")
    handler.setFormatter(formatter)
    log.addHandler(handler)


def down_up(provider, shutdown_value):
    gigabitethernet = native.interface.GigabitEthernet()
    gigabitethernet.name = "0/0/7"
    gigabitethernet.shutdown = shutdown_value
    native = xe_native.Native()
native.interface.gigabitethernet.append(gigabitethernet)

  service = NetconfService()
service.edit_config(provider=provider, target=Datastore.running, config=native) if __name__ == "__main__": enable_logging(logging.DEBUG) provider = NetconfServiceProvider(address="address", username="username", password="password") # Shutdown interface down_up(provider, Empty())
# Bring up interface
down_up(provider, YFilter.delete)

 

Yan Gorelik
YDK Solutions

View solution in original post

Highlighted

Thanks! It worked

This widget could not be displayed.