mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #39536 from twangboy/fix_win_status
Namespace 'status' functions in 'win_status'
This commit is contained in:
commit
40f72db53e
2 changed files with 48 additions and 55 deletions
|
@ -4,7 +4,6 @@ Module for returning various status data about a minion.
|
|||
These data can be useful for compiling into stats later.
|
||||
'''
|
||||
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import
|
||||
import datetime
|
||||
|
@ -38,6 +37,16 @@ __func_alias__ = {
|
|||
}
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Not all functions supported by Windows
|
||||
'''
|
||||
if salt.utils.is_windows():
|
||||
return False, 'Windows platform is not supported by this module'
|
||||
|
||||
return __virtualname__
|
||||
|
||||
|
||||
def _number(text):
|
||||
'''
|
||||
Convert a string to a number.
|
||||
|
@ -64,8 +73,6 @@ def procs():
|
|||
salt '*' status.procs
|
||||
'''
|
||||
# Get the user, pid and cmd
|
||||
if salt.utils.is_windows():
|
||||
raise CommandExecutionError('This platform is not supported')
|
||||
ret = {}
|
||||
uind = 0
|
||||
pind = 0
|
||||
|
@ -114,8 +121,6 @@ def custom():
|
|||
|
||||
salt '*' status.custom
|
||||
'''
|
||||
if salt.utils.is_windows():
|
||||
raise CommandExecutionError('This platform is not supported')
|
||||
ret = {}
|
||||
conf = __salt__['config.dot_vals']('status')
|
||||
for key, val in six.iteritems(conf):
|
||||
|
@ -584,10 +589,6 @@ def diskusage(*args):
|
|||
salt '*' status.diskusage ext? # usage for ext[234] filesystems
|
||||
salt '*' status.diskusage / ext? # usage for / and all ext filesystems
|
||||
'''
|
||||
|
||||
if salt.utils.is_windows():
|
||||
raise CommandExecutionError('This platform is not supported')
|
||||
|
||||
selected = set()
|
||||
fstypes = set()
|
||||
if not args:
|
||||
|
@ -926,8 +927,6 @@ def w(): # pylint: disable=C0103
|
|||
|
||||
salt '*' status.w
|
||||
'''
|
||||
if salt.utils.is_windows():
|
||||
raise CommandExecutionError('This platform is not supported')
|
||||
user_list = []
|
||||
users = __salt__['cmd.run']('w -h').splitlines()
|
||||
for row in users:
|
||||
|
|
|
@ -12,47 +12,59 @@ or for problem solving if your minion is having problems.
|
|||
|
||||
# Import Python Libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import ctypes
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils
|
||||
import salt.ext.six as six
|
||||
import salt.utils.event
|
||||
from salt._compat import subprocess
|
||||
from salt.utils.network import host_to_ips as _host_to_ips
|
||||
# pylint: disable=W0611
|
||||
from salt.modules.status import ping_master, time_
|
||||
import copy
|
||||
# pylint: enable=W0611
|
||||
from salt.utils import namespaced_function as _namespaced_function
|
||||
|
||||
import os
|
||||
import ctypes
|
||||
import sys
|
||||
import time
|
||||
import datetime
|
||||
from subprocess import list2cmdline
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
try:
|
||||
# Import 3rd Party Libs
|
||||
if salt.utils.is_windows():
|
||||
import wmi
|
||||
import salt.utils.winapi
|
||||
has_required_packages = True
|
||||
except ImportError:
|
||||
if salt.utils.is_windows():
|
||||
log.exception('pywin32 and wmi python packages are required '
|
||||
'in order to use the status module.')
|
||||
has_required_packages = False
|
||||
HAS_WMI = True
|
||||
else:
|
||||
HAS_WMI = False
|
||||
|
||||
__opts__ = {}
|
||||
|
||||
# Define the module's virtual name
|
||||
__virtualname__ = 'status'
|
||||
|
||||
|
||||
def __virtual__():
|
||||
'''
|
||||
Only works on Windows systems
|
||||
Only works on Windows systems with WMI and WinAPI
|
||||
'''
|
||||
if salt.utils.is_windows() and has_required_packages:
|
||||
return __virtualname__
|
||||
return (False, 'Cannot load win_status module on non-windows')
|
||||
if not salt.utils.is_windows():
|
||||
return False, 'win_status.py: Requires Windows'
|
||||
|
||||
if not HAS_WMI:
|
||||
return False, 'win_status.py: Requires WMI and WinAPI'
|
||||
|
||||
# Namespace modules from `status.py`
|
||||
global ping_master, time_
|
||||
ping_master = _namespaced_function(ping_master, globals())
|
||||
time_ = _namespaced_function(time_, globals())
|
||||
|
||||
return __virtualname__
|
||||
|
||||
__func_alias__ = {
|
||||
'time_': 'time'
|
||||
}
|
||||
|
||||
|
||||
def cpuload():
|
||||
|
@ -69,17 +81,8 @@ def cpuload():
|
|||
'''
|
||||
|
||||
# Pull in the information from WMIC
|
||||
cmd = list2cmdline(['wmic', 'cpu'])
|
||||
info = __salt__['cmd.run'](cmd).split('\r\n')
|
||||
|
||||
# Find the location of LoadPercentage
|
||||
column = info[0].index('LoadPercentage')
|
||||
|
||||
# Get the end of the number.
|
||||
end = info[1].index(' ', column+1)
|
||||
|
||||
# Return pull it out of the informatin and cast it to an int
|
||||
return int(info[1][column:end])
|
||||
cmd = ['wmic', 'cpu', 'get', 'loadpercentage', '/value']
|
||||
return int(__salt__['cmd.run'](cmd).split('=')[1])
|
||||
|
||||
|
||||
def diskusage(human_readable=False, path=None):
|
||||
|
@ -203,18 +206,9 @@ def uptime(human_readable=False):
|
|||
'''
|
||||
|
||||
# Open up a subprocess to get information from WMIC
|
||||
cmd = list2cmdline(['wmic', 'os', 'get', 'lastbootuptime'])
|
||||
outs = __salt__['cmd.run'](cmd)
|
||||
cmd = ['wmic', 'os', 'get', 'lastbootuptime', '/value']
|
||||
startup_time = __salt__['cmd.run'](cmd).split('=')[1][:14]
|
||||
|
||||
# Get the line that has when the computer started in it:
|
||||
stats_line = ''
|
||||
# use second line from output
|
||||
stats_line = outs.split('\r\n')[1]
|
||||
|
||||
# Extract the time string from the line and parse
|
||||
#
|
||||
# Get string, just use the leading 14 characters
|
||||
startup_time = stats_line[:14]
|
||||
# Convert to time struct
|
||||
startup_time = time.strptime(startup_time, '%Y%m%d%H%M%S')
|
||||
# Convert to datetime object
|
||||
|
|
Loading…
Add table
Reference in a new issue