mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Add additional grains and system info
Adds the `windowsdomaintype` grain Adds the get_join_info util to populate said grain Adds additional information to the output of `get_system_info` since we're already pulling the data anyway with the WMI call
This commit is contained in:
parent
99ea25371d
commit
501ade2ed1
@ -1234,6 +1234,7 @@ def _windows_platform_data():
|
||||
os_release = platform.release()
|
||||
kernel_version = platform.version()
|
||||
info = salt.utils.win_osinfo.get_os_version_info()
|
||||
net_info = salt.utils.win_osinfo.get_join_info()
|
||||
server = {'Vista': '2008Server',
|
||||
'7': '2008ServerR2',
|
||||
'8': '2012Server',
|
||||
@ -1268,7 +1269,8 @@ def _windows_platform_data():
|
||||
'serialnumber': _clean_value('serialnumber', biosinfo.SerialNumber),
|
||||
'osfullname': _clean_value('osfullname', osinfo.Caption),
|
||||
'timezone': _clean_value('timezone', timeinfo.Description),
|
||||
'windowsdomain': _clean_value('windowsdomain', systeminfo.Domain),
|
||||
'windowsdomain': _clean_value('windowsdomain', net_info['Domain']),
|
||||
'windowsdomaintype': _clean_value('windowsdomaintype', net_info['DomainType']),
|
||||
'motherboard': {
|
||||
'productname': _clean_value('motherboard.productname', motherboard['product']),
|
||||
'serialnumber': _clean_value('motherboard.serialnumber', motherboard['serial']),
|
||||
|
@ -18,6 +18,7 @@ from __future__ import absolute_import, unicode_literals, print_function
|
||||
import ctypes
|
||||
import logging
|
||||
import time
|
||||
import platform
|
||||
from datetime import datetime
|
||||
|
||||
# Import salt libs
|
||||
@ -513,11 +514,28 @@ def get_system_info():
|
||||
|
||||
salt 'minion-id' system.get_system_info
|
||||
'''
|
||||
def byte_calc(val):
|
||||
val = float(val)
|
||||
if val < 2**10:
|
||||
return '{0:.3f}B'.format(val)
|
||||
elif val < 2**20:
|
||||
return '{0:.3f}KB'.format(val / 2**10)
|
||||
elif val < 2**30:
|
||||
return '{0:.3f}MB'.format(val / 2**20)
|
||||
elif val < 2**40:
|
||||
return '{0:.3f}GB'.format(val / 2**30)
|
||||
else:
|
||||
return '{0:.3f}TB'.format(val / 2**40)
|
||||
|
||||
# Connect to WMI
|
||||
pythoncom.CoInitialize()
|
||||
conn = wmi.WMI()
|
||||
|
||||
# Lookup dicts for Win32_OperatingSystem
|
||||
os_type = {1: 'Work Station',
|
||||
2: 'Domain Controller',
|
||||
3: 'Server'}
|
||||
pythoncom.CoInitialize()
|
||||
conn = wmi.WMI()
|
||||
|
||||
system = conn.Win32_OperatingSystem()[0]
|
||||
ret = {'name': get_computer_name(),
|
||||
'description': system.Description,
|
||||
@ -535,12 +553,73 @@ def get_system_info():
|
||||
'system_drive': system.SystemDrive,
|
||||
'os_version': system.Version,
|
||||
'windows_directory': system.WindowsDirectory}
|
||||
|
||||
# lookup dicts for Win32_ComputerSystem
|
||||
domain_role = {0: 'Standalone Workstation',
|
||||
1: 'Member Workstation',
|
||||
2: 'Standalone Server',
|
||||
3: 'Member Server',
|
||||
4: 'Backup Domain Controller',
|
||||
5: 'Primary Domain Controller'}
|
||||
warning_states = {1: 'Other',
|
||||
2: 'Unknown',
|
||||
3: 'Safe',
|
||||
4: 'Warning',
|
||||
5: 'Critical',
|
||||
6: 'Non-recoverable'}
|
||||
pc_system_types = {0: 'Unspecified',
|
||||
1: 'Desktop',
|
||||
2: 'Mobile',
|
||||
3: 'Workstation',
|
||||
4: 'Enterprise Server',
|
||||
5: 'SOHO Server',
|
||||
6: 'Appliance PC',
|
||||
7: 'Performance Server',
|
||||
8: 'Maximum'}
|
||||
system = conn.Win32_ComputerSystem()[0]
|
||||
ret.update({'hardware_manufacturer': system.Manufacturer,
|
||||
'hardware_model': system.Model,
|
||||
'processors': system.NumberOfProcessors,
|
||||
'processors_logical': system.NumberOfLogicalProcessors,
|
||||
'system_type': system.SystemType})
|
||||
# Get pc_system_type depending on Windows version
|
||||
if platform.release() in ['Vista', '7', '8']:
|
||||
# Types for Vista, 7, and 8
|
||||
pc_system_type = pc_system_types[system.PCSystemType]
|
||||
else:
|
||||
# New types were added with 8.1 and newer
|
||||
pc_system_types.update({8: 'Slate', 9: 'Maximum'})
|
||||
pc_system_type = pc_system_types[system.PCSystemType]
|
||||
ret.update({
|
||||
'bootup_state': system.BootupState,
|
||||
'caption': system.Caption,
|
||||
'chassis_bootup_state': warning_states[system.ChassisBootupState],
|
||||
'chassis_sku_number': system.ChassisSKUNumber,
|
||||
'dns_hostname': system.DNSHostname,
|
||||
'domain': system.Domain,
|
||||
'domain_role': domain_role[system.DomainRole],
|
||||
'hardware_manufacturer': system.Manufacturer,
|
||||
'hardware_model': system.Model,
|
||||
'network_server_mode_enabled': system.NetworkServerModeEnabled,
|
||||
'part_of_domain': system.PartOfDomain,
|
||||
'pc_system_type': pc_system_type,
|
||||
'power_state': system.PowerState,
|
||||
'status': system.Status,
|
||||
'system_type': system.SystemType,
|
||||
'total_physical_memory': byte_calc(system.TotalPhysicalMemory),
|
||||
'total_physical_memory_raw': system.TotalPhysicalMemory,
|
||||
'thermal_state': warning_states[system.ThermalState],
|
||||
'workgroup': system.Workgroup
|
||||
})
|
||||
# Get processor information
|
||||
processors = conn.Win32_Processor()
|
||||
ret['processors'] = 0
|
||||
ret['processors_logical'] = 0
|
||||
ret['processor_cores'] = 0
|
||||
ret['processor_cores_enabled'] = 0
|
||||
ret['processor_manufacturer'] = processors[0].Manufacturer
|
||||
ret['processor_max_clock_speed'] = six.text_type(processors[0].MaxClockSpeed) + 'MHz'
|
||||
for system in processors:
|
||||
ret['processors'] += 1
|
||||
ret['processors_logical'] += system.NumberOfLogicalProcessors
|
||||
ret['processor_cores'] += system.NumberOfCores
|
||||
ret['processor_cores_enabled'] += system.NumberOfEnabledCore
|
||||
|
||||
system = conn.Win32_BIOS()[0]
|
||||
ret.update({'hardware_serial': system.SerialNumber,
|
||||
'bios_manufacturer': system.Manufacturer,
|
||||
|
@ -7,9 +7,11 @@ from __future__ import absolute_import, print_function, unicode_literals
|
||||
|
||||
# Import Third Party Libs
|
||||
import ctypes
|
||||
HAS_WIN32 = True
|
||||
try:
|
||||
from ctypes.wintypes import BYTE, WORD, DWORD, WCHAR
|
||||
HAS_WIN32 = True
|
||||
import win32net
|
||||
import win32netcon
|
||||
except (ImportError, ValueError):
|
||||
HAS_WIN32 = False
|
||||
|
||||
@ -76,3 +78,22 @@ def get_os_version_info():
|
||||
'ProductType': info.wProductType}
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
def get_join_info():
|
||||
'''
|
||||
Gets information about the domain/workgroup. This will tell you if the
|
||||
system is joined to a domain or a workgroup
|
||||
|
||||
.. version-added:: 2018.3.4
|
||||
|
||||
Returns:
|
||||
dict: A dictionary containing the domain/workgroup and it's status
|
||||
'''
|
||||
info = win32net.NetGetJoinInformation()
|
||||
status = {win32netcon.NetSetupUnknown: 'Unknown',
|
||||
win32netcon.NetSetupUnjoined: 'Unjoined',
|
||||
win32netcon.NetSetupWorkgroupName: 'Workgroup',
|
||||
win32netcon.NetSetupDomainName: 'Domain'}
|
||||
return {'Domain': info[0],
|
||||
'DomainType': status[info[1]]}
|
||||
|
Loading…
Reference in New Issue
Block a user