1.
[root@kylin1 grains]# cd /srv/salt/_grains/
[root@kylin1 _grains]# ls
cpu.py
[root@kylin1 _grains]# cat /srv/salt/_grains/cpu.py
#!/usr/bin/python
#coding:utf-8
import os
def cpu():
grains = {}
command = "top -b -n 1 | grep Cpu | awk -F'[:,]' '{print $5}'"
with os.popen(command) as file:
grains["cpu_id"] = file.read()
return grains
2.
3.