rvbd.common.connection
(no docstring)
Connection
class rvbd.common.connection.Connection
Handle authentication and communication to remote machines.
Connection(hostname, auth=None, port=None, verify=True, reauthenticate_handler=None)
hostname
- include protocol, e.g. "https://host.com"
auth
- 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 [OAuth](common.html#oauth)2Session
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.
type object 'Connection' has no attribute 'request' xml_request(method, path, body=None, params=None, extra_headers=None)
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.
json_request(method, path, body=None, params=None, extra_headers=None)
Send a JSON request and receive JSON response.
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).
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.
(no docstring)
type object 'Connection' has no attribute 'del_headers'