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

Failed to create route-policy with ($params) in route policy name

vipaoqun@hotmail.com
Cisco Employee
Cisco Employee

YDK Version: 0.7.2

nc-create-xr-policy-repository-cfg-20-ydk.py

 

#!/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.
#

"""
Create configuration for model Cisco-IOS-XR-policy-repository-cfg.

usage: nc-create-xr-policy-repository-cfg-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
from ydk.providers import NetconfServiceProvider
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_policy_repository_cfg \
    as xr_policy_repository_cfg
import logging


def config_routing_policy(routing_policy):
    """Add config data to routing_policy object."""
    route_policy_name = "SID($SID)"
    rpl_route_policy = """
        route-policy SID($SID)
          set label-index $SID
        end-policy
        """
    # configure RPL policy
    route_policy = routing_policy.route_policies.RoutePolicy()
    route_policy.route_policy_name = route_policy_name
    route_policy.rpl_route_policy = rpl_route_policy
    routing_policy.route_policies.route_policy.append(route_policy)


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.INFO)
        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 CRUD service
    crud = CRUDService()

    routing_policy = xr_policy_repository_cfg.RoutingPolicy()  # create object
    config_routing_policy(routing_policy)  # add object configuration

    # create configuration on NETCONF device
    crud.create(provider, routing_policy)

    exit()
# End of script

Current Behavior:
error.PNGBut the command runs successfully with my device(Cisco IOS XR Software, Version 6.5.1.25I)

route-policy.PNG

 

 

2 Replies 2

abhirame
Cisco Employee
Cisco Employee

Not sure about CLI behavior. But, YDK is based on YANG model which only allows values which fit a pattern. This info is available in YDK documentation for this class: http://ydk.cisco.com/py/docs/gen_doc_b34e5d6cd3d0eea7a1ccb30a13b2caa9ee8f64c4.html#ydk.models.cisco_ios_xr.Cisco_IOS_XR_policy_repository_cfg.RoutingPolicy.RoutePolicies.RoutePolicy

Thank you abhirame, and I have already found the definition of this pattern in Cisco-IOS-XR-policy-repository-cfg.yang and Cisco-IOS-XR-types.yang , it looks like a Yang definition error.

container.PNGdefinition.PNG

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: