Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created 11-28-2017 10:57 PM
How can i send the following command for putting datanode in maintenance mode in python program?
curl -u user -H "X-Requested-By:ambari" -i -X PUT -d '{"RequestInfo":{"context":"Turn Off Maintenance Mode for host","query":"Hosts/host_name.in(host1)"},"Body":{"Hosts":{"maintenance_state":"OFF"}}}' http://ambari_host:8080/api/v1/clusters/clustername/hostsI am trying it in this way
data = {"RequestInfo":{"context":"Turn OFF Maintenance Mode for host","query":"Hosts/host_name.in(host1,host2)"},"Body":{"Hosts":{"maintenance_state":"OFF"}}}
base_url = 'http://ambari_host:8080/api/v1/clusters/clustername/hosts'headers= {'Accept': 'application/json','data':data}
response = requests.put(base_url, data=json.dumps(data), auth=('username', argpaas), headers=headers)I don't get any response back.
Thanks
Meena Rajani
Created 11-29-2017 04:07 AM
The API returns empty content on success. You can check the response code to make sure that it passed.
assert response.status_code == 200
However if you still want to have more validations you can do the below
import requests
from requests.auth import HTTPBasicAuth
ambari_username = "admin"
ambari_password = "admin"
base_url = "http://ambari_host:8080/api/v1/clusters/clustername/hosts/host1"
basic_auth = HTTPBasicAuth(ambari_username, ambari_password)
headers = {'X-Requested-By' : 'ambari'}
response = requests.get(base_url, auth=basic_auth, headers=headers,verify=False)
print response.status_code
maint_state = response.json()["Hosts"]["maintenance_state"]
print maint_state
assert maint_state == "OFF"
Thanks,
Aditya
Created 11-29-2017 04:07 AM
The API returns empty content on success. You can check the response code to make sure that it passed.
assert response.status_code == 200
However if you still want to have more validations you can do the below
import requests
from requests.auth import HTTPBasicAuth
ambari_username = "admin"
ambari_password = "admin"
base_url = "http://ambari_host:8080/api/v1/clusters/clustername/hosts/host1"
basic_auth = HTTPBasicAuth(ambari_username, ambari_password)
headers = {'X-Requested-By' : 'ambari'}
response = requests.get(base_url, auth=basic_auth, headers=headers,verify=False)
print response.status_code
maint_state = response.json()["Hosts"]["maintenance_state"]
print maint_state
assert maint_state == "OFF"
Thanks,
Aditya
Created 11-29-2017 04:39 AM
Thanks Adtiya. Let me try the above one. I forgot to write in my post earlier not only I didn't receive the status but my command didn't switch the maintenance mode.
Do you have any documentation which I can refer to?
Created 11-29-2017 04:51 AM
I tried this and it worked for me. Please let me know how it goes for you
import requests
from requests.auth import HTTPBasicAuth
import json
ambari_username = "admin"
ambari_password = "admin"
base_url = "http://ambari_host:8080/api/v1/clusters/clustername/hosts"
basic_auth = HTTPBasicAuth(ambari_username, ambari_password)
data = {"RequestInfo":{"context":"Turn OFF Maintenance Mode for host","query":"Hosts/host_name.in(host1,host2)"},"Body":{"Hosts":{"maintenance_state":"ON"}}}
headers = {'X-Requested-By' : 'ambari'}
response = requests.put(base_url, data=json.dumps(data), auth=basic_auth, headers=headers,verify=False)
print response.status_code
assert response.status_code == 200Thanks,
Aditya
Created 11-29-2017 06:11 AM
Thanks Aditya That worked 🙂