pyats
pyats copied to clipboard
nso.connect does not work with rest
nso.connect(via='rest')
does not work.
topology.yaml
devices:
nso-master:
alias: nso-master
type: NSO
os: nso
tacacs:
username: admin
passwords:
tacacs: admin
connections:
defaults:
class: unicon.Unicon
via: cli
cli:
protocol: ssh
ip: nso_test
port: 1024
ssh_options: -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
con:
command: ncs_cli -C
restconf:
protocol: http
ip: nso_test
port: 80
username: admin
password: admin
netconf:
protocol: ssh
ip: nso_test
port: 1024
username: admin
password: admin
rest:
class: rest.connector.Rest
ip: nso_test
port: 80
protocol: http
credentials:
rest:
username: admin
password: admin
Error:
>>> from pyats.topology.loader import load
>>> testbed = load('topology.yaml')
>>> nso = testbed.devices['nso-master']
>>> nso.connect(alias='rest', via='rest')
Connecting to 'nso-master' with alias 'rest'
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "src/pyats/connections/manager.py", line 482, in pyats.connections.manager.ConnectionManager.connect
File "src/pyats/async_/synchronize.py", line 117, in pyats.async_.synchronize.Lockable.locked._wrapped
File "/venv/lib/python3.10/site-packages/rest/connector/libs/nso/implementation.py", line 142, in connect
raise RequestException("Connection to '{ip}:{port}' has returned the "
requests.exceptions.RequestException: Connection to '10.0.1.4:80' has returned the following code '404', instead of the expected status code '200'
Fix:
sed -i 's\{f}/api\{f}/restconf\g' /venv/lib/python3.10/site-packages/rest/connector/libs/nso/implementation.py
sed -i 's\application/vnd.yang.\application/yang-\g' /venv/lib/python3.10/site-packages/rest/connector/libs/nso/implementation.py
>>> from pyats.topology.loader import load
>>> testbed = load('topology.yaml')
>>> nso = testbed.devices['nso-master']
>>> nso.connect(alias='rest', via='rest')
Connecting to 'nso-master' with alias 'rest'
Connected successfully to 'nso-master'
<Response [200]>
>>>