To read the python dict below or its equivalent yaml and generate an equivalent python function call
mydict = {'RouteAdd': {'route_config': {'RouteConfig': {'table_name': 'my table', 'app_id': 'my app', 'nexthops': [{'NexthopInfo': {'nexthop_index': 2, 'nexthop_address': {'GatewayAddress': {'ethernet_mac': 'my mac', 'nexthop_ip': 'my ip'}}, 'if_name': 'my interface'}}]}}}}
Its barley (for readability):
RouteAdd: route_config: RouteConfig: app_id: "my app" nexthops: - NexthopInfo: if_name: "my interface" nexthop_address: GatewayAddress: ethernet_mac: "my mac" nexthop_ip: "my ip" nexthop_index: 2 table_name: "my table"
I would like to read the above type of yaml or python dict and call like below:
RouteAdd(route_config=Routeconfig(app_id="my app",nexthops=[NexthopInfo(if_name="my interface",nexthop_address=GatewayAddress(ethernet_mac="my mac",nexthop_ip="my ip"),nexthop_index=2)],table_name="my table"))
Basically an alternative hierarchy is an object. What I inserted is a small clip. Looking for a recursive function that does this by reading either yaml or python dict, and converting it to the format above so that I can call and execute the function. Any help is much appreciated. thanks
python object dictionary yaml
Surure
source share