01-13-2019 02:19 PM
I am trying to use "extend to add two values under "Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf.Interface()" to add two interface to the list but when I am trying to encode I can see only one value appear
I also tried append interface1 then interface2 but I got the same result
below the code I am using
import time
import datetime
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_mpls_vpn_oper
from ydk.services import CodecService
from argparse import ArgumentParser
from ydk.providers import CodecServiceProvider
#print(dir(Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs))
start = time.time()
class l3vpn_ydk_oper_object():
def __init__(self):
self.l3vpn = Cisco_IOS_XR_mpls_vpn_oper.L3vpn()
self.vrfs = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs()
def l3vpn_fun(self, vrf_name, RD, interfaces):
vrf = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf()
vrf.vrf_name = vrf_name
af = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf.Af()
af.af_name = Cisco_IOS_XR_mpls_vpn_oper.MplsVpnAfi.ipv4 #MplsVpnAfiEnum.ipv4
af.export_route_policy = 'y'
af.import_route_policy = 'x'
af.saf_name = Cisco_IOS_XR_mpls_vpn_oper.MplsVpnSafi.unicast #MplsVpnSafiEnum.unicast
vrf.af.append(af)
interface1 = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf.Interface()
interface1.interface_name = interfaces[0]
interface2 = Cisco_IOS_XR_mpls_vpn_oper.L3vpn.Vrfs.Vrf.Interface()
interface2.interface_name = interfaces[1]
vrf.interface.extend([interface2, interface1])
vrf.route_distinguisher = RD
vrf.vrf_name_xr = vrf_name
self.vrfs.vrf.append(vrf)
def return_l3vpn(self):
self.l3vpn.vrfs = self.vrfs
return self.l3vpn
if __name__ == "__main__":
"""Execute main program."""
parser = ArgumentParser()
parser.add_argument("-v", "--verbose", help="print debugging messages",
action="store_true")
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)
# create codec provider
provider = CodecServiceProvider(type="json")
# create codec service
codec = CodecService()
l3vpn_info = l3vpn_ydk_oper_object() # create object
l3vpn_list = ['vrf_red',"192.168.111.117:41",['gi1/1','gi1/2']]
l3vpn_info.l3vpn_fun(l3vpn_list[0],l3vpn_list[1],l3vpn_list[2])
# encode and print object
print(codec.encode(provider, l3vpn_info.return_l3vpn()))
end = time.time()
print("Total time: {}".format(end - start))
exit()
below the encoding output
{ "Cisco-IOS-XR-mpls-vpn-oper:l3vpn": { "vrfs": { "vrf": [ { "vrf-name": "vrf_red", "vrf-name-xr": "vrf_red", "route-distinguisher": "192.168.111.117:41", "interface": [ { "interface-name": "gi1/2" } ], "af": [ { "af-name": "ipv4", "saf-name": "unicast", "import-route-policy": "x", "export-route-policy": "y" } ] } ] } } }
Solved! Go to Solution.
01-15-2019 08:27 PM
01-14-2019 02:30 PM
It is actually not 'extend' issue, but YDK CodecService failure to encode keyless lists. Thank you for finding this bug. I have opened the corresponding GitHub issue to track its resolution.
01-15-2019 02:03 AM
Could you please help by providing a ydk code fix on github so I can use it.
01-15-2019 08:27 PM
01-17-2019 07:03 AM - edited 01-17-2019 07:08 AM
Hi ygorelik,
Many thanks for your support I tried on YDK release (0.8.1) and it is working fine
01-17-2019 08:46 AM
01-17-2019 09:32 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide