01-25-2019 08:24 PM
I think there is a bug while using Config/Filter in CRUD read/read_config .
I have a script(test_6.py) as belows:
#!/usr/bin/env python
from argparse import ArgumentParser
from urlparse import urlparse
from ydk.services import CRUDService
from ydk.providers import NetconfServiceProvider
from ydk.services import CodecService
from ydk.providers import CodecServiceProvider
from ydk.types import Filter, Config
import logging
import json
if __name__ == "__main__":
"""Execute main program."""
parser = ArgumentParser()
parser.add_argument("-v", "--verbose", help="print debugging messages",
action="store_true")
parser.add_argument("device",
help="NETCONF device (ssh://user:password@host:port)")
args = parser.parse_args()
device = urlparse(args.device)
# log debug messages if verbose argument specified
if args.verbose:
logger = logging.getLogger("ydk")
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
formatter = logging.Formatter(("%(asctime)s - %(name)s - "
"%(levelname)s - %(message)s"))
handler.setFormatter(formatter)
logger.addHandler(handler)
# create NETCONF provider
provider = NetconfServiceProvider(address=device.hostname,
port=device.port,
username=device.username,
password=device.password,
protocol=device.scheme)
json_provider = CodecServiceProvider(type=str("json"))
# create CRUD service
crud = CRUDService()
codec = CodecService()
entity = [
{
"Cisco-IOS-XR-ipv4-ospf-cfg:ospf": {}
},
{
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {}
}
]
entities = [codec.decode(json_provider, json.dumps(tree)) for tree in entity]
crud.read(provider, Filter(entities))
If I have both OSPF and BGP configuration in my netconf server(IOS-XRv 9000), the script works well,
IOS-XRv 9000 configuration:
Run script:
If I just have OSPF configuration in my netconf server, no BGP configuration, the script will raise a AttributeError as belows:
IOS-XRv 9000 configuration:
Run script:
02-05-2019 09:44 AM
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