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. 在线生成依赖关系图
作者:Florian
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则作者保留追究法律责任的权利。
若本文对你有所帮助,您的 关注 和 推荐 是我分享知识的动力!
若本文对你有所帮助,您的 关注 和 推荐 是我分享知识的动力!