Closed markhaajii closed 5 years ago
I executed below code
""" Netconf python example by yang-explorer (https://github.com/CiscoDevNet/yang-explorer)
Installing python dependencies:
> pip install lxml ncclient
Running script: (save as example.py)
> python example.py -a <address> -u <username> -p <password> --port
"""
from argparse import ArgumentParser from ncclient import manager from ncclient.operations import RPCError
if name == 'main':
parser = ArgumentParser(description='Usage:')
# script arguments
parser.add_argument('-a', '--host', type=str, required=True,
help="Device IP address or Hostname")
parser.add_argument('-u', '--username', type=str, required=True,
help="Device Username (netconf agent username)")
parser.add_argument('-p', '--password', type=str, required=True,
help="Device Password (netconf agent password)")
parser.add_argument('--port', type=int, default=830,
help="Netconf agent port")
args = parser.parse_args()
# connect to netconf agent
with manager.connect(host=args.host,
port=args.port,
username=args.username,
password=args.password,
timeout=90,
hostkey_verify=False,
device_params={'name': 'junos'}) as m:
# execute netconf operation
for c in m.server_capabilities:
print c
and then it worked:
$ python test-huawei.py -a 192.168.250.25 -u netconf -p xxxxxx., --port 830 urn:ietf:params:netconf:capability:writable-running:1.0 http://www.huawei.com/netconf/capability/execute-cli/1.0 urn:ietf:params:netconf:capability:rollback-on-error:1.0 http://www.huawei.com/netconf/capability/exchange/1.2 http://www.huawei.com/netconf/capability/discard-commit/1.0 urn:ietf:params:netconf:capability:confirmed-commit:1.0 http://www.huawei.com/netconf/capability/update/1.0 http://www.huawei.com/netconf/capability/active/1.0 urn:ietf:params:netconf:base:1.0 http://www.huawei.com/netconf/capability/sync/1.3 urn:ietf:params:netconf:capability:candidate:1.0 urn:ietf:params:netconf:capability:notification:1.0 http://www.huawei.com/netconf/capability/exchange/1.0 urn:ietf:params:netconf:capability:startup:1.0 http://www.huawei.com/netconf/capability/sync/1.2 http://www.huawei.com/netconf/capability/sync/1.1 http://www.huawei.com/netconf/capability/sync/1.0 http://www.huawei.com/netconf/capability/commit-description/1.0 http://www.huawei.com/netconf/capability/action/1.0 urn:ietf:params:netconf:capability:interleave:1.0
According to the #34 I solved the issue.
I am trying to work on Huawei devices.
During the Device profile requirements. I chose "others" in the Platform form.
When I fetch device capability, "HTTP request error" is displayed. Also, I tested the Huawei device using ncclient with simple code and Huawei's NETCONF client as well.
Below logs have appeared on yang-explorer server
INFO:explorer.views:request_handler: Received Request: (get-cap) [11/Jan/2019 17:06:05] ERROR [django.request] Internal Server Error: /explorer/netconf Traceback (most recent call last): File "/home/admin/yang-explorer/v/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response response = wrapped_callback(request, *callback_args, callback_kwargs) File "/home/admin/yang-explorer/server/explorer/views.py", line 242, in request_handler reply_xml = Adapter.run_request(request.user.username, payload) File "/home/admin/yang-explorer/server/explorer/utils/adapter.py", line 89, in run_request return Adapter.run_netconf(username, device, rpc, lock) File "/home/admin/yang-explorer/server/explorer/utils/adapter.py", line 112, in run_netconf return session.get_capability() File "/home/admin/yang-explorer/server/explorer/utils/runner.py", line 147, in get_capability self.disconnect() File "/home/admin/yang-explorer/server/explorer/utils/runner.py", line 160, in disconnect self.handle.close_session() File "/home/admin/yang-explorer/v/lib/python2.7/site-packages/ncclient/manager.py", line 216, in execute raise_mode=self._raise_mode).request(*args, *kwds) File "/home/admin/yang-explorer/v/lib/python2.7/site-packages/ncclient/operations/session.py", line 28, in request return self._request(new_ele("close-session")) File "/home/admin/yang-explorer/v/lib/python2.7/site-packages/ncclient/operations/rpc.py", line 330, in _request raise self._error SessionCloseError: Unexpected session close ERROR:django.request:Internal Server Error: /explorer/netconf Traceback (most recent call last): File "/home/admin/yang-explorer/v/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response response = wrapped_callback(request, callback_args, callback_kwargs) File "/home/admin/yang-explorer/server/explorer/views.py", line 242, in request_handler reply_xml = Adapter.run_request(request.user.username, payload) File "/home/admin/yang-explorer/server/explorer/utils/adapter.py", line 89, in run_request return Adapter.run_netconf(username, device, rpc, lock) File "/home/admin/yang-explorer/server/explorer/utils/adapter.py", line 112, in run_netconf return session.get_capability() File "/home/admin/yang-explorer/server/explorer/utils/runner.py", line 147, in get_capability self.disconnect() File "/home/admin/yang-explorer/server/explorer/utils/runner.py", line 160, in disconnect self.handle.close_session() File "/home/admin/yang-explorer/v/lib/python2.7/site-packages/ncclient/manager.py", line 216, in execute raise_mode=self._raise_mode).request(*args, **kwds) File "/home/admin/yang-explorer/v/lib/python2.7/site-packages/ncclient/operations/session.py", line 28, in request return self._request(new_ele("close-session")) File "/home/admin/yang-explorer/v/lib/python2.7/site-packages/ncclient/operations/rpc.py", line 330, in _request raise self._error SessionCloseError: Unexpected session close [11/Jan/2019 17:06:05]"GET /explorer/netconf?&mode=get%2Dcap&payload=%3Cpayload%20version%3D%223%22%20protocol%3D%22netconf%22%3E%0A%20%20%3Cmetadata%3E%0A%20%20%20%20%3Cdevice%2Dauth%20profile%3D%22%22%20platform%3D%22other%22%20host%3D%22%22%20port%3D%22%22%20user%3D%22%22%20passwd%3D%22%22%2F%3E%0A%20%20%20%20%3Cnetconf%2Dauth%20host%3D%22192%2E168%2E250%2E25%22%20port%3D%22830%22%20user%3D%22netconf%22%20passwd%3D%22123qweASD%2E%2C%22%2F%3E%0A%20%20%3C%2Fmetadata%3E%0A%20%20%3Ckeyvalue%2F%3E%0A%3C%2Fpayload%3E HTTP/1.1" 500 99463