mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 08:58:59 +00:00
Merge pull request #20128 from kim0/freebsd-status.cpuinfo
Freebsd status.cpuinfo
This commit is contained in:
commit
c6a11643f9
@ -251,21 +251,48 @@ def cpuinfo():
|
|||||||
|
|
||||||
salt '*' status.cpuinfo
|
salt '*' status.cpuinfo
|
||||||
'''
|
'''
|
||||||
procf = '/proc/cpuinfo'
|
def linux_cpuinfo():
|
||||||
if not os.path.isfile(procf):
|
'''
|
||||||
return {}
|
linux specific cpuinfo implementation
|
||||||
stats = salt.utils.fopen(procf, 'r').read().splitlines()
|
'''
|
||||||
ret = {}
|
procf = '/proc/cpuinfo'
|
||||||
for line in stats:
|
if not os.path.isfile(procf):
|
||||||
if not line:
|
return {}
|
||||||
continue
|
stats = salt.utils.fopen(procf, 'r').read().splitlines()
|
||||||
comps = line.split(':')
|
ret = {}
|
||||||
comps[0] = comps[0].strip()
|
for line in stats:
|
||||||
if comps[0] == 'flags':
|
if not line:
|
||||||
ret[comps[0]] = comps[1].split()
|
continue
|
||||||
else:
|
comps = line.split(':')
|
||||||
|
comps[0] = comps[0].strip()
|
||||||
|
if comps[0] == 'flags':
|
||||||
|
ret[comps[0]] = comps[1].split()
|
||||||
|
else:
|
||||||
|
ret[comps[0]] = comps[1].strip()
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def freebsd_cpuinfo():
|
||||||
|
'''
|
||||||
|
freebds specific cpuinfo implementation
|
||||||
|
'''
|
||||||
|
freebsd_cmd = 'sysctl hw.model hw.ncpu'
|
||||||
|
ret = {}
|
||||||
|
for line in __salt__['cmd.run'](freebsd_cmd).splitlines():
|
||||||
|
if not line:
|
||||||
|
continue
|
||||||
|
comps = line.split(':')
|
||||||
|
comps[0] = comps[0].strip()
|
||||||
ret[comps[0]] = comps[1].strip()
|
ret[comps[0]] = comps[1].strip()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
# dict that returns a function that does the right thing per platform
|
||||||
|
get_version = {
|
||||||
|
'Linux': linux_cpuinfo,
|
||||||
|
'FreeBSD': freebsd_cpuinfo,
|
||||||
|
}
|
||||||
|
|
||||||
|
errmsg = 'This method is unsupported on the current operating system!'
|
||||||
|
return get_version.get(__grains__['kernel'], lambda: errmsg)()
|
||||||
|
|
||||||
|
|
||||||
def diskstats():
|
def diskstats():
|
||||||
@ -459,7 +486,7 @@ def netdev():
|
|||||||
comps = line.split()
|
comps = line.split()
|
||||||
# Fix lines like eth0:9999..'
|
# Fix lines like eth0:9999..'
|
||||||
comps[0] = line.split(':')[0].strip()
|
comps[0] = line.split(':')[0].strip()
|
||||||
#Support lines both like eth0:999 and eth0: 9999
|
# Support lines both like eth0:999 and eth0: 9999
|
||||||
comps.insert(1, line.split(':')[1].strip().split()[0])
|
comps.insert(1, line.split(':')[1].strip().split()[0])
|
||||||
ret[comps[0]] = {'iface': comps[0],
|
ret[comps[0]] = {'iface': comps[0],
|
||||||
'rx_bytes': _number(comps[1]),
|
'rx_bytes': _number(comps[1]),
|
||||||
@ -572,15 +599,18 @@ def version():
|
|||||||
salt '*' status.version
|
salt '*' status.version
|
||||||
'''
|
'''
|
||||||
def linux_version():
|
def linux_version():
|
||||||
|
'''
|
||||||
|
linux specific implementation of version
|
||||||
|
'''
|
||||||
procf = '/proc/version'
|
procf = '/proc/version'
|
||||||
if not os.path.isfile(procf):
|
if not os.path.isfile(procf):
|
||||||
return {}
|
return {}
|
||||||
return salt.utils.fopen(procf, 'r').read().strip()
|
return salt.utils.fopen(procf, 'r').read().strip()
|
||||||
|
|
||||||
# dict that return a function that does the right thing per platform
|
# dict that returns a function that does the right thing per platform
|
||||||
get_version = {
|
get_version = {
|
||||||
'Linux': linux_version,
|
'Linux': linux_version,
|
||||||
'FreeBSD': lambda: __salt__['cmd.run']('sysctl -n kern.version'),
|
'FreeBSD': lambda: __salt__['cmd.run']('sysctl -n kern.version'),
|
||||||
}
|
}
|
||||||
|
|
||||||
errmsg = 'This method is unsupported on the current operating system!'
|
errmsg = 'This method is unsupported on the current operating system!'
|
||||||
|
Loading…
Reference in New Issue
Block a user