Skip to content

Instantly share code, notes, and snippets.

@111pontes
Created November 14, 2016 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 111pontes/b86dfca192e7fa55250bd5b06dd8babf to your computer and use it in GitHub Desktop.
Save 111pontes/b86dfca192e7fa55250bd5b06dd8babf to your computer and use it in GitHub Desktop.
#!/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.
#
"""
Get configuration for model Cisco-IOS-XR-ip-domain-cfg.
usage: nc-get-config-xr-ip-domain-cfg-99-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 NetconfService, Datastore
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_ip_domain_cfg \
as xr_ip_domain_cfg
import logging
def process_ip_domain(ip_domain):
"""Process config in ip_domain object."""
pass
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
provider = NetconfServiceProvider(address=device.hostname,
port=device.port,
username=device.username,
password=device.password,
protocol=device.scheme)
# create NETCONF service
netconf = NetconfService()
ip_domain = xr_ip_domain_cfg.IpDomain() # create object
# get configuration from NETCONF device
ip_domain = netconf.get_config(provider, Datastore.running, ip_domain)
process_ip_domain(ip_domain) # process object data
provider.close()
exit()
# End of script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment