Skip to content

Instantly share code, notes, and snippets.

@mrmichalis
Last active December 15, 2015 11:39
Show Gist options
  • Save mrmichalis/5254107 to your computer and use it in GitHub Desktop.
Save mrmichalis/5254107 to your computer and use it in GitHub Desktop.
Cloudera Manager 4.5 compatible Update rackId for all hosts
#!/usr/bin/env python
from cm_api.api_client import ApiResource
from cm_api.endpoints.hosts import ApiHost
import json
def update_rackId(resource_root, host_id, rack_id=None):
resp = resource_root.put('%s/%s' % ("/hosts", host_id), data=json.dumps({"rackId":rack_id}))
return ApiHost.from_json_dict(resp, resource_root)
api = ApiResource('localhost', 7180, 'admin', 'admin')
for h in api.get_all_hosts():
print 'Before hostId: {0} rackId: {1}'.format(h.hostId, h.rackId)
host = update_rackId( api, h.hostId, "/default")
print 'After hostId: {0} rackId: {1} \n'.format(host.hostId, host.rackId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment