<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: How to do the node maintenance turn on/off curl command in python in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203741#M71943</link>
    <description>&lt;P&gt;Thanks Aditya That worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 29 Nov 2017 14:11:49 GMT</pubDate>
    <dc:creator>meenakrajani</dc:creator>
    <dc:date>2017-11-29T14:11:49Z</dc:date>
    <item>
      <title>How to do the node maintenance turn on/off curl command in python</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203737#M71939</link>
      <description>&lt;P&gt;
How can i send the following command for putting datanode in maintenance mode in python program? &lt;/P&gt;&lt;PRE&gt;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"}}}' &lt;A href="http://ambari_host:8080/api/v1/clusters/clustername/hosts" target="_blank"&gt;http://ambari_host:8080/api/v1/clusters/clustername/hosts&lt;/A&gt;&lt;/PRE&gt;&lt;P&gt;I am trying it in this way &lt;/P&gt;&lt;PRE&gt;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)&lt;/PRE&gt;&lt;P&gt;I don't get any response back.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Meena Rajani&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 06:57:54 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203737#M71939</guid>
      <dc:creator>meenakrajani</dc:creator>
      <dc:date>2017-11-29T06:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to do the node maintenance turn on/off curl command in python</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203738#M71940</link>
      <description>&lt;P&gt; &lt;A rel="user" href="https://community.cloudera.com/users/19245/meenakrajani.html" nodeid="19245"&gt;@Meena Rajani&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;The API returns empty content on success. You can check the response code to make sure that it passed.&lt;/P&gt;&lt;PRE&gt;assert response.status_code == 200&lt;/PRE&gt;&lt;P&gt;However if you still want to have more validations you can do the below&lt;/P&gt;&lt;PRE&gt;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"
&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aditya&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 12:07:37 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203738#M71940</guid>
      <dc:creator>asirna</dc:creator>
      <dc:date>2017-11-29T12:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to do the node maintenance turn on/off curl command in python</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203739#M71941</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;Do you have any documentation which I can refer to?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 12:39:07 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203739#M71941</guid>
      <dc:creator>meenakrajani</dc:creator>
      <dc:date>2017-11-29T12:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to do the node maintenance turn on/off curl command in python</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203740#M71942</link>
      <description>&lt;P&gt;I tried this and it worked for me. Please let me know how it goes for you&lt;/P&gt;&lt;PRE&gt;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 == 200&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Aditya&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 12:51:29 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203740#M71942</guid>
      <dc:creator>asirna</dc:creator>
      <dc:date>2017-11-29T12:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to do the node maintenance turn on/off curl command in python</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203741#M71943</link>
      <description>&lt;P&gt;Thanks Aditya That worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Nov 2017 14:11:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/How-to-do-the-node-maintenance-turn-on-off-curl-command-in/m-p/203741#M71943</guid>
      <dc:creator>meenakrajani</dc:creator>
      <dc:date>2017-11-29T14:11:49Z</dc:date>
    </item>
  </channel>
</rss>

