ciscotestautomation / rest Goto Github PK
View Code? Open in Web Editor NEWpyATS | Genie REST API Connector
pyATS | Genie REST API Connector
Using the following testbed.yaml snippet:
devices:
N9K-C9508-SPINE-01:
type: switch
connections:
vty:
alias: nxapi
protocol: https
ip: 172.31.0.61
port: "443"
username: admin
password: cisco.123
class: rest.connector.Rest
defaults:
via: vty
platform: nxos
os: nxos
I get the following error:
# python
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyats.topology import loader
d('testbeds/testbed-17_1.yaml')
device = testbed.devices['N9K-C9508-SPINE-01']
device.connect(alias='nxapi',>>> testbed = loader.load('testbeds/testbed-17_1.yaml')
via='vty')
device.rest.connected
<stdin>:1: DeprecationWarning: Device N9K-C9508-SPINE-01 'tacacs.username' is deprecated in the testbed YAML. This key has been moved to device 'credentials'.
<stdin>:1: DeprecationWarning: Device N9K-C9508-SPINE-01 'passwords.linux' is deprecated in the testbed YAML. Use 'credentials' instead.
>>> device = testbed.devices['N9K-C9508-SPINE-01']
>>> device.connect(alias='nxapi', via='vty')
Traceback (most recent call last):
File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.8/http/client.py", line 1347, in getresponse
response.begin()
File "/usr/lib/python3.8/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.8/http/client.py", line 276, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/venv/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 637, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "/venv/lib/python3.8/site-packages/urllib3/util/retry.py", line 368, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/venv/lib/python3.8/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/venv/lib/python3.8/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.8/http/client.py", line 1347, in getresponse
response.begin()
File "/usr/lib/python3.8/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.8/http/client.py", line 276, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "src/pyats/connections/manager.py", line 339, 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.8/site-packages/rest/connector/libs/nxos/implementation.py", line 138, in connect
response = self.session.post(login_url, data=_data, timeout=timeout)
File "/venv/lib/python3.8/site-packages/requests/sessions.py", line 578, in post
return self.request('POST', url, data=data, json=json, **kwargs)
File "/venv/lib/python3.8/site-packages/requests/sessions.py", line 530, in request
resp = self.send(prep, **send_kwargs)
File "/venv/lib/python3.8/site-packages/requests/sessions.py", line 643, in send
r = adapter.send(request, **kwargs)
File "/venv/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
>>> device.rest.connected
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "src/pyats/topology/device.py", line 518, in pyats.topology.device.Device.__getattr__
AttributeError: 'Device' object has no attribute 'rest'
>>>
I'm suspecting verify=false may be needed for the connection?
I'm trying to connect to an APIC using PyATS and the rest.connector.Rest method, but no matter what, I get authentication failures. Here is my testbed file:
devices:
apic:
os: apic
type: apic
custom:
abstraction:
order: [os]
connections:
rest:
class: rest.connector.Rest
protocol: http
port: 443
ip: 10.10.10.10
verify: False
username: "apic:Tacacs\\my.user.account"
password: "my_password"
Output from pyATS shell:
>>> testbed = load('aci_tb.yml')
-------------------------------------------------------------------------------
>>> testbed.devices['apic'].connect(alias='rest', via='rest')
Connecting to 'apic' with alias 'rest'
<Response [401]>
{"totalCount":"1","imdata":[{"error":{"attributes":{"code":"401","text":"TACACS+ Server Authentication DENIED"}}}]}
Request to apic failed. Waiting 10 seconds before retrying
Traceback (most recent call last):
File "/.robotFramework/lib64/python3.11/site-packages/rest/connector/libs/apic/implementation.py", line 144, in connect
raise RequestException("Connection to '{ip}' has returned the "
requests.exceptions.RequestException: Connection to '10.10.10.10' has returned the following code '401', instead of the expected status code '200'
And here is the session log from the APIC:
General
Description
From-10.10.10.20-client-type-REST-Failure
Settings
Affected
uni/userext
cause
unknown
clientTag
-
code
generic
Created
2024-04-22T17:49:09.915+00:00
ID
8590532284
Action
special
Session ID
-
severity
info
System Id
1
Trigger
login, session
txId
0
User
remoteuser-my.user.account
I'm running:
genie==24.3
pyats==24.3
rest.connector==24.3
I've tried every combination of credentials and connections that I can think of and I'm still getting 401. The API works with ansible using the rest modules.
When try to connect
to a device
object using the rest.connector.Rest
class, an exception is raised.
device.connect(via="rest")
Exception (truncated)
2023-06-22T16:25:15: %AETEST-ERROR: Caught an exception while executing section [...]:
2023-06-22T16:25:15: %AETEST-ERROR: Traceback (most recent call last):
[...]
2023-06-22T16:25:15: %AETEST-ERROR: File "src/pyats/connections/manager.py", line 453, in pyats.connections.manager.ConnectionManager.connect
2023-06-22T16:25:15: %AETEST-ERROR: File "src/pyats/async_/synchronize.py", line 117, in pyats.async_.synchronize.Lockable.locked._wrapped
2023-06-22T16:25:15: %AETEST-ERROR: File "[...]/venv/lib/python3.9/site-packages/rest/connector/libs/iosxe/implementation.py", line 145, in connect
2023-06-22T16:25:15: %AETEST-ERROR: raise RequestException("Connection to '{ip}:{port}' has returned the "
2023-06-22T16:25:15: %AETEST-ERROR: requests.exceptions.RequestException: Connection to '192.0.2.1:443' has returned the following code '404', instead of the expected status code '200'
Assume the following testbed:
devices:
my_device_1:
os: iosxe
platform: cat9k
connections:
rest:
class: rest.connector.Rest
ip: 192.0.2.1
And the following code:
device = tb.devices['my_device_1']
device.connect(via="rest") # Raises the exception
This is because in file implementation.py, a GET request to https://192.0.2.1:443
is sent.
=> This is not a valid RESTCONF URL for IOS-XE devices.
When changing the line 126 from:
self.login_url = '{f}/'.format(f=self.base_url)
to
self.login_url = '{f}/'.format(f=self.base_url)
# self.login_url = self.login_url + "restconf/data/<ANY-VALID-RESTCONF-RESOURCE>"
# Example:
self.login_url = self.login_url + "restconf/data/Cisco-IOS-XE-native:native/version"
the connect
works.. This is similar to the CLI based connect and the first thing which is issued is a show version
Hi,
Would it be possible to keep updating the tags as the versions are incrementing ?
Thank you for your work !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.