Package cm_api :: Module http_client :: Class HttpClient
[hide private]
[frames] | no frames]

Class HttpClient

source code

object --+
         |
        HttpClient

Basic HTTP client tailored for rest APIs.

Instance Methods [hide private]
 
__init__(self, base_url, exc_class=None, logger=None, ssl_context=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
set_basic_auth(self, username, password, realm)
Set up basic auth for the client
source code
 
set_headers(self, headers)
Add headers to the request
source code
 
_get_headers(self, headers) source code
 
execute(self, http_method, path, params=None, data=None, headers=None)
Submit an HTTP request.
source code
 
_make_url(self, path, params) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  base_url
  logger

Inherited from object: __class__

Method Details [hide private]

__init__(self, base_url, exc_class=None, logger=None, ssl_context=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • base_url - The base url to the API.
  • exc_class - An exception class to handle non-200 results.
  • ssl_context - A custom SSL context to use for HTTPS (Python 2.7.9+)

    Creates an HTTP(S) client to connect to the Cloudera Manager API.

Overrides: object.__init__

set_basic_auth(self, username, password, realm)

source code 

Set up basic auth for the client

Parameters:
  • username - Login name.
  • password - Login password.
  • realm - The authentication realm.
Returns:
The current object

set_headers(self, headers)

source code 

Add headers to the request

Parameters:
  • headers - A dictionary with the key value pairs for the headers
Returns:
The current object

execute(self, http_method, path, params=None, data=None, headers=None)

source code 

Submit an HTTP request.

Parameters:
  • http_method - GET, POST, PUT, DELETE
  • path - The path of the resource.
  • params - Key-value parameter data.
  • data - The data to attach to the body of the request.
  • headers - The headers to set for this request.
Returns:
The result of urllib2.urlopen()

Property Details [hide private]

base_url

Get Method:
unreachable.base_url(self)

logger

Get Method:
unreachable.logger(self)