This module defines the Service class and associated authentication classes. The Service class is not instantiated directly, but is instead subclassed to implement handlers for particular REST namespaces.
For example, the NetShark is based on Service using the “netshark” namespace, and will provide the necessary methods to interface with the REST resources available within that namespace.
If a device or appliance implements multiple namespaces, each namespace will be exposed by a separate child class. The SteelCentral NetExpress product implements both the “netprofiler” and “netshark” namespaces. These will be exposed via NetShark and NetProfiler classes respectively, both based on the the Service class. A script that interacts with both namespaces must instantiate two separate objects.
This class is the main interface to interact with a device via REST and provides the following functionality:
A connection is established as soon as the an instance of this object is created. Requests can be made via the Service.conn property.
Establish a connection to the named host.
host is the name or IP address of the device to connect to
Authenticate with device using the defined authentication method. This sets up the appropriate authentication headers to access restricted resources.
auth must be an instance of either UserAuth or OAuth.
Check that the server supports the given API versions.
End the authenticated session with the device.
Ping the service. On failure, this raises an exception
Retry the authentication method
Most REST resource calls require authentication. Devices will support one or more authentication methods. The following methods may be supported:
When a Service object is created, the user may either pass an authentication object to the constructor, or later passed to the Service.authenticate() method.
This class is used for both Basic and Cookie based authentication which rely on username and password.
Define an authentication method using username and password. By default this will be used for both Basic as well as Cookie based authentication methods (whichever is supported by the target). Authentication can be restricted by setting the method to either Auth.BASIC or Auth.COOKIE.