demo_utils.ambari module¶
A module which houses Ambari - an instantiable Ambari client
Each call to the Ambari client uses the curl_client module. The output from the curl client is send through the static load_output
method to keep the return format similar for requests which fail.
See the load_ouput
method for some more information
Response with Error
1 2 3 | {
"message": "curl (6) Could not connect to host"
}
|
Response without error (from something like get_service
)
1 2 3 4 5 6 7 8 9 | {
"href" : "http://sandbox.hortonworks.com:8080/api/v1/clusters/Sandbox/services/YARN?fields=ServiceInfo",
"ServiceInfo" : {
"cluster_name" : "Sandbox",
"maintenance_state" : "OFF",
"service_name" : "YARN",
"state" : "INSTALLED"
}
}
|
-
class
demo_utils.ambari.
Ambari
(username='', password='', proto='http', server='127.0.0.1', port=8080, service_wait_time=60, config='')¶ Initalize the Ambari client
Parameters: - username (str, optional) – username to use for authentication (should have admin access)
- password (str, optional) – password to use for authentication (should have admin access)
- proto (str, optional) – Must be one of ‘http’ or ‘https’. Defines which protocol to use. Defaults to ‘http’
- server (str, optional) – The hostname (or IP) of the Ambari server. Defaults to 127.0.0.1.
- port (int, optional) – The port that ambari server is running on. Defaults to 8080
- service_wait_time (int, optional) – The time (in seconds) we should before we decide a service has failed changing states.
- config (dict, optional) – This is a dictionary object which should contain the any of the keys ‘username’, ‘password’, ‘proto’, ‘server’, ‘port’, or ‘service_wait_time’. Given the config here you can set any of the client’s parameters through this object. However, when using this, the config object will override any of the specific arguments passed.
Returns: N/A
-
get_cluster_info
(cluster_name, query='')¶ Get all of the information about a current cluster. Equivalent to GET /api/v1/clusters/{cluster_name}
Parameters: cluster_name (string) – The name of the cluster to query.
-
get_clusters
(query='')¶ Returns a list of clusters from the given Ambari host/port. Equivalent to GET /api/v1/clusters
Parameters: query (string, optional) – A formatted query string which is appended to the end of the request URL (advanced). Used for filtering results. Returns: An object which is created after being passed to self.load_output Return type: dict
-
get_service
(cluster_name, service_name, query='')¶ Get all of the information about a single service from the Ambari API. Equivalent to GET /api/v1/clusters/{CLUSTER}/services/{SERVICE}
Parameters: - cluster_name (str) – The name of the cluster to query
- service_name (str) – The name of the service we want to query.
- query (str, optional) – A query to filter results. Will be appended to the end of the string. i.e
field1=serviceState&field2=AnotherVal
Returns: An object converted from the JSON response of the Ambari API. Message will denote otherwise if the request was not successful
Return type: dict
-
get_services
(cluster_name, query='')¶ Get a list of services installed on a cluster. Equivalent to GET /api/v1/clusters/{cluster_name}/services
Parameters: - cluster_name (string) – The name of the cluster to query
- query (string, optional) – A query to be appended to the url for filtering results
Returns: a dictionary object built from the HTTP response and self.load_output
Return type: dict
-
static
load_output
(output)¶ Load the output from the curl_client into an object
The idea behind this function is to try and keep the same behavior on failed requests across the entire client.
Parameters: output – (str): The output from a curl_client action Returns: a dictionary object created from the JSON response of the Ambari request. If the request was unsuccessful a message attribute will be present containing the error from the curl request. Return type: dict Raises: ValueError
– This is raised when an object can’t be converted into JSON
-
password
= ''¶ class variable
-
port
= ''¶ class variable
-
proto
= ''¶ class variable
-
server
= ''¶ class variable
-
service_action
(cluster_name, service_name, action, queue=False)¶ Executes an action on a given service inside of a cluster. Action must be one of START, STOP, or RESTART
Parameters: - cluster_name (str) – the name of the cluster that the service resides in
- service_name (str) – the name of the service which we are acting on
- action (str) – A string of ‘START’, ‘STOP’, or ‘RESTART’
- queue (bool) – False when we want the function to wait to continue until the service starts. True when we simply just want to add the function to the Ambari task queue. Defaults to False. Note: Does not guarantee the service will complete successfully.
Returns: True is the action is completed successfully, False if otherwise.
Return type: bool
Raises: ValueError
– Raised when the action is not one of START/STOP/RESTART
-
set_password
(password)¶ Set the authentication password
Parameters: password (str) – Returns: N/A
-
set_port
(port)¶ Set the port to be used
Parameters: port (int) – Returns: N/A
-
set_proto
(proto)¶ Set the http protocol to be used
Parameters: proto (str) – Returns: N/A
-
set_server
(server)¶ Set the server/hostname which the client connects to
Parameters: server (str) – Returns: N/A
-
set_service_wait_time
(wait_time)¶ Set the timeout (in seconds) when waiting for a service to change states. i.e to Start/Stop/Restart a service.
Parameters: wait_time (int) – Returns: N/A
-
set_username
(user)¶ Set the authentication username
Parameters: user (str) – Returns: N/A
-
username
= ''¶ class variable