mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix windows grains for os
This commit is contained in:
parent
dc518c5340
commit
92034936c1
2 changed files with 64 additions and 8 deletions
|
@ -33,6 +33,8 @@ _supported_dists += ('arch', 'mageia', 'meego', 'vmware', 'bluewhite64',
|
|||
import salt.log
|
||||
import salt.utils
|
||||
import salt.utils.network
|
||||
if salt.utils.is_windows():
|
||||
import salt.utils.win_osinfo
|
||||
|
||||
# Solve the Chicken and egg problem where grains need to run before any
|
||||
# of the modules are loaded and are generally available for any usage.
|
||||
|
@ -839,7 +841,7 @@ def _windows_platform_data():
|
|||
wmi_c = wmi.WMI()
|
||||
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa394102%28v=vs.85%29.aspx
|
||||
systeminfo = wmi_c.Win32_ComputerSystem()[0]
|
||||
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa394239%28v=vs.85%29.aspx
|
||||
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
||||
osinfo = wmi_c.Win32_OperatingSystem()[0]
|
||||
# http://msdn.microsoft.com/en-us/library/windows/desktop/aa394077(v=vs.85).aspx
|
||||
biosinfo = wmi_c.Win32_BIOS()[0]
|
||||
|
@ -860,10 +862,18 @@ def _windows_platform_data():
|
|||
# the name of the OS comes with a bunch of other data about the install
|
||||
# location. For example:
|
||||
# 'Microsoft Windows Server 2008 R2 Standard |C:\\Windows|\\Device\\Harddisk0\\Partition2'
|
||||
(osfullname, _) = osinfo.Name.split('|', 1)
|
||||
osfullname = osfullname.strip()
|
||||
osrelease = platform.release()
|
||||
if salt.utils.win_osinfo.get_os_version_info()['ProductType'] > 1:
|
||||
server = {'Vista': '2008',
|
||||
'7': '2008R2',
|
||||
'8': '2012',
|
||||
'8.1': '2012R2',
|
||||
'10': '2016'}
|
||||
osrelease = server[osrelease]
|
||||
|
||||
grains = {
|
||||
'osversion': osinfo.Version,
|
||||
'osrelease': osrelease,
|
||||
'osmanufacturer': osinfo.Manufacturer,
|
||||
'manufacturer': systeminfo.Manufacturer,
|
||||
'productname': systeminfo.Model,
|
||||
|
@ -871,7 +881,7 @@ def _windows_platform_data():
|
|||
# 'PhoenixBIOS 4.0 Release 6.0 '
|
||||
'biosversion': biosinfo.Name.strip(),
|
||||
'serialnumber': biosinfo.SerialNumber,
|
||||
'osfullname': osfullname,
|
||||
'osfullname': osinfo.Caption,
|
||||
'timezone': timeinfo.Description,
|
||||
'windowsdomain': systeminfo.Domain,
|
||||
'motherboard': {
|
||||
|
@ -1066,14 +1076,11 @@ def os_data():
|
|||
grains['os'] = 'proxy'
|
||||
grains['os_family'] = 'proxy'
|
||||
elif salt.utils.is_windows():
|
||||
with salt.utils.winapi.Com():
|
||||
wmi_c = wmi.WMI()
|
||||
grains['osrelease'] = grains['kernelrelease']
|
||||
grains['osversion'] = grains['kernelrelease'] = wmi_c.Win32_OperatingSystem()[0].Version
|
||||
grains['os'] = 'Windows'
|
||||
grains['os_family'] = 'Windows'
|
||||
grains.update(_memdata(grains))
|
||||
grains.update(_windows_platform_data())
|
||||
grains['kernelrelease'] = grains['osversion']
|
||||
grains.update(_windows_cpudata())
|
||||
grains.update(_windows_virtual(grains))
|
||||
grains.update(_ps(grains))
|
||||
|
|
49
salt/utils/win_osinfo.py
Normal file
49
salt/utils/win_osinfo.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Get Versioning information from Windows
|
||||
'''
|
||||
# http://stackoverflow.com/questions/32300004/python-ctypes-getting-0-with-getversionex-function
|
||||
import ctypes
|
||||
from ctypes.wintypes import BYTE, WORD, DWORD, WCHAR
|
||||
|
||||
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
|
||||
|
||||
class OSVERSIONINFO(ctypes.Structure):
|
||||
_fields_ = (('dwOSVersionInfoSize', DWORD),
|
||||
('dwMajorVersion', DWORD),
|
||||
('dwMinorVersion', DWORD),
|
||||
('dwBuildNumber', DWORD),
|
||||
('dwPlatformId', DWORD),
|
||||
('szCSDVersion', WCHAR * 128))
|
||||
def __init__(self, *args, **kwds):
|
||||
super(OSVERSIONINFO, self).__init__(*args, **kwds)
|
||||
self.dwOSVersionInfoSize = ctypes.sizeof(self)
|
||||
kernel32.GetVersionExW(ctypes.byref(self))
|
||||
|
||||
class OSVERSIONINFOEX(OSVERSIONINFO):
|
||||
_fields_ = (('wServicePackMajor', WORD),
|
||||
('wServicePackMinor', WORD),
|
||||
('wSuiteMask', WORD),
|
||||
('wProductType', BYTE),
|
||||
('wReserved', BYTE))
|
||||
|
||||
def errcheck_bool(result, func, args):
|
||||
if not result:
|
||||
raise ctypes.WinError(ctypes.get_last_error())
|
||||
return args
|
||||
|
||||
kernel32.GetVersionExW.errcheck = errcheck_bool
|
||||
kernel32.GetVersionExW.argtypes = (ctypes.POINTER(OSVERSIONINFO),)
|
||||
|
||||
def get_os_version_info():
|
||||
info = OSVERSIONINFOEX()
|
||||
ret = {'MajorVersion': info.dwMajorVersion,
|
||||
'MinorVersion': info.dwMinorVersion,
|
||||
'BuildNumber': info.dwBuildNumber,
|
||||
'PlatformID': info.dwPlatformId,
|
||||
'ServicePackMajor': info.wServicePackMajor,
|
||||
'ServicePackMinor': info.wServicePackMinor,
|
||||
'SuiteMask': info.wSuiteMask,
|
||||
'ProductType': info.wProductType}
|
||||
|
||||
return ret
|
Loading…
Add table
Reference in a new issue