采集各家云厂商的服务器和负载信息

2017-01-12 19:04:03来源:cnblogs.com作者:岁月经年人点击

项目介绍:

  • 项目代号取自蚂蚁搬家之意,主要是用来采集各家云厂商的服务器和负载信息。
  • 'amazon','aliyun','qcloud','ucloud','qingcloud'

支持python版本

python2.7python3.5

安装方式

依赖 qingcloud-sdk 、botopip2.7 install yunAnt

配置项 /etc/yun_config

[aliyun]url = https://ecs.aliyuncs.comid  = xxxxxxkey = xxxxxxslburl = https://slb.aliyuncs.com[ucloud]url = http://api.ucloud.cnid  = xxxxxxkey = xxxxxx[amazon]url = http://api.ucloud.cnid  = xxxxxxkey = xxxxxx[qcloud]url = api.qcloud.comid  = xxxxxxkey = xxxxxx[qingcloud]id = xxxxxxkey = xxxxxx

用法参考

#/usr/bin/python evn#coding=utf-8import osfrom  ant.yun.api import apifrom pprint import  pprintdef run(yun_name):    #查询云的Region    strat = api(yun_name,'get_idcs')    idcs = strat.get_result()    #查询Region中服务器信息    for idc in idcs:        print(idc)        t = api(yun_name,'get_hosts',idc)        data =  t.get_result()        #直接打印个数        pprint(len(data))        #pprint(data)    print("="*50)    # 查询Region中负载信息    for idc in idcs:        print(idc)        t = api(yun_name,'get_balancers',idc)        data =  t.get_result()        # 直接打印个数        pprint(len(data))        # pprint(data)if __name__ == '__main__':    #,'amazon','qcloud','ucloud','qingcloud'    yun_list = ['aliyun']    for yun in yun_list:        run(yun)

输出格式

区域格式:{'prefix': u'pek1', 'name': u'pek1'}服务器格式: [  {'hostname': 'codis_test1',  'inner_ip': '10.10.10.76',  'is_del': 0,  'os': 'centos65x64d',  'outer_ip': '114.114.114.114',  'purchase_date': '2016-10-11 07:14:55',  'wxsn': 'i-ipzzr9sr'},  {'hostname': 'codis_test1',  'inner_ip': '10.10.10.76',  'is_del': 0,  'os': 'centos65x64d',  'outer_ip': '114.114.114.114',  'purchase_date': '2016-10-11 07:14:55',  'wxsn': 'i-ipzzr9sr'}  ]负载格式:[ {'children': u'i-tw6ksevg,i-z76mpmku',  'hostname': 'xxx_lb',  'outer_ip': '114.114.114.114',  'wxsn': 'lb-ypysddsm'}, {'children': u'i-uqylknbc,i-1wtbms18',  'hostname': 'xxx_lb',  'outer_ip': '114.114.114.115',  'wxsn': 'lb-thvj2bhc'}  ]

Ant项目代码:

  • https://github.com/djshell/yunAnt

欢迎加入我们的行列!欢迎加入我们的行列!欢迎加入我们的行列!


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台