【问题标题】:Filter minions by memory size按内存大小过滤 minions
【发布时间】:2016-10-12 21:59:46
【问题描述】:

是否可以在 Salt Stack 中按内存大小过滤 minions,但指示内存大小必须大于或小于,而不是等于?所以不要这样:

salt -C 'G@mem_total:993' test.ping

我需要这样的东西:

salt -C 'G@mem_total > 993' test.ping

【问题讨论】:

    标签: salt-stack


    【解决方案1】:

    恐怕您实际上不能按原样使用targeting feature。

    我首先想到的是写一个custom grain。

    如果您只需要在一个地方并且该值不经常更改,这可能是一种解决方法:

    未经测试的示例:

    #!/usr/bin/env python
    from psutil import virtual_memory
    
    def categorize_memory():
        grains = {}
        mem = virtual_memory()
        total_mem = mem.total
        if total_mem < 1024 * 999:
            grains['memory_category'] = 'low_mem_minion'
        else:
            grains['memory_category'] = 'high_mem_minion'
        return grains
    

    以后就这样用salt -C 'G@memory_category:high_mem_minion' test.ping

    在python中解析内存的代码取自Get total physical memory in Python

    【讨论】:

      猜你喜欢
      • 2017-08-23
      • 1970-01-01
      • 2021-01-30
      • 2016-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 2021-03-07
      相关资源
      最近更新 更多