http – HTTP REST Base Class

HPLeftHand HTTP Client

Author:Walter A. Boring IV
Description:This is the HTTP Client that is used to make the actual calls. It includes the authentication that knows the cookie name for LH.
class hplefthandclient.http.HTTPJSONRESTClient(api_url[, secure=True[, http_log_debug=False]])[source]

An HTTP REST Client that sends and recieves JSON data as the body of the HTTP request.

Parameters:
  • api_url (str) – The url to the LH OS REST service ie. https://<hostname or IP>:<port>/lhos
  • secure (bool) – Validate SSL cert? Default will not validate
  • http_log_debug (bool) – Turns on http log debugging. Default will not log
authenticate(user, password, optional=None)[source]

This tries to create an authenticated session with the LH OS server

Parameters:
  • user (str) – The username
  • password (str) – The password
unauthenticate()[source]

This clears the authenticated session with the LH server. It logs out.

set_debug_flag(flag)[source]

This turns on/off http request/response debugging output to console

Parameters:flag (bool) – Set to True to enable debugging output
request(*args, **kwargs)[source]

This makes an HTTP Request to the LH server. You should use get, post, delete instead.

get(url, **kwargs)[source]

Make an HTTP GET request to the server.

#example call
try {
    headers, body = http.get('/volumes')
} except exceptions.HTTPUnauthorized as ex:
    print "Not logged in"
}
Parameters:url (str) – The relative url from the LH api_url
Returns:headers - dict of HTTP Response headers
Returns:body - the body of the response. If the body was JSON,

it will be an object

post(url, **kwargs)[source]

Make an HTTP POST request to the server.

#example call
try {
    info = {'name': 'new volume name', 'sizeMiB': 300}
    headers, body = http.post('/volumes', body=info)
} except exceptions.HTTPUnauthorized as ex:
    print "Not logged in"
}
Parameters:url (str) – The relative url from the LH api_url
Returns:headers - dict of HTTP Response headers
Returns:body - the body of the response. If the body was JSON,

it will be an object

put(url, **kwargs)[source]

Make an HTTP PUT request to the server.

#example call
try {
    info = {'name': 'something'}
    headers, body = http.put('/volumes', body=info)
} except exceptions.HTTPUnauthorized as ex:
    print "Not logged in"
}
Parameters:url (str) – The relative url from the LH api_url
Returns:headers - dict of HTTP Response headers
Returns:body - the body of the response. If the body was JSON,

it will be an object

delete(url, **kwargs)[source]

Make an HTTP DELETE request to the server.

#example call
try {
    headers, body = http.delete('/volumes/%s' % name)
} except exceptions.HTTPUnauthorized as ex:
    print "Not logged in"
}
Parameters:url (str) – The relative url from the LH api_url
Returns:headers - dict of HTTP Response headers
Returns:body - the body of the response. If the body was JSON,

it will be an object

Previous topic

exceptions – HTTP Exceptions

This Page