<?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 remove roles on a given host ID on cludera API v11? in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/51488#M47514</link>
    <description>&lt;P&gt;hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you explain how you solved it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;im looking for a solution to remove all roles on a host- but not remove the role itself..&amp;nbsp;&lt;/P&gt;&lt;P&gt;is that what you implement? if so- can you explain it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;-Maya&lt;/P&gt;</description>
    <pubDate>Sun, 26 Feb 2017 09:36:50 GMT</pubDate>
    <dc:creator>mayasha</dc:creator>
    <dc:date>2017-02-26T09:36:50Z</dc:date>
    <item>
      <title>How to remove roles on a given host ID on cludera API v11?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/45271#M47511</link>
      <description>&lt;P&gt;I am trying to delete a host using cloudera API through the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;API.get_cloudera_manager().decommission(hosts)&lt;BR /&gt;API.delete_hosts(hostID)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it failed with error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;File "/usr/lib/python2.6/site-packages/cm_api/api_client.py", line 160, in delete_host&lt;BR /&gt;return hosts.delete_host(self, host_id)&lt;BR /&gt;File "/usr/lib/python2.6/site-packages/cm_api/endpoints/hosts.py", line 63, in delete_host&lt;BR /&gt;return call(resource_root.delete, "%s/%s" % (HOSTS_PATH, host_id), ApiHost)&lt;BR /&gt;File "/usr/lib/python2.6/site-packages/cm_api/endpoints/types.py", line 139, in call&lt;BR /&gt;ret = method(path, params=params)&lt;BR /&gt;File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 134, in delete&lt;BR /&gt;return self.invoke("DELETE", relpath, params)&lt;BR /&gt;File "/usr/lib/python2.6/site-packages/cm_api/resource.py", line 73, in invoke&lt;BR /&gt;headers=headers)&lt;BR /&gt;File "/usr/lib/python2.6/site-packages/cm_api/http_client.py", line 174, in execute&lt;BR /&gt;raise self._exc_class(ex)&lt;BR /&gt;cm_api.api_client.ApiException: Cannot delete host with associated roles. (error 400)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know the problem was that the roles on the hosts should be deleted first. But I couldn't find a way how to do that. Does anyone have the corresponding function call?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 21:11:01 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/45271#M47511</guid>
      <dc:creator>keagles</dc:creator>
      <dc:date>2016-09-19T21:11:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove roles on a given host ID on cludera API v11?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/45272#M47512</link>
      <description>&lt;P&gt;info can be found here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://cloudera.github.io/cm_api/epydoc/5.8.0/cm_api.endpoints.services.ApiService-class.html#delete_role" target="_blank"&gt;https://cloudera.github.io/cm_api/epydoc/5.8.0/cm_api.endpoints.services.ApiService-class.html#delete_role&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Ben&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 21:21:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/45272#M47512</guid>
      <dc:creator>bgooley</dc:creator>
      <dc:date>2016-09-19T21:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove roles on a given host ID on cludera API v11?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/45273#M47513</link>
      <description>&lt;P&gt;That's it. Thanks so much bgooley!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Sep 2016 21:42:51 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/45273#M47513</guid>
      <dc:creator>keagles</dc:creator>
      <dc:date>2016-09-19T21:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove roles on a given host ID on cludera API v11?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/51488#M47514</link>
      <description>&lt;P&gt;hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you explain how you solved it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;im looking for a solution to remove all roles on a host- but not remove the role itself..&amp;nbsp;&lt;/P&gt;&lt;P&gt;is that what you implement? if so- can you explain it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks,&lt;/P&gt;&lt;P&gt;-Maya&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2017 09:36:50 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/51488#M47514</guid>
      <dc:creator>mayasha</dc:creator>
      <dc:date>2017-02-26T09:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove roles on a given host ID on cludera API v11?</title>
      <link>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/64636#M47515</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This python script helps to remove the hosts from the cluster. The following are the steps:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. stop and decommission all roles in a host&lt;BR /&gt;2. remove the roles from a host&lt;BR /&gt;identify and delete the roles one by one&lt;BR /&gt;3. remove host from a cluster&lt;BR /&gt;4. remove host from cloudera manager&lt;/P&gt;&lt;P&gt;This script removes the hosts from the cloudera managed cluster running in aws. It is intend to scale down the worker node(node manager role) and gateway role from the cluster once the demand is over.&lt;/P&gt;&lt;P&gt;You can change the script accordingly based on your environment.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;#!/bin/python
