mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #38456 from twangboy/gate_win_utils
Gate Windows Specific Salt Utils
This commit is contained in:
commit
5395d3210a
5 changed files with 55 additions and 23 deletions
|
@ -64,7 +64,7 @@ try:
|
|||
# pylint: enable=unused-import
|
||||
logging.getLogger('boto').setLevel(logging.CRITICAL)
|
||||
HAS_BOTO = True
|
||||
except ImportError:
|
||||
except (ImportError, AttributeError):
|
||||
HAS_BOTO = False
|
||||
|
||||
|
||||
|
|
|
@ -6,9 +6,6 @@ missing functions in other modules
|
|||
from __future__ import absolute_import
|
||||
from salt.exceptions import CommandExecutionError
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils
|
||||
|
||||
# Import 3rd Party Libs
|
||||
try:
|
||||
import ntsecuritycon
|
||||
|
@ -22,12 +19,12 @@ except ImportError:
|
|||
HAS_WIN32 = False
|
||||
|
||||
|
||||
# Although utils are often directly imported, it is also possible to use the
|
||||
# loader.
|
||||
def __virtual__():
|
||||
'''
|
||||
Load only on Windows with necessary modules
|
||||
Only load if Win32 Libraries are installed
|
||||
'''
|
||||
if not salt.utils.is_windows():
|
||||
return False, 'This utility only works on Windows'
|
||||
if not HAS_WIN32:
|
||||
return False, 'This utility requires pywin32'
|
||||
|
||||
|
|
|
@ -1,14 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Get Versioning information from Windows
|
||||
Get Version information from Windows
|
||||
'''
|
||||
# http://stackoverflow.com/questions/32300004/python-ctypes-getting-0-with-getversionex-function
|
||||
from __future__ import absolute_import
|
||||
|
||||
# Import Third Party Libs
|
||||
import ctypes
|
||||
from ctypes.wintypes import BYTE, WORD, DWORD, WCHAR
|
||||
try:
|
||||
from ctypes.wintypes import BYTE, WORD, DWORD, WCHAR
|
||||
HAS_WIN32 = True
|
||||
except (ImportError, ValueError):
|
||||
HAS_WIN32 = False
|
||||
|
||||
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
|
||||
if HAS_WIN32:
|
||||
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
|
||||
|
||||
|
||||
# Although utils are often directly imported, it is also possible to use the
|
||||
# loader.
|
||||
def __virtual__():
|
||||
'''
|
||||
Only load if Win32 Libraries are installed
|
||||
'''
|
||||
if not HAS_WIN32:
|
||||
return False, 'This utility requires pywin32'
|
||||
|
||||
return 'win_osinfo'
|
||||
|
||||
|
||||
class OSVERSIONINFO(ctypes.Structure):
|
||||
|
@ -38,8 +56,9 @@ def errcheck_bool(result, func, args):
|
|||
raise ctypes.WinError(ctypes.get_last_error())
|
||||
return args
|
||||
|
||||
kernel32.GetVersionExW.errcheck = errcheck_bool
|
||||
kernel32.GetVersionExW.argtypes = (ctypes.POINTER(OSVERSIONINFO),)
|
||||
if HAS_WIN32:
|
||||
kernel32.GetVersionExW.errcheck = errcheck_bool
|
||||
kernel32.GetVersionExW.argtypes = (ctypes.POINTER(OSVERSIONINFO),)
|
||||
|
||||
|
||||
def get_os_version_info():
|
||||
|
|
|
@ -27,20 +27,20 @@ try:
|
|||
except ImportError:
|
||||
HAS_WIN32 = False
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils
|
||||
|
||||
# Set up logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# Although utils are often directly imported, it is also possible to use the
|
||||
# loader.
|
||||
def __virtual__():
|
||||
'''
|
||||
Load only on Windows
|
||||
Only load if Win32 Libraries are installed
|
||||
'''
|
||||
if salt.utils.is_windows() and HAS_WIN32:
|
||||
return 'win_runas'
|
||||
return False
|
||||
if not HAS_WIN32:
|
||||
return False, 'This utility requires pywin32'
|
||||
|
||||
return 'win_runas'
|
||||
|
||||
|
||||
if HAS_WIN32:
|
||||
|
|
|
@ -8,10 +8,26 @@ from os.path import splitext, abspath
|
|||
from sys import modules
|
||||
|
||||
# Import third party libs
|
||||
import win32serviceutil
|
||||
import win32service
|
||||
import win32event
|
||||
import win32api
|
||||
try:
|
||||
import win32serviceutil
|
||||
import win32service
|
||||
import win32event
|
||||
import win32api
|
||||
HAS_WIN32 = True
|
||||
except ImportError:
|
||||
HAS_WIN32 = False
|
||||
|
||||
|
||||
# Although utils are often directly imported, it is also possible to use the
|
||||
# loader.
|
||||
def __virtual__():
|
||||
'''
|
||||
Only load if Win32 Libraries are installed
|
||||
'''
|
||||
if not HAS_WIN32:
|
||||
return False, 'This utility requires pywin32'
|
||||
|
||||
return 'winservice'
|
||||
|
||||
|
||||
class Service(win32serviceutil.ServiceFramework):
|
||||
|
|
Loading…
Add table
Reference in a new issue