Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gNMI sample app for XR access lists config #308

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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-ipv4-acl-cfg.

usage: gn-get-xr-ipv4-acl-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_ipv4_acl_cfg \
as xr_ipv4_acl_cfg
import os
import logging


YDK_REPO_DIR = os.path.expanduser("~/.ydk/")

def process_ipv4_acl_and_prefix_list(ipv4_acl_and_prefix_list):
"""Process data in ipv4_acl_and_prefix_list 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()

ipv4_acl_and_prefix_list = xr_ipv4_acl_cfg.Ipv4AclAndPrefixList() # create object

# get data from gNMI device
# ipv4_acl_and_prefix_list.yfilter = YFilter.read
# ipv4_acl_and_prefix_list = gnmi.get(provider, ipv4_acl_and_prefix_list)
process_ipv4_acl_and_prefix_list(ipv4_acl_and_prefix_list) # process object data

exit()
# End of script
Original file line number Diff line number Diff line change
@@ -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-ipv4-acl-cfg.

usage: gn-get-xr-ipv4-acl-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_ipv4_acl_cfg \
as xr_ipv4_acl_cfg
import os
import logging


YDK_REPO_DIR = os.path.expanduser("~/.ydk/")

def process_ipv4_acl_and_prefix_list(ipv4_acl_and_prefix_list):
"""Process data in ipv4_acl_and_prefix_list 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()

ipv4_acl_and_prefix_list = xr_ipv4_acl_cfg.Ipv4AclAndPrefixList() # create object

# get data from gNMI device
ipv4_acl_and_prefix_list.yfilter = YFilter.read
ipv4_acl_and_prefix_list = gnmi.get(provider, ipv4_acl_and_prefix_list)
process_ipv4_acl_and_prefix_list(ipv4_acl_and_prefix_list) # process object data

exit()
# End of script
Original file line number Diff line number Diff line change
@@ -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-ipv4-acl-cfg.

usage: gn-set-xr-ipv4-acl-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_ipv4_acl_cfg \
as xr_ipv4_acl_cfg
import os
import logging


YDK_REPO_DIR = os.path.expanduser("~/.ydk/")

def config_ipv4_acl_and_prefix_list(ipv4_acl_and_prefix_list):
"""Add config data to ipv4_acl_and_prefix_list 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()

ipv4_acl_and_prefix_list = xr_ipv4_acl_cfg.Ipv4AclAndPrefixList() # create object
config_ipv4_acl_and_prefix_list(ipv4_acl_and_prefix_list) # add object configuration

# set configuration on gNMI device
# ipv4_acl_and_prefix_list.yfilter = YFilter.replace
# gnmi.set(provider, ipv4_acl_and_prefix_list)

exit()
# End of script
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Cisco-IOS-XR-ipv4-acl-cfg:ipv4-acl-and-prefix-list": {
"log-update": {
"rate": 10
}
}
}

Original file line number Diff line number Diff line change
@@ -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-ipv4-acl-cfg.

usage: gn-set-xr-ipv4-acl-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_ipv4_acl_cfg \
as xr_ipv4_acl_cfg
import os
import logging


YDK_REPO_DIR = os.path.expanduser("~/.ydk/")

def config_ipv4_acl_and_prefix_list(ipv4_acl_and_prefix_list):
"""Add config data to ipv4_acl_and_prefix_list object."""
ipv4_acl_and_prefix_list.log_update.rate = 10


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()

ipv4_acl_and_prefix_list = xr_ipv4_acl_cfg.Ipv4AclAndPrefixList() # create object
config_ipv4_acl_and_prefix_list(ipv4_acl_and_prefix_list) # add object configuration

# set configuration on gNMI device
ipv4_acl_and_prefix_list.yfilter = YFilter.replace
gnmi.set(provider, ipv4_acl_and_prefix_list)

exit()
# End of script
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
!! IOS XR Configuration version = 6.2.1
ipv4 access-list log-update rate 10
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Cisco-IOS-XR-ipv4-acl-cfg:ipv4-acl-and-prefix-list": {
"log-update": {
"threshold": 5,
"rate": 10
}
}
}

Loading