通过cm_api退役主机(优雅地)

时间:2015-10-07 18:46:17

标签: python api automation cloudera cloudera-manager

我正在尝试使用cm_api从cloudera管理器(优雅地)中取消主机。 我试过跟随但是正在删除角色并突然停止在其上运行的YARN容器

#!/usr/bin/env python2.6
my_cluster = "cluster"
cloudera_manager = "1.2.3.4"
cloudera_username = "admin"
cloudera_password = "admin"

import time
from datetime import datetime, timedelta
from cm_api.api_client import ApiResource
from cm_api.endpoints.cms import ClouderaManager
from cm_api.endpoints.clusters import ApiCluster
from cm_api.endpoints.hosts import get_host, delete_host

api = ApiResource(cloudera_manager, username=cloudera_username, password=cloudera_password)
cl = ApiCluster(api, my_cluster)
hosts = []
roles = []
ha = get_host(api, "$INSTANCE_ID")

for r in ha.roleRefs:
    roles.append((r.serviceName, r.roleName))

for srv_name, role_name in roles:
    service = cl.get_service(srv_name)
    service.delete_role(role_name)

有谁知道我们如何使用cm_api在cloudera管理器中停用主机?

1 个答案:

答案 0 :(得分:1)

这是因为您只删除了代码中的角色。要停用主机,您需要使用 ClouderaManager 类的 hosts_decommission 功能。

在此链接中搜索ClouderaManager类和hosts_decommission函数http://cloudera.github.io/cm_api/epydoc/5.4.0/index.html

您将使用以下内容:

cm = ClouderaManager(api)
# Get all the hosts to decommission and save it in hosts array
hosts = ['host1','host2','host3']

for h in hosts:
    cm.hosts_decommission(h)