mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #1628 from jre/grains
Grain fiddling on OpenBSD (second try)
This commit is contained in:
commit
24df88cb87
1 changed files with 27 additions and 21 deletions
|
@ -107,21 +107,28 @@ def _linux_cpudata():
|
|||
return grains
|
||||
|
||||
|
||||
def _freebsd_cpudata():
|
||||
def _bsd_cpudata(osdata):
|
||||
'''
|
||||
Return cpu information for FreeBSD systems
|
||||
Return cpu information for BSD-like systems
|
||||
'''
|
||||
grains = {}
|
||||
sysctl = salt.utils.which('sysctl')
|
||||
arch = salt.utils.which('arch')
|
||||
cmds = {}
|
||||
|
||||
if sysctl:
|
||||
machine_cmd = '{0} -n hw.machine'.format(sysctl)
|
||||
ncpu_cmd = '{0} -n hw.ncpu'.format(sysctl)
|
||||
model_cpu = '{0} -n hw.model'.format(sysctl)
|
||||
grains['num_cpus'] = __salt__['cmd.run'](ncpu_cmd).strip()
|
||||
grains['cpu_model'] = __salt__['cmd.run'](model_cpu).strip()
|
||||
grains['cpuarch'] = __salt__['cmd.run'](machine_cmd).strip()
|
||||
grains['cpu_flags'] = []
|
||||
cmds['num_cpus'] = '{0} -n hw.ncpu'.format(sysctl)
|
||||
cmds['cpu_model'] = '{0} -n hw.model'.format(sysctl)
|
||||
cmds['cpuarch'] = '{0} -n hw.machine'.format(sysctl)
|
||||
if arch and osdata['kernel'] == 'OpenBSD':
|
||||
cmds['cpuarch'] = '{0} -s'.format(arch)
|
||||
|
||||
grains = dict([(k, __salt__['cmd.run'](v)) for k, v in cmds.items()])
|
||||
grains['cpu_flags'] = []
|
||||
try:
|
||||
grains['num_cpus'] = int(grains['num_cpus'])
|
||||
except Exception:
|
||||
grains['num_cpus'] = 0
|
||||
|
||||
return grains
|
||||
|
||||
|
||||
|
@ -477,15 +484,14 @@ def os_data():
|
|||
elif grains['kernel'] == 'Darwin':
|
||||
grains['os'] = 'MacOS'
|
||||
grains['os_family'] = 'MacOS'
|
||||
grains.update(_freebsd_cpudata())
|
||||
grains.update(_bsd_cpudata(grains))
|
||||
else:
|
||||
grains['os'] = grains['kernel']
|
||||
grains['os_family'] = grains['kernel']
|
||||
if grains['kernel'] == 'Linux':
|
||||
grains.update(_linux_cpudata())
|
||||
elif grains['kernel'] in ('FreeBSD', 'OpenBSD'):
|
||||
# _freebsd_cpudata works on OpenBSD as well.
|
||||
grains.update(_freebsd_cpudata())
|
||||
grains.update(_bsd_cpudata(grains))
|
||||
|
||||
grains.update(_memdata(grains))
|
||||
|
||||
|
@ -659,14 +665,14 @@ def _hw_data(osdata):
|
|||
grains['productname'] = __salt__['cmd.run']('{0} smbios.system.product'.format(kenv)).strip()
|
||||
elif osdata['kernel'] == 'OpenBSD':
|
||||
sysctl = salt.utils.which('sysctl')
|
||||
vendor_cmd = '{0} -n hw.vendor'.format(sysctl)
|
||||
product_cmd = '{0} -n hw.product'.format(sysctl)
|
||||
version_cmd = '{0} -n hw.version'.format(sysctl)
|
||||
serial_cmd = '{0} -n hw.serialno'.format(sysctl)
|
||||
grains['biosversion'] = __salt__['cmd.run'](version_cmd).strip()
|
||||
grains['manufacturer'] = __salt__['cmd.run'](vendor_cmd).strip()
|
||||
grains['productname'] = __salt__['cmd.run'](product_cmd).strip()
|
||||
grains['serialnumber'] = __salt__['cmd.run'](serial_cmd).strip()
|
||||
hwdata = {'biosversion': 'hw.version',
|
||||
'manufacturer': 'hw.vendor',
|
||||
'productname': 'hw.product',
|
||||
'serialnumber': 'hw.serialno'}
|
||||
for key, oid in hwdata.items():
|
||||
value = __salt__['cmd.run']('{0} -n {1}'.format(sysctl, oid))
|
||||
if not value.endswith(' value is not available'):
|
||||
grains[key] = value
|
||||
return grains
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue