From 26f325a29a3c598a9358535576e7f86cf7eb5009 Mon Sep 17 00:00:00 2001 From: Dasom Eom Date: Mon, 5 Aug 2019 16:12:25 -0700 Subject: [PATCH] Add gNMI sample app for XR MPLS IP TTL configuration Includes two boilerplate apps and two custom apps to configure global MPLS attributes (MPLS LSD) for XR data model using gNMI/gNMI: gn-set-xr-mpls-lsd-cfg-10-ydk.py - set boilerplate gn-set-xr-mpls-lsd-cfg-20-ydk.py - disable for all packets gn-get-xr-mpls-lsd-cfg-10-ydk.py - get boilerplate gn-get-xr-mpls-lsd-cfg-10-ydk.py - get global MPLS attributes --- .../gn-get-xr-mpls-lsd-cfg-10-ydk.py | 89 ++++++++++++++++++ .../gn-get-xr-mpls-lsd-cfg-20-ydk.py | 89 ++++++++++++++++++ .../gn-set-xr-mpls-lsd-cfg-10-ydk.py | 89 ++++++++++++++++++ .../gn-set-xr-mpls-lsd-cfg-20-ydk.json | 6 ++ .../gn-set-xr-mpls-lsd-cfg-20-ydk.py | 93 +++++++++++++++++++ .../gn-set-xr-mpls-lsd-cfg-20-ydk.txt | 2 + 6 files changed, 368 insertions(+) create mode 100755 samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-get-xr-mpls-lsd-cfg-10-ydk.py create mode 100755 samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-get-xr-mpls-lsd-cfg-20-ydk.py create mode 100755 samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-10-ydk.py create mode 100644 samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.json create mode 100755 samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.py create mode 100644 samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.txt diff --git a/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-get-xr-mpls-lsd-cfg-10-ydk.py b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-get-xr-mpls-lsd-cfg-10-ydk.py new file mode 100755 index 0000000..907923b --- /dev/null +++ b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-get-xr-mpls-lsd-cfg-10-ydk.py @@ -0,0 +1,89 @@ +#!/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 data for model Cisco-IOS-XR-mpls-lsd-cfg. + +usage: gn-get-xr-mpls-lsd-cfg-10-ydk.py [-h] [-v] device + +positional arguments: + device gNMI device (http://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.path import Repository +from ydk.filters import YFilter +from ydk.gnmi.services import gNMIService +from ydk.gnmi.providers import gNMIServiceProvider +from ydk.models.cisco_ios_xr import Cisco_IOS_XR_mpls_lsd_cfg \ + as xr_mpls_lsd_cfg +import os +import logging + + +YDK_REPO_DIR = os.path.expanduser("~/.ydk/") + +def process_mpls_lsd(mpls_lsd): + """Process data in mpls_lsd 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="gNMI device (http://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 gNMI provider + repository = Repository(YDK_REPO_DIR+device.hostname) + provider = gNMIServiceProvider(repo=repository, + address=device.hostname, + port=device.port, + username=device.username, + password=device.password) + # create gNMI service + gnmi = gNMIService() + + mpls_lsd = xr_mpls_lsd_cfg.MplsLsd() # create object + + # get data from gNMI device + # mpls_lsd.yfilter = YFilter.read + # mpls_lsd = gnmi.get(provider, mpls_lsd) + process_mpls_lsd(mpls_lsd) # process object data + + exit() +# End of script diff --git a/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-get-xr-mpls-lsd-cfg-20-ydk.py b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-get-xr-mpls-lsd-cfg-20-ydk.py new file mode 100755 index 0000000..db83403 --- /dev/null +++ b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-get-xr-mpls-lsd-cfg-20-ydk.py @@ -0,0 +1,89 @@ +#!/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 data for model Cisco-IOS-XR-mpls-lsd-cfg. + +usage: gn-get-xr-mpls-lsd-cfg-20-ydk.py [-h] [-v] device + +positional arguments: + device gNMI device (http://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.path import Repository +from ydk.filters import YFilter +from ydk.gnmi.services import gNMIService +from ydk.gnmi.providers import gNMIServiceProvider +from ydk.models.cisco_ios_xr import Cisco_IOS_XR_mpls_lsd_cfg \ + as xr_mpls_lsd_cfg +import os +import logging + + +YDK_REPO_DIR = os.path.expanduser("~/.ydk/") + +def process_mpls_lsd(mpls_lsd): + """Process data in mpls_lsd 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="gNMI device (http://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 gNMI provider + repository = Repository(YDK_REPO_DIR+device.hostname) + provider = gNMIServiceProvider(repo=repository, + address=device.hostname, + port=device.port, + username=device.username, + password=device.password) + # create gNMI service + gnmi = gNMIService() + + mpls_lsd = xr_mpls_lsd_cfg.MplsLsd() # create object + + # get data from gNMI device + mpls_lsd.yfilter = YFilter.read + mpls_lsd = gnmi.get(provider, mpls_lsd) + process_mpls_lsd(mpls_lsd) # process object data + + exit() +# End of script diff --git a/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-10-ydk.py b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-10-ydk.py new file mode 100755 index 0000000..16d9d25 --- /dev/null +++ b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-10-ydk.py @@ -0,0 +1,89 @@ +#!/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. +# + +""" +Set configuration for model Cisco-IOS-XR-mpls-lsd-cfg. + +usage: gn-set-xr-mpls-lsd-cfg-10-ydk.py [-h] [-v] device + +positional arguments: + device gNMI device (http://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.path import Repository +from ydk.filters import YFilter +from ydk.gnmi.services import gNMIService +from ydk.gnmi.providers import gNMIServiceProvider +from ydk.models.cisco_ios_xr import Cisco_IOS_XR_mpls_lsd_cfg \ + as xr_mpls_lsd_cfg +import os +import logging + + +YDK_REPO_DIR = os.path.expanduser("~/.ydk/") + +def config_mpls_lsd(mpls_lsd): + """Add config data to mpls_lsd 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="gNMI device (http://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 gNMI provider + repository = Repository(YDK_REPO_DIR+device.hostname) + provider = gNMIServiceProvider(repo=repository, + address=device.hostname, + port=device.port, + username=device.username, + password=device.password) + # create gNMI service + gnmi = gNMIService() + + mpls_lsd = xr_mpls_lsd_cfg.MplsLsd() # create object + config_mpls_lsd(mpls_lsd) # add object configuration + + # set configuration on gNMI device + # mpls_lsd.yfilter = YFilter.replace + # gnmi.set(provider, mpls_lsd) + + exit() +# End of script diff --git a/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.json b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.json new file mode 100644 index 0000000..a394b49 --- /dev/null +++ b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.json @@ -0,0 +1,6 @@ +{ + "Cisco-IOS-XR-mpls-lsd-cfg:mpls-lsd": { + "mpls-ip-ttl-propagate-disable": "all" + } +} + diff --git a/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.py b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.py new file mode 100755 index 0000000..09e869f --- /dev/null +++ b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.py @@ -0,0 +1,93 @@ +#!/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. +# + +""" +Set configuration for model Cisco-IOS-XR-mpls-lsd-cfg. + +usage: gn-set-xr-mpls-lsd-cfg-20-ydk.py [-h] [-v] device + +positional arguments: + device gNMI device (http://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.path import Repository +from ydk.filters import YFilter +from ydk.gnmi.services import gNMIService +from ydk.gnmi.providers import gNMIServiceProvider +from ydk.models.cisco_ios_xr import Cisco_IOS_XR_mpls_lsd_cfg \ + as xr_mpls_lsd_cfg +import os +import logging + + +YDK_REPO_DIR = os.path.expanduser("~/.ydk/") + +def config_mpls_lsd(mpls_lsd): + """Add config data to mpls_lsd object.""" + # To disable MPLS IP TTL propagate: + # "all" disables for all MPLS packets. + # forward disables for only forwarded MPLS packets. + # local disables for only locally generated MPLS packets. + mpls_lsd.mpls_ip_ttl_propagate_disable = xr_mpls_lsd_cfg.MplsIpTtlPropagateDisable.all + + +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="gNMI device (http://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 gNMI provider + repository = Repository(YDK_REPO_DIR+device.hostname) + provider = gNMIServiceProvider(repo=repository, + address=device.hostname, + port=device.port, + username=device.username, + password=device.password) + # create gNMI service + gnmi = gNMIService() + + mpls_lsd = xr_mpls_lsd_cfg.MplsLsd() # create object + config_mpls_lsd(mpls_lsd) # add object configuration + + # set configuration on gNMI device + mpls_lsd.yfilter = YFilter.replace + gnmi.set(provider, mpls_lsd) + + exit() +# End of script diff --git a/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.txt b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.txt new file mode 100644 index 0000000..69a3fa5 --- /dev/null +++ b/samples/basic/gnmi/models/cisco-ios-xr/Cisco-IOS-XR-mpls-lsd-cfg/gn-set-xr-mpls-lsd-cfg-20-ydk.txt @@ -0,0 +1,2 @@ +mpls ip-ttl-propagate disable +end