import httplib2
import os
import requests
import json
import boto3
import time
from requests.auth import HTTPBasicAuth
os.environ["AWS_ACCESS_KEY_ID"] = "ACCESS_KEY"
os.environ["AWS_SECRET_ACCESS_KEY"] = "SECRET_ACCESS_KEY"
os.environ["AWS_DEFAULT_REGION"] = "us-east-1"
region='us-east-1'
metadata = requests.get(url='http://169.254.169.254/latest/meta-data/instance-id')
instance_id = metadata.text
host = requests.get(url='http://169.254.169.254/latest/meta-data/hostname')
host_id = host.text
username='admin'
password='admin'
cluster_name='cluster001'
scm_protocol='http'
scm_host='host.compute-1.amazonaws.com'
scm_port='7180'
scm_api='v17'
&amp;nbsp;
client = boto3.client('autoscaling')
ec2 = boto3.client('autoscaling', region_name=region)
response = client.describe_auto_scaling_instances(InstanceIds=[instance_id,])
state = response['AutoScalingInstances'][0]['LifecycleState']
print "vm is in " + state 
if state == 'Terminating:Wait':
print "host decommision started"
##decommission host
service_url = scm_protocol + '://' + scm_host + ':' + scm_port + '/api/' + scm_api + '/cm/commands/hostsDecommission'

#service_url = scm_protocol + '://' + scm_host + ':' + scm_port + '/api/' + scm_api + '/cm/hostsRecommission'
#service_url = scm_protocol + '://' + scm_host + ':' + scm_port + '/api/' + scm_api + '/cm/commands/hostsStartRoles'

print service_url
headers = {'content-type': 'application/json'}
req_body = { "items":[ host_id ]}
print req_body
req = requests.post(url=service_url, auth=HTTPBasicAuth(username, password), data=json.dumps(req_body), headers=headers)
print req.text
time.sleep(120)
##delete roles in a host
api_url = scm_protocol + '://' + scm_host + ':' + scm_port + '/api/' + scm_api + '/hosts/' + host_id
req = requests.get(api_url, auth=HTTPBasicAuth(username, password))
a = json.loads(req.content)

for i in a['roleRefs']:
scm_uri='/api/' + scm_api + '/clusters/' + cluster_name + '/services/'+i['serviceName']+'/roles/'+i['roleName']
scm_url = scm_protocol + '://' + scm_host + ':' + scm_port + scm_uri
print scm_url
req = requests.delete(scm_url, auth=HTTPBasicAuth(username, password))
print req.text
time.sleep(10)

##remove host from cluster
service_url = scm_protocol + '://' + scm_host + ':' + scm_port + '/api/' + scm_api + '/clusters/' + cluster_name + '/hosts/' + host_id
print service_url
req = requests.delete(service_url, auth=HTTPBasicAuth(username, password))
time.sleep(10)

##remove host from cloudera manager
os.system("/etc/init.d/cloudera-scm-agent stop") 
service_url = scm_protocol + '://' + scm_host + ':' + scm_port + '/api/' + scm_api + '/hosts/' + host_id
print service_url
req = requests.delete(service_url, auth=HTTPBasicAuth(username, password))
print req.text
time.sleep(10)
##refresh cluster configuration
service_url = scm_protocol + '://' + scm_host + ':' + scm_port + '/api/' + scm_api + '/clusters/' + 'commands/refresh'
print service_url
req = requests.post(service_url, auth=HTTPBasicAuth(username, password))
print req.text
time.sleep(10)
##deploy client configuration
service_url = scm_protocol + '://' + scm_host + ':' + scm_port + '/api/' + scm_api + '/clusters/' + 'commands/deployClientConfig'
print service_url
req = requests.post(service_url, auth=HTTPBasicAuth(username, password))
print req.text
time.sleep(10)&lt;/PRE&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Radhakrishnan Rk&lt;/P&gt;</description>
      <pubDate>Thu, 15 Feb 2018 17:34:08 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/How-to-remove-roles-on-a-given-host-ID-on-cludera-API-v11/m-p/64636#M47515</guid>
      <dc:creator>rkkrishnaa</dc:creator>
      <dc:date>2018-02-15T17:34:08Z</dc:date>
    </item>
  </channel>
</rss>

