Ambari服务依赖关系图生成脚本

1. 生成服务依赖关系

#!/usr/bin/python

import sys
import commands
import json

def genDependString(ip):
  url="curl --user admin:admin -H 'X-Requested-By:admin' 'http://{0}:8080/api/v1/stacks/HDP/versions/2.2/services?fields=StackServices/required_services&minimal_response=true' 2> /dev/null".format(ip)
  (status, output) = commands.getstatusoutput(url)
  if not status:
    items = json.loads(output).get("items")
    content = ""
    for item in items:
      service_name = item.get("StackServices").get("service_name")
      require_services = item.get("StackServices").get("required_services")
      content += '''  "ROOT" -> "{0}"\n'''.format(service_name)
      if not len(require_services):
        content += '''  "{0}" -> "NULL"\n'''.format(service_name)
      for require_service in require_services:
        content += '''  "{0}" -> "{1}"\n'''.format(service_name, require_service)
    content = "digraph G {\n" + content + "}"
    return content

if __name__ == '__main__':
  ip = sys.argv[1]
  print genDependString(ip)

2. 在线生成依赖关系图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值