I'm considering collect server data and in those servers Python 2.6 are pre-installed. Now I wonder if there are Python library correspond to "facter" of Ruby, not the Python "binding" for facter.
I googled about it but couldn't find any. Does anyone have any idea about this?
I can't see any reason why you wouldn't just use facter itself. The output format is easily consumable from within a python script.
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() )
Salt implements a Facter replacement called Grains.
http://docs.saltstack.org/en/latest/ref/modules/index.html#grains-data
There is also an attempt to do this called Phacter
http://code.google.com/p/speed/wiki/Phacter
I haven't tried it, however I agree with the concept. One may not want/be able to install Ruby on their system but want the similar functionality.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With