Merge pull request #37031 from isbm/isbm-solaris-status-fix-dev

Prevent fallback to uptime on status.uptime for Solaris 9, 10 and 11
This commit is contained in:
Mike Place 2016-10-20 14:53:11 +09:00 committed by GitHub
commit 60ec60ddfd

View file

@ -148,18 +148,17 @@ def uptime():
salt '*' status.uptime
'''
ut_path = "/proc/uptime"
if not os.path.exists(ut_path):
if __grains__['kernel'] == 'Linux':
ut_ret = {'seconds': 0}
if salt.utils.is_linux():
ut_path = "/proc/uptime"
if not os.path.exists(ut_path):
raise CommandExecutionError("File {ut_path} was not found.".format(ut_path=ut_path))
elif not salt.utils.which('uptime'):
raise CommandExecutionError("No uptime binary available.")
else:
return __salt__['cmd.run']('uptime')
ut_ret = {
'seconds': int(float(open(ut_path).read().strip().split()[0]))
}
ut_ret['seconds'] = int(float(open(ut_path).read().strip().split()[0]))
elif salt.utils.is_sunos():
cmd = "kstat -p unix:0:system_misc:boot_time | nawk '{printf \"%d\\n\", srand()-$2}'"
ut_ret['seconds'] = int(__salt__['cmd.shell'](cmd, output_loglevel='trace').strip() or 0)
else:
return __salt__['cmd.run']('uptime')
utc_time = datetime.datetime.utcfromtimestamp(time.time() - ut_ret['seconds'])
ut_ret['since_iso'] = utc_time.isoformat()