Package cm_api :: Module api_client :: Class ApiResource
[hide private]
[frames] | no frames]

Class ApiResource

source code

       object --+    
                |    
resource.Resource --+
                    |
                   ApiResource

Resource object that provides methods for managing the top-level API resources.

Instance Methods [hide private]
 
__init__(self, server_host, server_port=None, username='admin', password='admin', use_tls=False, version=10)
Creates a Resource object that provides API endpoints.
source code
 
get_cloudera_manager(self)
Returns a Cloudera Manager object.
source code
 
create_cluster(self, name, version=None, fullVersion=None)
Create a new cluster.
source code
 
delete_cluster(self, name)
Delete a cluster by name.
source code
 
get_all_clusters(self, view=None)
Retrieve a list of all clusters.
source code
 
get_cluster(self, name)
Look up a cluster by name.
source code
 
create_host(self, host_id, name, ipaddr, rack_id=None)
Create a host.
source code
 
delete_host(self, host_id)
Delete a host by id.
source code
 
get_all_hosts(self, view=None)
Get all hosts
source code
 
get_host(self, host_id)
Look up a host by id.
source code
 
get_all_users(self, view=None)
Get all users.
source code
 
get_user(self, username)
Look up a user by username.
source code
 
create_user(self, username, password, roles)
Create a user.
source code
 
delete_user(self, username)
Delete user by username.
source code
 
query_events(self, query_str=None)
Query events.
source code
 
get_event(self, event_id)
Retrieve a particular event by ID.
source code
 
echo(self, message)
Have the server echo a message back.
source code
 
echo_error(self, message)
Generate an error, but we get to set the error message.
source code
 
get_metrics(self, path, from_time, to_time, metrics, view, params=None)
Generic function for querying metrics.
source code
 
query_timeseries(self, query, from_time=None, to_time=None)
Query time series.
source code
 
get_metric_schema(self)
Get the schema for all of the metrics.
source code
 
do_batch(self, elements)
Execute a batch request with one or more elements.
source code

Inherited from resource.Resource: delete, get, invoke, post, put

Inherited from resource.Resource (private): _join_uri, _make_headers

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

Properties [hide private]
  version
Returns the API version (integer) being used.

Inherited from resource.Resource: base_url

Inherited from object: __class__

Method Details [hide private]

__init__(self, server_host, server_port=None, username='admin', password='admin', use_tls=False, version=10)
(Constructor)

source code 

Creates a Resource object that provides API endpoints.

Parameters:
  • server_host - The hostname of the Cloudera Manager server.
  • server_port - The port of the server. Defaults to 7180 (http) or 7183 (https).
  • username - Login name.
  • password - Login password.
  • use_tls - Whether to use tls (https).
  • version - API version.
Returns:
Resource object referring to the root.
Overrides: object.__init__

create_cluster(self, name, version=None, fullVersion=None)

source code 

Create a new cluster.

Parameters:
  • name - Cluster name.
  • version - Cluster major CDH version, e.g. 'CDH5'. Ignored if fullVersion is specified.
  • fullVersion - Complete CDH version, e.g. '5.1.2'. Overrides major version if both specified.
Returns:
The created cluster.

delete_cluster(self, name)

source code 

Delete a cluster by name.

Parameters:
  • name - Cluster name
Returns:
The deleted ApiCluster object

get_all_clusters(self, view=None)

source code 

Retrieve a list of all clusters.

Parameters:
  • view - View to materialize ('full' or 'summary').
Returns:
A list of ApiCluster objects.

get_cluster(self, name)

source code 

Look up a cluster by name.

Parameters:
  • name - Cluster name.
Returns:
An ApiCluster object.

create_host(self, host_id, name, ipaddr, rack_id=None)

source code 

Create a host.

Parameters:
  • host_id - The host id.
  • name - Host name
  • ipaddr - IP address
  • rack_id - Rack id. Default None.
Returns:
An ApiHost object

delete_host(self, host_id)

source code 

Delete a host by id.

Parameters:
  • host_id - Host id
Returns:
The deleted ApiHost object

get_all_hosts(self, view=None)

source code 

Get all hosts

Parameters:
  • view - View to materialize ('full' or 'summary').
Returns:
A list of ApiHost objects.

get_host(self, host_id)

source code 

Look up a host by id.

Parameters:
  • host_id - Host id
Returns:
An ApiHost object

get_all_users(self, view=None)

source code 

Get all users.

Parameters:
  • view - View to materialize ('full' or 'summary').
Returns:
A list of ApiUser objects.

get_user(self, username)

source code 

Look up a user by username.

Parameters:
  • username - Username to look up
Returns:
An ApiUser object

create_user(self, username, password, roles)

source code 

Create a user.

Parameters:
  • username - Username
  • password - Password
  • roles - List of roles for the user. This should be [] for a regular user, or ['ROLE_ADMIN'] for an admin.
Returns:
An ApiUser object

delete_user(self, username)

source code 

Delete user by username.

Parameters:
  • username - Username
Returns:
An ApiUser object

query_events(self, query_str=None)

source code 

Query events.

Parameters:
  • query_str - Query string.
Returns:
A list of ApiEvent.

get_event(self, event_id)

source code 

Retrieve a particular event by ID.

Parameters:
  • event_id - The event ID.
Returns:
An ApiEvent.

get_metrics(self, path, from_time, to_time, metrics, view, params=None)

source code 

Generic function for querying metrics.

Parameters:
  • from_time - A datetime; start of the period to query (optional).
  • to_time - A datetime; end of the period to query (default = now).
  • metrics - List of metrics to query (default = all).
  • view - View to materialize ('full' or 'summary')
  • params - Other query parameters.
Returns:
List of metrics and their readings.

query_timeseries(self, query, from_time=None, to_time=None)

source code 

Query time series.

Parameters:
  • query - Query string.
  • from_time - Start of the period to query (optional).
  • to_time - End of the period to query (default = now).
Returns:
A list of ApiTimeSeriesResponse.

get_metric_schema(self)

source code 

Get the schema for all of the metrics.

Returns:
A list of ApiMetricSchema.

do_batch(self, elements)

source code 

Execute a batch request with one or more elements. If any element fails, the entire request is rolled back and subsequent elements are ignored.

Parameters:
  • elements - A list of ApiBatchRequestElements
Returns:
2-tuple (overall success, list of ApiBatchResponseElements).

Property Details [hide private]

version

Returns the API version (integer) being used.

Get Method:
unreachable.version(self) - Returns the API version (integer) being used.