Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python version of "facter"?

Tags:

python

facter

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?

like image 811
ymotongpoo Avatar asked Dec 22 '22 17:12

ymotongpoo


2 Answers

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() )
like image 57
Andrew Walker Avatar answered Jan 10 '23 16:01

Andrew Walker


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.

like image 27
gregswift Avatar answered Jan 10 '23 14:01

gregswift