updated grains/core.py to use cmd.run instead of subprocess

This commit is contained in:
Christer Edwards 2011-12-20 21:21:43 -07:00
parent aa957b993e
commit 335942ffb7

View File

@ -15,7 +15,6 @@ as those returned here
import os
import socket
import subprocess
import sys
import re
import platform
@ -29,14 +28,12 @@ def _kernel():
# Provides:
# kernel
grains = {}
grains['kernel'] = subprocess.Popen(['uname', '-s'],
stdout=subprocess.PIPE).communicate()[0].strip()
grains['kernel'] = __salt__['cmd.run']('uname -s').strip()
if grains['kernel'] == 'aix':
grains['kernelrelease'] = subprocess.Popen(['oslevel', '-s'],
stdout=subprocess.PIPE).communicate()[0].strip()
grains['kernelrelease'] = __salt__['cmd.run']('oslevel -s').strip()
else:
grains['kernelrelease'] = subprocess.Popen(['uname', '-r'],
stdout=subprocess.PIPE).communicate()[0].strip()
grains['kernelrelease'] = __salt__['cmd.run']('uname -r').strip()
if 'kernel' not in grains:
grains['kernel'] = 'Unknown'
if not grains['kernel']:
@ -56,8 +53,7 @@ def _linux_cpudata():
grains = {}
cpuinfo = '/proc/cpuinfo'
# Grab the Arch
arch = subprocess.Popen(['uname', '-m'],
stdout=subprocess.PIPE).communicate()[0].strip()
arch = __salt__['cmd.run']('uname -m').strip()
grains['cpuarch'] = arch
if not grains['cpuarch']:
grains['cpuarch'] = 'Unknown'
@ -90,21 +86,9 @@ def _freebsd_cpudata():
sysctl = salt.utils.which("sysctl")
if sysctl:
grains['cpuarch'] = subprocess.Popen(
'{0} -n hw.machine'.format(sysctl),
shell=True,
stdout=subprocess.PIPE
).communicate()[0].strip()
grains['num_cpus'] = subprocess.Popen(
'{0} -n hw.ncpu'.format(sysctl),
shell=True,
stdout=subprocess.PIPE
).communicate()[0].strip()
grains['cpu_model'] = subprocess.Popen(
'{0} -n hw.model'.format(sysctl),
shell=True,
stdout=subprocess.PIPE
).communicate()[0].strip()
grains['cpuarch'] = __salt__['cmd.run']('{0} -n hw.machine').strip()
grains['num_cpus'] = __salt__['cmd.run']('{0} -n hw.ncpu').strip()
grains['cpu_model'] = __salt__['cmd.run']('{0} -n hw.model').strip()
grains['cpu_flags'] = []
return grains
@ -129,11 +113,7 @@ def _memdata(osdata):
elif osdata['kernel'] in ('FreeBSD','OpenBSD'):
sysctl = salt.utils.which("sysctl")
if sysctl:
mem = subprocess.Popen(
'{0} -n hw.physmem'.format(sysctl),
shell=True,
stdout=subprocess.PIPE
).communicate()[0].strip()
mem = __salt__['cmd.run']('{0} -n hw.physmem').strip()
grains['mem_total'] = str(int(mem) / 1024 / 1024)
return grains
@ -152,10 +132,7 @@ def _virtual(osdata):
dmidecode = salt.utils.which("dmidecode")
if dmidecode:
output=subprocess.Popen(dmidecode,
shell=True,
stdout=subprocess.PIPE
).communicate()[0].lower()
output = __salt__['cmd.run']('dmidecode').lower()
# Product Name: VirtualBox
if 'Vendor: QEMU' in output:
# FIXME: Make this detect between kvm or qemu
@ -171,10 +148,7 @@ def _virtual(osdata):
grains['virtual'] = 'VirtualPC'
# Fall back to lspci if dmidecode isn't available
elif lspci:
model=subprocess.Popen(lspci,
shell=True,
stdout=subprocess.PIPE
).communicate()[0].lower()
model = __salt__['cmd.run']('lspci').lower()
if 'vmware' in model:
grains['virtual'] = 'VMware'
# 00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
@ -207,11 +181,7 @@ def _virtual(osdata):
elif osdata['kernel'] == 'FreeBSD':
sysctl = salt.utils.which("sysctl")
if sysctl:
model = subprocess.Popen(
'{0} hw.model'.format(sysctl),
shell=True,
stdout=subprocess.PIPE
).communicate()[0].split(':')[1].strip()
model = __salt__['cmd.run']('{0} hw.model').strip()
if 'QEMU Virtual CPU' in model:
grains['virtual'] = 'kvm'
return grains