04-26-2017 11:32 AM
Hi there,
Hi there,
I am trying to use Python to print out the result of a CRUD read in xml format. The following works perfectly:
from ydk.models.cisco_ios_xr import Cisco_IOS_XR_l2vpn_oper as L2VpnOper
def get_xconnect(provider, crud):
base_obj = L2VpnOper.L2Vpn.Xconnects.Xconnect()
base_data = crud.read(provider, base_obj)
When I change the value of “base_obj” to the following, a proper read request is sent but I get a timeout (possibly because the resulting object has too much information to populate in the allotted time – is this the case?):
def get_xconnect(provider, crud):
base_obj = L2VpnOper.L2VpnForwarding.Nodes.Node()
base_data = crud.read(provider, base_obj)
output:
READ operation initiated
<rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="urn:uuid:a18cbaf9-c8b9-4af9-b775-08ee13c96a62">
<get>
<filter type="subtree">
<l2vpn-forwarding xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-l2vpn-oper">
<nodes>
<node/>
</nodes>
</l2vpn-forwarding>
</filter>
</get>
</rpc>
after some time …
READ operation completed
Traceback (most recent call last):
. . .
. . .
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ncclient/operations/rpc.py", line 345, in _request
raise TimeoutExpiredError('ncclient timed out while waiting for an rpc reply.')
ncclient.operations.errors.TimeoutExpiredError: ncclient timed out while waiting for an rpc reply.
I then tried to initialize “base_obj” to a child class of L2VpnForwarding.Nodes.Node to see if the timeout would still occur, but got an INVALID_HIERARCHY_PARENT error instead.
def get_xconnect(provider, crud):
base_obj = L2VpnOper.L2VpnForwarding.Nodes.Node.L2FibBridgeDomains.L2FibBridgeDomain()
base_data = crud.read(provider, base_obj)
output:
READ operation initiated
YPYErrorCode.INVALID_HIERARCHY_PARENT
READ operation completed
Traceback (most recent call last):
File "mpls_te_demo.py", line 588, in <module>
get_xconnect_output = get_xconnect(provider, crud)
File "mpls_te_demo.py", line 466, in get_xconnect
base_data = crud.read(provider, base_obj)
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ydk/services/crud_service.py", line 150, in read
payload = self._execute_crud_operation_on_provider(provider, read_filter, 'READ', only_config)
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ydk/services/crud_service.py", line 166, in _execute_crud_operation_on_provider
only_config
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ydk/providers/netconf_provider.py", line 88, in encode
return self.sp_instance.encode(entity, operation, only_config)
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ydk/providers/_provider_plugin.py", line 114, in encode
root = self._encode_read_request(root, entity, operation, only_config)
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ydk/providers/_provider_plugin.py", line 457, in _encode_read_request
root = self._create_preamble(entity, root)
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ydk/providers/_provider_plugin.py", line 494, in _create_preamble
parent_meta_tuple_list = self._get_parent_tuple_list(entity, entity._meta_info())
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ydk/providers/_provider_plugin.py", line 590, in _get_parent_tuple_list
self._raise_parent_hierarchy_error()
File "/auto/cafy_dev/cafykit/exec/lib/python3.4/site-packages/ydk/providers/_provider_plugin.py", line 520, in _raise_parent_hierarchy_error
raise YPYServiceProviderError(error_code=YPYErrorCode.INVALID_HIERARCHY_PARENT)
ydk.errors.YPYServiceProviderError: Parent is not set. Parent Hierarchy cannot be determined
This has happened with every child class of L2VpnForwarding.Nodes.Node I have tried. I copied straight from the YDK documentation, so I know the class names are correct.
How to deal with this INVALID_HIERARCHY_PARENT error? What’s wrong?
04-26-2017 02:23 PM
You can specify your timeout (default 60s) for the NETCONF service provider. For instance:
provider = NetconfServiceProvider(address=10.0.0.1,
port=830,
username='admin',
password='admin',
protocol='ssh',
timeout=120)
04-26-2017 03:11 PM
Thank you Santiago, this is very helpful for the timeout issue. Any idea about the INVALID_HIERARCHY_PARENT error discussed below it?
04-26-2017 07:47 PM
ydk.errors.YPYServiceProviderError: Parent is not set. Parent Hierarchy cannot be determined
It seems like it complains about missing key value for L2VpnOper.L2VpnForwarding.Nodes.Node. Maybe an issue related to #399.
A related discussion could be found here.
And as suggested in the issue and the discussion, you might need to instantiate L2VpnForwarding.Nodes.Node and append base_obj to the corresponding attribute for this object.
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: