我正在考虑收集服务器数据,并在那些服务器中预安装Python 2.6.现在我想知道是否有Python库对应Ruby的"facter",而不是Python的"绑定"因为facter.
我用Google搜索但却找不到任何东西.有没有人对此有任何想法?
我看不出为什么你不会只使用facter本身的任何理由.输出格式很容易从python脚本中获取.
import subprocess
import pprint
def facter2dict( lines ):
res = {}
for line in lines:
k, v = line.split(' => ')
res[k] = v
return res
def facter():
p = subprocess.Popen( ['facter'], stdout=subprocess.PIPE )
p.wait()
lines = p.stdout.readlines()
return facter2dict( lines )
if __name__ == "__main__":
pprint.pprint( facter() )
Run Code Online (Sandbox Code Playgroud)
Salt实现了称为谷物的Facter替代品。
http://docs.saltstack.org/en/latest/ref/modules/index.html#grains-data
还有一种尝试做到这一点的方法叫做Phacter
http://code.google.com/p/speed/wiki/Phacter
我没有尝试过,但是我同意这个概念。一个人可能不想/不能在他们的系统上安装Ruby,但是想要类似的功能。
| 归档时间: |
|
| 查看次数: |
3410 次 |
| 最近记录: |