-
-
Save 111pontes/eb2bde9e2bfddc29bb4f2f212c58ef78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Copyright 2016 Cisco Systems, Inc. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# | |
""" | |
Read all data for model openconfig-bgp. | |
usage: oc-bgp-20-ydk.py [-h] [-v] device | |
positional arguments: | |
device NETCONF device (ssh://user:password@host:port) | |
optional arguments: | |
-h, --help show this help message and exit | |
-v, --verbose print debugging messages | |
""" | |
from argparse import ArgumentParser | |
from urlparse import urlparse | |
from ydk.services import CRUDService, CodecService | |
from ydk.providers import NetconfServiceProvider, CodecServiceProvider | |
from ydk.models.openconfig import openconfig_bgp as oc_bgp | |
import logging | |
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.DEBUG) | |
handler = logging.StreamHandler() | |
formatter = logging.Formatter(("%(asctime)s - %(name)s - " | |
"%(levelname)s - %(message)s")) | |
handler.setFormatter(formatter) | |
logger.addHandler(handler) | |
# create NETCONF provider | |
nc_provider = NetconfServiceProvider(address=device.hostname, | |
port=device.port, | |
username=device.username, | |
password=device.password, | |
protocol=device.scheme) | |
# create CRUD service | |
crud = CRUDService() | |
# create codec provider | |
cd_provider = CodecServiceProvider(type="xml") | |
# create codec service | |
codec = CodecService() | |
bgp = oc_bgp.Bgp() # create config object | |
bgp = crud.read(nc_provider, bgp, only_config=True) # read BGP config | |
print(codec.encode(cd_provider, bgp)) # process object data | |
cd_provider.close() | |
nc_provider.close() | |
exit() | |
# End of script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment