Python 版本的“facter”?

发布于 2024-10-19 19:20:24 字数 137 浏览 3 评论 0原文

我正在考虑收集服务器数据,并且在这些服务器中预安装了 Python 2.6。 现在我想知道是否有Python库对应于Ruby的“facter”,而不是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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

青衫儰鉨ミ守葔 2024-10-26 19:20:24

我看不出你有什么理由不直接使用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() )

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() )
攒一口袋星星 2024-10-26 19:20:24

Salt 实现了一个称为 Grains 的 Facter 替代品。

http://docs.saltstack.org/en/latest /ref/modules/index.html#grains-data

还有一种尝试称为 Phacter

http://code.google.com/p/speed/wiki/Phacter

我没有尝试过,但我同意这个概念。人们可能不希望/无法在他们的系统上安装 Ruby,但想要类似的功能。

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.

似狗非友 2024-10-26 19:20:24

有点新 http://github.com/hihellobolke/sillyfacter/

安装使用

  # Needs pip v1.5
  pip install --upgrade --allow-all-external --allow-unverified netifaces sillyfacter

您可能需要升级 pip也

  # To upgrade pip
  pip install --ugrade pip

Somewhat new http://github.com/hihellobolke/sillyfacter/

Install using

  # Needs pip v1.5
  pip install --upgrade --allow-all-external --allow-unverified netifaces sillyfacter

You may beed to upgrade pip too

  # To upgrade pip
  pip install --ugrade pip
单身狗的梦 2024-10-26 19:20:24

这是@AndrewWalker 建议的更压缩版本。它还确保 ' => ' 在分割之前存在并删除尾随 \n :

import subprocess

p = subprocess.Popen( ['facter'], stdout=subprocess.PIPE )
p.wait()
facts = p.stdout.readlines()
# strip removes the trailing \n
facts = dict(k.split(' => ') for k in [s.strip() for s in facts if ' => ' in s])
print facts["architecture"]

我想我会选择 facterpy,不过。 pip installfacterpy,然后:

import facter

facts = facter.Facter()
print facts["architecture"]

Here is a more compressed version of @AndrewWalker's suggestion. It also ensures ' => ' is present before splitting and removes the trailing \n :

import subprocess

p = subprocess.Popen( ['facter'], stdout=subprocess.PIPE )
p.wait()
facts = p.stdout.readlines()
# strip removes the trailing \n
facts = dict(k.split(' => ') for k in [s.strip() for s in facts if ' => ' in s])
print facts["architecture"]

I think I am going for facterpy, though. pip install facterpy, then:

import facter

facts = facter.Facter()
print facts["architecture"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文