cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
932
Views
0
Helpful
2
Replies

ERROR - Data is invalid according to the yang model when configuration openconfig bgp and ios-xr

jaime botello
Level 1
Level 1

Hi,

I'm been trying to figure out why I'm getting the following error.  

:python -u /opt/project/bgp_oc_gnmi_create.py -v -i pr04.lab01 -g 57777 -u user -p password-y /opt/project/yang/vendor/cisco/xr/651
2019-03-06 19:15:47,367 - ydk - ERROR - Data is invalid according to the yang model. Libyang error: Invalid value "198.168.1.2" in "neighbor-address" element. Path: '/openconfig-network-instance:network-instances/network-instance[name='default']/protocols/protocol[identifier='openconfig-policy-types:BGP'][name='default']/bgp/neighbors/neighbor[neighbor-address='198.168.1.2']/neighbor-address'
Traceback (most recent call last):
File "/opt/project/bgp_oc_gnmi_create.py", line 121, in <module>
crud.create(provider, bgp_ni)
File "/usr/local/lib/python2.7/dist-packages/ydk/errors/error_handler.py", line 112, in helper
return func(self, provider, entity, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/ydk/services/crud_service.py", line 49, in create
return self._crud.create(provider, entity)
File "/usr/lib/python2.7/contextlib.py", line 35, in __exit__
self.gen.throw(type, value, traceback)
File "/usr/local/lib/python2.7/dist-packages/ydk/errors/error_handler.py", line 82, in handle_runtime_error
_raise(_exc)
File "/usr/local/lib/python2.7/dist-packages/ydk/errors/error_handler.py", line 56, in _raise
raise exc
ydk.errors.YModelError: Invalid value "198.168.1.2" in "neighbor-address" element. Path: /openconfig-network-instance:network-instances/network-instance[name='default']/protocols/protocol[identifier='openconfig-policy-types:BGP'][name='default']/bgp/neighbors/neighbor[neighbor-address='198.168.1.2']/neighbor-address
2019-03-06 19:15:47,376 - ydk - INFO - Disconnected from device

 What it seems, I'm building the path incorrectly but based on the yang model, I don't know what I'm missing.  

 Wed Mar 6 21:20:27.629 UTC
Cisco IOS XR Software, Version 6.5.1
Copyright (c) 2013-2018 by Cisco Systems, Inc.

Build Information:
Built By : ahoang
Built On : Wed Aug 8 17:10:43 PDT 2018
Built Host : iox-ucs-025
Workspace : /auto/srcarchive17/prod/6.5.1/ncs5500/ws
Version : 6.5.1
Location : /opt/cisco/XR/packages/

cisco NCS-5500 () processor
System uptime is 5 weeks 6 days 20 hours 4 minutes

This is the code i'm trying to get it to work, basically the idea is to push bgp peer/config into a lab device.

#!/usr/bin/env python
#
# Copyright 2019 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.
#
import logging
import os
from argparse import ArgumentParser
from ydk.gnmi.providers import gNMIServiceProvider
from ydk.path import Repository
from ydk.models.openconfig import openconfig_network_instance as oc_ni
from ydk.services import CRUDService
from ydk.models.openconfig import openconfig_policy_types as oc_policy_types
from ydk.models.openconfig import openconfig_bgp_types as oc_bgp_types

bgp = {
'vrf': 'default',
'as': '65000',
'router_id': '104.160.139.133',
'peer-group-name': 'gNMI SET TEST',
'peer-as': '65000',
'peer-group-local-address': '192.168.1.1',
'neighbor': '198.168.1.2'
}


def config_oc_bgp_ipv4():
ni = oc_ni.NetworkInstances.NetworkInstance()
ni.name = bgp["vrf"]

protocol = ni.Protocols.Protocol()
protocol.identifier = oc_policy_types.BGP()
protocol.name = bgp["vrf"]
protocol.config.identifier = oc_policy_types.BGP()
protocol.config.name = bgp["vrf"]
protocol.bgp.global_.config.as_ = int(bgp['as'])

# Global bgp parameters
afi_safi = protocol.bgp.global_.afi_safis.AfiSafi()
afi_safi.afi_safi_name = oc_bgp_types.IPV4UNICAST()
afi_safi.config.enabled = True
protocol.bgp.global_.afi_safis.afi_safi.append(afi_safi)
#
# peer-group and address family
peer_group = protocol.bgp.peer_groups.PeerGroup()
peer_group.peer_group_name = bgp["peer-group-name"]
peer_group.config.peer_group_name = bgp["peer-group-name"]
peer_group.config.peer_as = int(bgp["peer-as"])
peer_group.transport.config.local_address = bgp["peer-group-local-address"]
afi_safi = peer_group.afi_safis.AfiSafi()
afi_safi.afi_safi_name = oc_bgp_types.IPV4UNICAST()
afi_safi.config.enabled = True
peer_group.afi_safis.afi_safi.append(afi_safi)

# bgp neighbor with peer-group
neighbor = protocol.bgp.neighbors.Neighbor()
neighbor.neighbor_address = bgp["neighbor"]
neighbor.config.neighbor_address = bgp["neighbor"] # type: str
neighbor.config.peer_group = bgp["peer-group-name"]
#
# Putting all together
protocol.bgp.peer_groups.peer_group.append(peer_group)
protocol.bgp.neighbors.neighbor.append(neighbor)
ni.protocols.protocol.append(protocol)
return ni

if __name__ == "__main__":
"""Execute main program."""
parser = ArgumentParser()
parser.add_argument("-v", "--verbose", help="print debugging messages",
action="store_true")
parser.add_argument('-i', '--grpc-ip', action='store', dest='grpc_ip',
help='Specify the IOS-XR GRPC server IP address', required=True)
parser.add_argument('-g', '--grpc-port', action='store', dest='grpc_port',
help='Specify the IOS-XR GRPC server port', required=True)
parser.add_argument('-u', '--username', action='store', dest='username',
help='Specify username to connect to gRPC server on XR', required=True)
parser.add_argument('-p', '--password', action='store', dest='password',
help='Specify password to connect to gRPC server on XR', required=True)
parser.add_argument('-y', '--yang-repo-path', action='store', dest='yang_repo_location',
help='Specify yang repo path', required=True)
parser.add_argument('-e', '--extra-verbose', action='store_true',
help='Extra Verbose logs')
args = parser.parse_args()

# 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)
if args.extra_verbose:
os.environ['GRPC_TRACE'] = 'all'
os.environ['GRPC_VERBOSITY'] = 'DEBUG'

repository = Repository(args.yang_repo_location)
provider = gNMIServiceProvider(repo=repository,
address=args.grpc_ip,
port=int(args.grpc_port),
username=args.username,
password=args.password)

crud = CRUDService()
bgp_ni = config_oc_bgp_ipv4()
crud.create(provider, bgp_ni)

thanks in advance for any pointers

2 Replies 2

jaime botello
Level 1
Level 1

Let me clarify that you don't need to generate your own OC bundle. You can just patch the YANG files under `~/.ydk/<router>/`
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: