rest.connector.libs package
Subpackages
apic
- class rest.connector.libs.apic.implementation.Implementation(*args, **kwargs)
Bases:
rest.connector.implementation.Implementation
Rest Implementation for APIC
Implementation of Rest connection to devices based on pyATS BaseConnection for APIC
- devices:
- apic1:
- connections:
- rest:
class: rest.connector.Rest ip : “2.3.4.5” credentials:
- rest:
username: admin password: cisco123
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/testbed.yaml') >>> device = testbed.devices['apic1'] >>> device.connect(alias='rest', via='rest') >>> device.rest.connected True
__init__ instantiates a single connection instance.
- connect(timeout=30, retries=3, retry_wait=10)
connect to the device via REST
- Parameters
(int) (retry_wait) –
(int) –
(int) –
- Raises
Exception –
--------- – If the connection did not go well
Note
There is no return from this method. If something goes wrong, an exception will be raised.
- devices:
- apic1:
- connections:
- rest:
class: rest.connector.Rest ip : “2.3.4.5” credentials:
- rest:
username: admin password: cisco123
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/testbed.yaml') >>> device = testbed.devices['apic1'] >>> device.connect(alias='rest', via='rest')
- disconnect()
disconnect the device for this particular alias
- isconnected()
Decorator to make sure session to device is active
There is limitation on the amount of time the session cab be active on the APIC. However, there are no way to verify if session is still active unless sending a command. So, its just faster to reconnect every time.
- get(*args, **kwargs)
GET REST Command to retrieve information from the device
- post(*args, **kwargs)
POST REST Command to configure information from the device
- delete(*args, **kwargs)
DELETE REST Command to delete information from the device
dnac
- class rest.connector.libs.dnac.implementation.Implementation(*args, **kwargs)
Bases:
rest.connector.implementation.Implementation
Rest Implementation for DNAC
Implementation of Rest connection to devices based on pyATS BaseConnection for DNAC
- devices:
- dnac1:
- connections:
- rest:
class: rest.connector.Rest ip : “2.3.4.5” port: 443 verify: False credentials:
- rest:
username: admin password: cisco123
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/dna.yaml') >>> device = testbed.devices['dnac1'] >>> device.connect(alias='rest', via='rest') >>> device.rest.connected True
__init__ instantiates a single connection instance.
- connect(timeout=30)
connect to the device via REST
- Parameters
(int) (timeout) –
- Raises
Exception –
--------- – If the connection did not go well
Note
There is no return from this method. If something goes wrong, an exception will be raised.
- disconnect()
disconnect the device for this particular alias
- get(api_url, timeout=30, **kwargs)
GET REST Command to retrieve information from the device
- Parameters
(string) (api_url) –
timeout (timeout in seconds (default: 30)) –
**kwargs (keyword arguments supported in requests.get method) –
- put(api_url, timeout=30, **kwargs)
GET REST Command to retrieve information from the device
- Parameters
(string) (api_url) –
timeout (timeout in seconds (default: 30)) –
- post(api_url, timeout=30, **kwargs)
GET REST Command to POST information to the device
- Parameters
(string) (api_url) –
timeout (timeout in seconds (default: 30)) –
lib (**kwargs are the same keyword arguments for the requests) –
iosxe
- class rest.connector.libs.iosxe.implementation.Implementation(*args, **kwargs)
Bases:
rest.connector.implementation.Implementation
Rest Implementation for IOS-XE
Implementation of Rest connection to IOS-XE devices supporting RESTCONF
- devices:
- eWLC:
os: iosxe connections:
- rest:
class: rest.connector.Rest ip: 127.0.0.1 port: “443” protocol: https credentials:
- rest:
username: admin password: admin
- custom:
- abstraction:
order: [os]
>>> from pyats.topology import loader >>> testbed = loader.load('topology.yaml') >>> device = testbed.devices['eWLC'] >>> device.connect(alias='rest', via='rest') >>> device.rest.connected True
__init__ instantiates a single connection instance.
- connect(timeout=30, default_content_type='json', verbose=False, port='443', protocol='https')
connect to the device via REST
- Parameters
(int) (timeout) –
default_content_type (Default for content type, json or xml) –
proxies (Specify the proxy to use for connection as seen below.) – {‘http’: ‘http://proxy.esl.cisco.com:80/’, ‘ftp’: ‘http://proxy.esl.cisco.com:80/’, ‘https’: ‘http://proxy.esl.cisco.com:80/’, ‘no’: ‘.cisco.com’}
- Raises
Exception –
--------- – If the connection did not go well
Note
Connecting via RESTCONF does not require contacting the device. This does nothing
- disconnect()
Does not make sense to disconnect from a device.
- get(api_url, content_type=None, headers=None, expected_status_codes=(204, 200), timeout=30, verbose=False)
GET REST Command to retrieve information from the device
- Parameters
api_url (API url string) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
- post(api_url, payload='', content_type=None, headers=None, expected_status_codes=(201, 204, 200), timeout=30, verbose=False)
POST REST Command to configure information from the device
- Parameters
api_url (API url string) –
payload (payload to sent, can be string or dict) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
- patch(api_url, payload, content_type=None, headers=None, expected_status_codes=(201, 204, 200), timeout=30, verbose=False)
PATCH REST Command to configure information from the device
- Parameters
api_url (API url string) –
payload (payload to sent, can be string or dict) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
- put(api_url, payload, content_type=None, headers=None, expected_status_codes=(201, 204, 200), timeout=30, verbose=False)
PUT REST Command to configure information from the device
- Parameters
api_url (API url string) –
payload (payload to sent, can be string or dict) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
- delete(api_url, content_type=None, headers=None, expected_status_codes=(201, 204, 200), timeout=30, verbose=False)
DELETE REST Command to configure information from the device
- Parameters
api_url (API url string) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
nd
- class rest.connector.libs.nd.implementation.Implementation(*args, **kwargs)
Bases:
rest.connector.implementation.Implementation
Rest Implementation for ND Implementation of Rest connection to devices based on pyATS BaseConnection for ND
- devices:
- nd1:
os: nd connections:
- rest:
class: rest.connector.Rest ip : “2.3.4.5”
- credentials:
- rest:
username: admin password: cisco123
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/testbed.yaml') >>> device = testbed.devices['nd1'] >>> device.connect(alias='rest', via='rest') >>> device.rest.connected True
__init__ instantiates a single connection instance.
- connect(timeout=30, retries=3, retry_wait=10)
connect to the device via REST :param timeout (int): :type timeout (int): Timeout value :param retries (int): :type retries (int): Max retries on request exception (default: 3) :param retry_wait (int): :type retry_wait (int): Seconds to wait before retry (default: 10)
- Raises
Exception –
--------- – If the connection did not go well
Note
There is no return from this method. If something goes wrong, an exception will be raised.
- devices:
- nd1:
os: nd connections:
- rest:
class: rest.connector.Rest ip : “2.3.4.5”
- credentials:
- rest:
username: admin password: cisco123
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/testbed.yaml') >>> device = testbed.devices['nd1'] >>> device.connect(alias='rest', via='rest')
- disconnect()
disconnect the device for this particular alias
- isconnected()
Decorator to make sure session to device is active
There is limitation on the amount of time the session can be active on the ND. However, there is no way to verify if session is still active unless sending a command. So, it’s just faster to reconnect every time.
- get(*args, **kwargs)
GET REST Command to retrieve information from the device
- post(*args, **kwargs)
POST REST Command to configure information from the device
- put(*args, **kwargs)
PUT REST Command to update information on the device
- delete(*args, **kwargs)
DELETE REST Command to delete information from the device
nso
- class rest.connector.libs.nso.implementation.Implementation(*args, **kwargs)
Bases:
rest.connector.implementation.Implementation
Rest Implementation for NSO
Implementation of Rest connection to Network Service Orchestrator (NSO)
- devices:
- ncs:
os: nso connections:
- rest:
class: rest.connector.Rest ip: 127.0.0.1 port: “8080” protocol: http credentials:
- rest:
username: admin password: admin
- custom:
- abstraction:
order: [os]
>>> from pyats.topology import loader >>> testbed = loader.load('ncs.yaml') >>> device = testbed.devices['ncs'] >>> device.connect(alias='rest', via='rest') >>> device.rest.connected True
__init__ instantiates a single connection instance.
- connect(timeout=30, port='8080', protocol='http', default_content_type='json', verbose=False)
connect to the device via REST
- Parameters
(int) (timeout) –
(str) (protocol) –
(str) –
default_content_type (Default for content type, json or xml) –
- Raises
Exception –
--------- – If the connection did not go well
Note
There is no return from this method. If something goes wrong, an exception will be raised.
- disconnect()
disconnect the device for this particular alias
- get(api_url, content_type=None, headers=None, expected_status_codes=(204, 200), timeout=30, verbose=False)
GET REST Command to retrieve information from the device
- Parameters
api_url (API url string) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
- post(api_url, payload='', content_type=None, headers=None, expected_status_codes=(201, 204, 200), timeout=30, verbose=False)
POST REST Command to configure information from the device
- Parameters
api_url (API url string) –
payload (payload to sent, can be string or dict) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
- patch(api_url, payload, content_type=None, headers=None, expected_status_codes=(201, 204, 200), timeout=30, verbose=False)
PATCH REST Command to configure information from the device
- Parameters
api_url (API url string) –
payload (payload to sent, can be string or dict) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
- put(api_url, payload, content_type=None, headers=None, expected_status_codes=(201, 204, 200), timeout=30, verbose=False)
PUT REST Command to configure information from the device
- Parameters
api_url (API url string) –
payload (payload to sent, can be string or dict) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
- delete(api_url, content_type=None, headers=None, expected_status_codes=(201, 204, 200), timeout=30, verbose=False)
DELETE REST Command to configure information from the device
- Parameters
api_url (API url string) –
content_type (expected content type to be returned (xml or json)) –
headers (dictionary of HTTP headers (optional)) –
expected_status_codes (list of expected result codes (integers)) –
timeout (timeout in seconds (default: 30)) –
nxos
- class rest.connector.libs.nxos.implementation.Implementation(*args, **kwargs)
Bases:
rest.connector.implementation.Implementation
Rest Implementation for NXOS
Implementation of Rest connection to devices based on pyATS BaseConnection for NXOS
- devices:
- PE1:
- connections:
- a:
protocol: telnet ip: “1.2.3.4” port: 2004
- vty:
protocol : telnet ip : “2.3.4.5”
- rest:
class: rest.connector.Rest ip : “2.3.4.5” protocol: https credentials:
- rest:
username: admin password: cisco123
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/asr22.yaml') >>> device = testbed.devices['PE1'] >>> device.connect(alias='rest', via='rest') >>> device.rest.connected True
__init__ instantiates a single connection instance.
- connect(timeout=30, port=443, protocol='https', retries=3, retry_wait=10)
connect to the device via REST
- Parameters
(int) (retry_wait) –
(int) –
(str) (protocol) –
(int) –
(int) –
- Raises
Exception –
--------- – If the connection did not go well
Note
There is no return from this method. If something goes wrong, an exception will be raised.
- devices:
- PE1:
- connections:
- a:
protocol: telnet ip: “1.2.3.4” port: 2004
- vty:
protocol : telnet ip : “2.3.4.5”
- rest:
class: rest.connector.Rest ip : “2.3.4.5” port: “443” protocol: https credentials:
- rest:
username: admin password: admin
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/asr22.yaml') >>> device = testbed.devices['asr22'] >>> device.connect(alias='rest', via='rest')
- disconnect()
disconnect the device for this particular alias
- isconnected()
Decorator to make sure session to device is active
There is limitation on the amount of time the session ca be active for on the NXOS devices. However, there are no way to verify if session is still active unless sending a command. So, its just faster to reconnect every time.
- get(*args, **kwargs)
GET REST Command to retrieve information from the device
- post(*args, **kwargs)
POST REST Command to configure information from the device
- delete(*args, **kwargs)
DELETE REST Command to delete information from the device
- patch(*args, **kwargs)
PATCH REST Command to update information on the device
- put(*args, **kwargs)
PUT REST Command to update information on the device
virl
- class rest.connector.libs.virl.implementation.Implementation(*args, **kwargs)
Bases:
rest.connector.implementation.Implementation
Rest Implementation for VIRL
Implementation of Rest connection to devices based on pyATS BaseConnection for VIRL
- devices:
- virl:
- connections:
- rest:
class: rest.connector.Rest ip : “192.168.1.1” port: “19399” protocol: http credentials:
- default:
username: admin password: cisco123
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/testbed.yaml') >>> device = testbed.devices['virl'] >>> device.connect(alias='rest', via='rest') >>> device.rest.connected True
__init__ instantiates a single connection instance.
- connect(timeout=30, port='19399', protocol='http')
connect to the device via REST
- Parameters
(int) (timeout) –
(str) (protocol) –
(str) –
- Raises
Exception –
--------- – If the connection did not go well
Note
There is no return from this method. If something goes wrong, an exception will be raised.
- devices:
- virl:
- connections:
- rest:
class: rest.connector.Rest ip : “192.168.1.1” port: “80” protocol : http credentials:
- default:
username: admin password: cisco123
>>> from pyats.topology import loader >>> testbed = loader.load('/users/xxx/xxx/testbed.yaml') >>> device = testbed.devices['virl'] >>> device.connect(alias='rest', via='rest')
- disconnect()
disconnect the device for this particular alias
- isconnected()
Decorator to make sure session to device is active
There is limitation on the amount of time the session cab be active on the VIRL. However, there are no way to verify if session is still active unless sending a command. So, its just faster to reconnect every time.
- get(*args, **kwargs)
GET REST Command to retrieve information from the device
- post(*args, **kwargs)
POST REST Command to configure information from the device
- delete(*args, **kwargs)
DELETE REST Command to delete information from the device
- put(url, timeout=30, **kwargs)
GET REST Command to retrieve information from the device
- Parameters
(string) (url) –
timeout (timeout in seconds (default: 30)) –