3.3. steelscript.common.connection

3.3.1. Connection Objects

class steelscript.common.connection.Connection(hostname, auth=None, port=None, verify=True, reauthenticate_handler=None)

Handle authentication and communication to remote machines.

__init__(hostname, auth=None, port=None, verify=True, reauthenticate_handler=None)

Initialize new connection and setup authentication

hostname - include protocol, e.g. “https://host.comauth - authentication object, see below port - optional port to use for connection verify - require SSL certificate validation.

Authentication: For simple basic auth, passing a tuple of (user, pass) is sufficient as a shortcut to an instance of HTTPBasicAuth. This auth method will trigger a check to ensure the protocol is using SSL to connect (though cert verification may still be turned off to avoid errors with self-signed certs).

OAuth2 will require the requests-oauthlib package and an instance of the OAuth2Session object.

netrc config files will be checked if auth is left as None. If no authentication is provided for the hostname in the netrc file, or no file exists, an error will be raised when trying to connect.

class JsonEncoder(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)

Handle more object types if first encoding doesn’t work.

Connection.download(url, path=None, overwrite=False, method='GET', extra_headers=None, params=None)

Download a file from a remote URI and save it to a local path.

url is the url of the file to download.

path is an optional path on the local filesystem to save the downloaded file. It can be:

  • a complete path
  • a directory

In the first case the file will have the specified name and extension. In the second case the filename will be retrieved by the ‘Content-Disposition’ HTTP header. If a path cannot be determined, a ValueError is raised.

overwrite if True will save the downloaded file to path no matter
if the file already exists.

method is the HTTP method used for the request.

extra_headers is a dictionary of headers to use for the request.

params is a dictionary of parameters for the request.

Connection.get_url(path)

Returns a fully qualified URL given a path.

Connection.json_request(method, path, body=None, params=None, extra_headers=None, raw_response=False)

Send a JSON request and receive JSON response.

Connection.upload(path, data, method='POST', params=None, extra_headers=None)

Upload raw data to the given URL path with the given content type.

data may be either a string or a python file object.

extra_headers is a dictionary of additional HTTP headers to send
with the request (e.g. Content-Type, Content-Disposition)
params is a dictionary of URL parameters to attach to the request.
The keys and values will be urlencoded.
method defaults to “POST”, but can be overridden if the API requires
another method such as “PUT” to be used instead.

Returns location information if resource has been created, otherwise the response body (if any).

Connection.xml_request(method, path, body=None, params=None, extra_headers=None, raw_response=False)

Send an XML request to the host.

The Content-Type and Accept headers are set to text/xml. In addition, any response will be XML-decoded as an xml.etree.ElementTree. The body is assumed to be an XML encoded text string and is inserted into the HTTP payload as-is.

SteelScript Common

This Page

License