6. Core¶
The dyn.core
module contains functionality that is core to the behavior
of the rest of the library. This is where a lot of the “heavy lifting”
for sessions is done.
6.1. Singleton¶
6.2. SessionEngine¶
-
class
dyn.core.
SessionEngine
(host=None, port=443, ssl=True, history=False, proxy_host=None, proxy_port=None, proxy_user=None, proxy_pass=None)[source]¶ Base object representing a DynectSession Session
-
__init__
(host=None, port=443, ssl=True, history=False, proxy_host=None, proxy_port=None, proxy_user=None, proxy_pass=None)[source]¶ Initialize a Dynect Rest Session object and store the provided credentials
Parameters: - host – DynECT API server address
- port – Port to connect to DynECT API server
- ssl – Enable SSL
- history – A boolean flag determining whether or not you would like to store a record of all API calls made to review later
- proxy_host – A proxy host to utilize
- proxy_port – The port that the proxy is served on
- proxy_user – A username to connect to the proxy with if required
- proxy_pass – A password to connect to the proxy with if required
Returns: SessionEngine object
-
classmethod
close_session
()[source]¶ Remove the current session from the dict of instances and return it. If there was not currently a session being stored, return None. If, after removing this session, there is nothing under the current key, delete that key’s entry in the _instances dict.
-
connect
()[source]¶ Establishes a connection to the REST API server as defined by the host, port and ssl instance variables. If a proxy is specified, it is used.
-
execute
(uri, method, args=None, final=False)[source]¶ Execute a commands against the rest server
Parameters: - uri – The uri of the resource to access. /REST/ will be prepended if it is not at the beginning of the uri
- method – One of ‘DELETE’, ‘GET’, ‘POST’, or ‘PUT’
- args – Any arguments to be sent as a part of the request
- final – boolean flag representing whether or not we have already failed executing once or not
-
classmethod
get_session
()[source]¶ Return the current session for this Session type or None if there is not an active session
-
history
¶ A history of all API calls that have been made during the duration of this Session’s existence. These API call details are returned as a list of 5-tuples of the form: (timestamp, uri, method, args, status) where status will be one of ‘success’ or ‘failure’
-
name
¶ A human readable version of the name of this object
-
classmethod
new_session
(*args, **kwargs)[source]¶ Return a new session instance, regardless of whether or not there is already an existing session.
Parameters: - args – Arguments to be passed to the Singleton __call__ method
- kwargs – keyword arguments to be passed to the Singleton __call__ method
-
poll_response
(response, body)[source]¶ Looks at a response from a REST command, and while indicates that the job is incomplete, poll for response
Parameters: - response – the JSON response containing return codes
- body – the body of the HTTP response
-
send_command
(uri, method, args)[source]¶ Responsible for packaging up the API request and sending it to the server over the established connection
Parameters: - uri – The uri of the resource to interact with
- method – The HTTP method to use
- args – Encoded arguments to send to the server
-
uri_root
= '/'¶
-
wait_for_job_to_complete
(job_id, timeout=120)[source]¶ When a response comes back with a status of “incomplete” we need to wait and poll for the status of that job until it comes back with success or failure
Parameters: - job_id – the id of the job to poll for a response from
- timeout – how long (in seconds) we should wait for a valid response before giving up on this request
-