HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/grains/__pycache__/core.cpython-310.pyc
o

�N�g��@s`dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZmZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZddlmZ ddlm!Z"zddlm#Z$Wne%y�dd	�Z&d
d�Z$Ynwdd
�Z'zddl(Z)dZ*Wne%y�dZ*Ynwe�+e,�Z-dZ.ej/j�0�r�ddl1Zzddl2Z2ddl3Z3ddl4Zddl5ZdZ.Wne%y�e-�6d�YnwdgZ7da8ej9j:j;ej9j:j<ej9j:j=ej9j>j?ej9j>j@ej9jAjBd�ZCeDed�ZEdZFdZGdd�ZHdd�ZIdd�ZJdd�ZKdd�ZLd d!�ZMd"d#�ZNd$d%�ZOd&d'�ZPd(d)�ZQd*d+�ZRd,d-�ZSd.d/�ZTd0d1�ZUd2d3�ZVd4d5�ZWd6d7�ZXd8d9�ZYd:d;�ZZd<d=�Z[d>d?�Z\d@dA�Z]dBdC�Z^dDdE�Z_dFdG�Z`dHdI�ZadJdK�Zbe�cdL�Zde�cdM�Zee�cdNejf�ZgidOdP�dQdR�dSdT�dUdV�dWdX�dYdY�dZd[�d\d]�d^d_�d`da�dbdc�ddde�dfdg�dhdg�didj�dkdj�dldm�idnd]�dodp�dqdr�dsdt�dudv�dwdx�dydx�dzd{�d|d}�d~d�d�d��d�d��d�d��d�d��d�d��d�d��d�d���d�d�i�Zhd�d�d�d��Zi�dd�d��Zjid�dX�d]dP�d_dP�dadP�d�dP�d�dP�d�dP�d�dP�d�dP�dcdP�djdP�dmdP�d�dP�dgdP�d�dP�d�dP�d�dP�id�dP�d�dP�d�dP�d�d��d�dX�d�d��d�d��d�d��d�d��d�d��d�d��d�d��d�d��dd��d�d��d�d��d�d���idTdV�dxdV�d�dV�d}dV�d�dV�dedP�d�dX�d�dX�d�dX�d�dX�d�dX�d{dX�dpdP�d[dX�d�dX�d�dX�d�dX��id�dX�d�dX�d�dX�d�dX�dtdt�d�dX�d�d��d�dX�d�dR�d�dX�d�dX�d�dP�d�dX�d�dX�d�dP�d�dX�d�dX��Zkd�dPiZld�dńZme�cdơZnd�dȄZod�dʄZpd�d̄Zqd�d΄Zrd�dЄZsd�d҄Ztd�dԄZud�dքZvd�d؄Zwd�dڄZxd�d܄Zyd�dބZzd�d�Z{d�d�Z|d�d�Z}d�d�Z~d�d�Zd�d�Z�d�d�Z�d�d�Z�d�d�Z�d�d�ZBd�d�Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d��d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d	�d
�Z��d�d�Z��d
�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z��d�d�Z�dS(a�
The static grains, these are the core, or built in grains.

When grains are loaded they are not loaded in the same way that modules are
loaded, grain functions are detected and executed, the functions MUST
return a dict which will be applied to the main grains dict. This module
will always be executed first, so that any grains loaded here in the core
module can be overwritten just by returning dict keys with the same value
as those returned here
�N)�EACCES�EPERM)�_clear_interfaces�_get_interfaces)�get_machine_identifier)�linux_distribution)�freedesktop_os_releasec	Gs�dddd�}d}|D]W}z@tjj�|��-}t�d�}|D]}|�|���}|r6t�dd|�	d��||�	d	�<qWd�W|S1sDwYW|St
ya}z	|j}WYd}~q
d}~wwt
|d
�d�
|����)aq
        Parse os-release and return a parameter dictionary

        This function will behave identical to
        platform.freedesktop_os_release() from Python >= 3.10, if
        called with ("/etc/os-release", "/usr/lib/os-release").

        See http://www.freedesktop.org/software/systemd/man/os-release.html
        for specification of the file format.
        �Linux�linux)�NAME�ID�PRETTY_NAMENz^([\w]+)=(?:'|")?(.*?)(?:'|")?$z
\\([$"\'\\`])z\1��zUnable to read files {}z, )�salt�utils�files�fopen�re�compile�match�strip�sub�group�OSError�errno�format�join)	Zos_release_files�retr�filename�ifile�regex�liner�error�r$�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/grains/core.py�_parse_os_release3s6

���
�
�
����r&cCs
tdd�S)Nz/etc/os-releasez/usr/lib/os-release)r&r$r$r$r%�_freedesktop_os_releaseY�
r'cCs
t�dS�N)r)�optsr$r$r%�__init__]r(r+TFzDUnable to import Python wmi module, some core grains will be missing�*)�cmd.run�cmd.retcode�cmd.run_allzsmbios.records�
smbios.get�
network.fqdns�unamer�cCs�i}|��D]K}|�d�}|�d�r|�d�d|d<|�d�r9|�d�d|d<|�d�d	|d
<|�d�|d<|�d�rQ||d
<t�d|�}|rQ|�d�|d<q|S)N�utf-8�Model� r�model�Junos�	osrelease�.r�osmajorrelease�osrelease_infozJUNOS OS Kernel�
kernelversionz\[(.*)\]�
kernelrelease)�
splitlines�decode�
startswith�splitr�searchr)�txt�showver�lZdecoded_lineZrelnor$r$r%�_parse_junos_showver�s 



�rGcCsbi}dtjvr zttjd�|d<Wn
tyd|d<Ynwtjjjdddd��d�|d	<|S)
z8
    Return some CPU information on Windows minions
    ZNUMBER_OF_PROCESSORS�num_cpusr�HKEY_LOCAL_MACHINEz.HARDWARE\DESCRIPTION\System\CentralProcessor\0ZProcessorNameString)Zhive�keyZvnameZvdata�	cpu_model)	�os�environ�int�
ValueErrorrrZwin_regZ
read_value�get��grainsr$r$r%�_windows_cpudata�s
���rScCsni}d}tj�|�r�tjj�|d���}d|d<|D]t}|�d�}t|�dks'q|d�	�}|d�	�}|dkr@|dd7<q|dkrKt
|�|d<q|d	krT||d
<q|dkr]||d
<q|dkrh|��|d
<q|dkrs|��|d
<q|dkr�|�d�d|d
<d|d<q|dkr�||d
<qWd�n1s�wYd|vr�d|d<d
|vr�d|d
<d
|vr�g|d
<|S)z7
    Return some CPU information for Linux minions
    �
/proc/cpuinfo�rrrH�:r�	processorz# processorsZ	vendor_idrKz
model name�flags�	cpu_flags�FeaturesZ	Processor�-ZcpuN�Unknown)rL�path�isfilerrrrrB�lenrrN)rRZcpuinfo�_fpr"�compsrJ�valr$r$r%�_linux_cpudata�sL



���1rccCs�t�dd�dur
iSt�dd�duriStjj�d�}|s$t�d�iSgd�}d}g}zYtd	|�d
��}i}d}|�	�}|�
d�|D]7}|dkr]|�dd���|vrZ|�
|�i}qEt�
d
|�rt|�dd�\}	}
|
��||	��<qEd}t�d|�qE|r�t�d�Wn	ty�Ynwg}|D]%}t�d|d���}
d}|D]
}||
vr�|}nq�|�
||dd��q�i}t|�|d<||d<|S)�Z
    num_gpus: int
    gpus:
      - vendor: nvidia|amd|ati|...
        model: string
    �enable_lspciTFZenable_gpu_grains�lspcizTThe `lspci` binary is not available on the system. GPU grains will not be available.�ZnvidiaZamdZatiZintelzcirrus logic�vmwareZmatroxZaspeed)z
3d controllerzdisplay controllerzprocessing acceleratorszvga compatible controllerr-z -vmm�ZClassz
^\w+:\s+.*rVrzUnexpected lspci output: '%s'z�Error loading grains, unexpected linux_gpu_data output, check that you have a valid shell configured and permissions to run lspci commandz[^A-Za-z0-9]ZVendor�unknownZDevice��vendorr7�num_gpus�gpus)�__opts__rPrrr]�which�log�debug�__salt__r?�append�lowerrrrBr�warningrr_)rf�
known_vendorsZgpu_classesZdevsZ	lspci_outZcur_devr#Z
lspci_listr"rJrbrnZgpuZvendor_stringsrl�namerRr$r$r%�_linux_gpu_datash�


����rycCs�gd�}g}z0tdd�}|��D]#}|D]}t�d|�d�|tj�}|r3|�|�d�|�d�d��qqWn	ty?Ynwi}t|�|d	<||d
<|S)rdrgr-zpcictl pci0 listz	[0-9:]+ (z) (.+) \(VGA .+\)rrrkrmrn)	rsr?rr�
IGNORECASErtrrr_)rwrn�
pcictl_outr"rlZvendor_matchrRr$r$r%�_netbsd_gpu_data[s2�������r|c	Cs�g}z1tdd�}|��D]$}|�d�\}}}|��dkr1|�d�\}}}|��}|�||d��q
Wn	ty<Ynwi}t|�|d<||d<|S)	rdr-z"system_profiler SPDisplaysDataType�: z
Chipset Modelr6rkrmrn)rsr?�	partitionrrurtrr_)	rnr{r"�	fieldname�_Zfieldvalrlr7rRr$r$r%�_osx_gpudata�s$���r�cCs&tjj�d�}tjj�d�}i}|r$|�|�d�|�d�|�d�d��|r3|ddkr3|�d	�|d
<|ddkrG|�d�|d
<|�d�|d<dd�|��D�}d|vrdt|dt�rd|d�d�|d<|ddkr�g|d<t	dd��
�D]}t�d|�}|r�|�
d��d�}|d�|�qv|ddkr�tj�d�r�g|d<tjj�dd��H}d}	|D];}|�d�r�d}	q�|	r�|�d�s�n)d|vr�|�d �}
|�d!�}|
d"kr�|d"kr�||
d|��d�}|d�|�q�Wd#�n1s�wYzt|d$�|d$<W|St�yd|d$<Y|Sw)%z5
    Return CPU information for BSD-like systems
    �sysctl�archz -n hw.ncpuz -n hw.machine� -n hw.model)rH�cpuarchrK�kernel�OpenBSD� -sr��Darwinz -n machdep.cpu.brand_stringrKz -n machdep.cpu.featuresrYcSsi|]\}}|td|��qS)r-)rs)�.0�k�vr$r$r%�
<dictcomp>��z _bsd_cpudata.<locals>.<dictcomp>r6�NetBSDr-zcpuctl identify 0z#cpu[0-9]:\ features[0-9]?\ .+<(.+)>r�,�FreeBSDz/var/run/dmesg.bootrUFzCPU: TrZ�<�>rNrH)rrr]rp�update�items�
isinstance�strrBrsr?rrr�extendrLr^rrrA�findrNrO)�osdatar�r�ZcmdsrRr"Z	cpu_match�flagr`Zcpu_here�start�endr$r$r%�_bsd_cpudata�sh	���



���
�r�cCs�i}g|d<tdd�|d<d}ttd|dd����|d<d	}td|���D]}t�d
|�}|r9|�d�|d<q(d
}td|���D]}t�d|�}|r\|�d���}|d�|�qD|S)z=
    Return the CPU information for Solaris-like systems
    rYr-z
isainfo -kr�z/usr/sbin/psrinfo 2>/dev/nullT�Zpython_shellrHzkstat -p cpu_info:*:*:brandz(\w+:\d+:\w+\d+:\w+)\s+(.+)rrKz
isainfo -n -vz^\s+(.+)r)rsr_r?rrrrBr�)rRZpsrinfoZ
kstat_infor"rZisainforYr$r$r%�_sunos_cpudata�s*	���r�cCs�i}tjj�d�}|rEtd|��tj}dD]+\}}dd�|fD�D]}|�|�}|rAt|�	��dkrA|�
d����dd�||<q#q|St
�d	�|S)
z0
    Return CPU information for AIX systems
    �prtconfr-))r�z"(?im)^\s*Processor\s+Type:\s+(\S+))rYz%(?im)^\s*Processor\s+Version:\s+(\S+))rKz2(?im)^\s*Processor\s+Implementation\s+Mode:\s+(.*))rHz*(?im)^\s*Number\s+Of\s+Processors:\s+(\S+)cS�g|]}t�|��qSr$�rr�r�rUr$r$r%�
<listcomp>�z _aix_cpudata.<locals>.<listcomp>r�'ri�,The 'prtconf' binary was not found in $PATH.)rrr]rprsrL�lineseprCr_�groupsrr�replacerqr#)rR�cmd�data�dest�	regstringr!�resr$r$r%�_aix_cpudatas	
��
�r�cCs�ddd�}d}tj�|�rftjj�|d��I}|D]=}|�d��d�}t	|�dks)q|d�
�dkr?t|d��d�d	|d
<|d�
�dkrUt|d��d�d	|d<qWd
�|S1sawY|S)z>
    Return the memory information for Linux-like systems
    r��	mem_total�
swap_totalz
/proc/meminforU�
rVrZMemTotal�r�Z	SwapTotalr�N)rLr]r^rrrr�rstriprBr_rrN)rRZmeminfor r"rar$r$r%�_linux_memdata"s$
��
��r�cCs�ddd�}tjj�d�}|r]td|�d��}td|�d����d�dd	�}|�d
�r0d}n|�d�r8d
}n|�d�r?d}t|dd��|}t	|�dd|d<t	|�dd|d<|S)�<
    Return the memory information for BSD-like systems
    rr�r�r-z -n hw.memsizez -n vm.swapusagerr�r:�Kr��M��Gi@N���r�r�)
rrr]rprsrBr��endswith�floatrN)rRr��memr�Z_powerr$r$r%�_osx_memdata8s&
��


r�cCs�ddd�}tjj�d�}|rmtd|�d��}|ddkr+|�d�r+td|�d	��}t|�d
d
|d<|ddvrZtjj�d
�}td|�d��}|dkrRd}n|�d�d}n	td|�d��}t|�d
d
|d<|S)r�rr�r�r-z -n hw.physmemr�r�r[z -n hw.physmem64r�r��r�r��swapctlz -skzno swap devices configuredr6rz -n vm.swap_totalr�)rrr]rprsrArNrB)r�rRr�r�r��	swap_datar�r$r$r%�_bsd_memdataSs 
r�c	Cs�ddd�}d}td|dd���D]!}|�d�}|d��dkr2|d	��d
kr2t|d���|d<qtjj�d
�}td|�d����}zt|ddd��}t|ddd��}||d}Wnt	yld}Ynw||d<|S)z>
    Return the memory information for SunOS-like systems
    rr�z/usr/sbin/prtconf 2>/dev/nullr-Tr�r6�Memoryrzsize:rr��swapr����Nr����r�r�)
rsr?rBrrNrrr]rprO)	rRr�r"ra�swap_cmdr�Z
swap_availZ	swap_usedr�r$r$r%�_sunos_memdatams$

 ��r�cCsddd�}tjj�d�}|rDtd|dd���D]*}dd�|���d	�D�}t|�d
krBd|dvrBd|d
vrBt	|d
�|d<nqnt
�d�tjj�d�}|rtd|�d����}zt	|d�t	|d�d}Wntyxd}Ynw||d<|St
�d�|S)z7
    Return the memory information for AIX systems
    rr�r�r-Tr�cSsg|]}|r|�qSr$r$�r��xr$r$r%r���z _aix_memdata.<locals>.<listcomp>r6rr�ZSizerr�r�r�r�r�i����r3Nr�z)The 'swap' binary was not found in $PATH.)
rrr]rprsr?rrBr_rNrqr#rO)rRr�r"rar�r�r�r$r$r%�_aix_memdata�s,
$�
 �
�r�cCs(ddi}t��d}t|d�|d<|S)z;
    Return the memory information for Windows systems
    r�rZ	TotalPhysr�)�win32apiZGlobalMemoryStatusExrN)rRZ	tot_bytesr$r$r%�_windows_memdata�sr�cCs�ddi}|ddkr|�t��|S|ddvr!|�t|��|S|ddkr/|�t��|S|ddkr=|�t��|S|ddkrK|�t��|S|dd	krYtrY|�t��|S)
z4
    Gather information about the system memory
    r�rr�r	)r�r�r�r��SunOS�AIX�Windows)r�r�r�r�r�r��HAS_WMIr�)r�rRr$r$r%�_memdata�s&�	����r�cCs�i}tjj�d�}|r?td|�d��tj}t�d�g}|D]}|�	|�}|r<t
|���dkr<|�d��
�|d<|Sq|St�d�|S)z9
    Parse the output of lsattr -El sys0 for os_uuid
    Zlsattrr-z	 -El sys0z(?im)^\s*os_uuid\s+(\S+)\s+(.*)rZ
machine_idz+The 'lsattr' binary was not found in $PATH.)rrr]rprsrLr�rrrCr_r�rrrqr#)rRr�r��uuid_regexesr!r�r$r$r%�_aix_get_machine_id�s
�
�r�cCs�t�}|ddkr|Sd|d<|�dd�}|durd}|�dd�}|dur'd}|�d	d�}|dur3d}d
|vr=d|d<|Sd|vrGd
|d<|Sd|vrQd|d<|Sd|vrcd|d<d|vrad|d<|Sd|vrmd|d<|Sd|vrwd|d<|Sd|vr�d|d<d|d<|Sd|vr�d|d<d|d<|Sd|vr�d|d<|Sd|vr�d|d<|Sd|vr�d|vr�d|d<|Sd|vr�d|d<|Sd|vr�d|d<|Sd|vr�d|d<d |d<|S)!�R
    Returns what type of virtual hardware is under the hood, kvm or physical
    r�r��physical�virtual�manufacturerriN�productname�
biosstring�QEMU�kvmZVRTUAL�HyperVzA M I�	VirtualPC�Xen�HVM domU�virtual_subtypeZAMAZONZEC2�BochsZoVirt�RHEV Hypervisor�rhev�
VirtualBox�VMware�	Microsoft�Virtual Machine�	OpenStack�	ParallelszCloudStack KVM HypervisorZ
cloudstack)�dictrP)r�rRr��product_nameZbios_stringr$r$r%�_windows_virtual�sx)�'�%�!�������
���r�c"	s�d|�dd�i}d}gd�}tjj��s$|d|vr$tjj�d�r$dg}t�dd�dur7tj�	d	�r7|d
g7}|d|vr?d}t
rS|ddkrSd
t��vrSd|d<|St�}|D�]�}g}|ddkrid}dg}n<|ddkr�tjj�d�}|r�zt
d|�}Wntjjy�|�|�Ynw|d�d�r�d}n
d}|�d�nd}tjj�|�}	|	s�qXd�|	d�|��}	z%t
d|	�}|ddkr�tjj��s�d|	vs�d|	vr�WqX|�|�WqXWntjjy�tjj��r�YqX|�|�YqXw|d}
|dk�r3|
��}d|v�rd|d<d |v�rd|d<d!|v�rd"|d<d#|v�r'd"|d<d$|v�r0d%|d<�n%|dk�r�|
d&v�rD|
|d<�nd!|
v�rPd"|d<�nd'|
v�r\d(|d<�n�d)|
v�rld*|d<d+|d,<�n�d-|
v�r|d*|d<d.|d,<�n�d/|
v�r�d0|d<d1|d,<�n�qX|dk�r|
��D]g}|d2v�r�||d<n[d)|v�r�d*|d<d+|d,<nLd!|v�r�d"|d<nAd |v�r�d|d<n6d3|v�r�d4|d<n+|d5k�r�d6|d<n |d7k�r�d8|d<d9|d,<n|d:k�r�d8|d<d;|d,<n�q��nW|d<k�r�d=|
v�rd6|d<d>|
v�rd6|d<d?|
v�r!d6|d<d@|
v�r*d6|d<dA|
v�r4dB|d<n\dC|
v�rBd6|d<dD|d,<nNdE|
v�rPd6|d<dF|d,<n@d%|
v�rZd%|d<n6d"|
v�rdd"|d<n,dG|
v�rsdH|
v�rsd(|d<ndI|
v�r}d|d<ndJ|
v�r�d6|d<n	dK|
v�r�d6|d<n�|d
k�r�|
��}
d!|
v�r�d"|d<nd$|
v�r�d%|d<ndL|
v�r�d6|d<n	dM|
v�r�d6|d<n�|dk�r�|
���dN�d}
d!|
v�r�d"|d<nd$|
v�r�d%|d<ndL|
v�r�d6|d<n	dO|
v�r�d6|d<n]|dk�rW|
dPk�r0dQ|d<g}dRD]}dS�||�}t
dT|��}|dUk�r&|�|��q
|�r/||d,<n%|
dVk�r>d|d<dW|d,<n|
dXk�rLd|d<d|d,<n	|
d!k�rUd"|d<nqXdY}tjj}tjj�dZ�}|d|v�rtj�d[��r�zt�d\�}t�d]�}||k�r�d^|d,<Wn
t�y�Ynw|d_��r�tj�d`��r�da|d<ntj�db��r�dc|d<|�d
�|�d<�tj�dd��rtjj�dd��A}t� de�}|D]1}|�!|�"dN��}|�r�t#|�$�d�dk�r�dc|d<�q�|�r�t#|�$�d�dk�r�da|d<�q�Wdf�n	1�swY|dg��s |dh��s |di��r�tj�dj��r,dk|d,<nf|�dldm�dnk�r:do|d,<nXtj�dp��rrt�%dptj&��rrtjj�dp��}dq|�'�v�r]dr|d,<ndk|d,<Wdf�n	1�slwYn |dh��r�tj�ds��r�dr|d,<ndtt
dTdu���v�r�dr|d,<dv|�d,dm���v�r�dw|d<tj�dx��r�tjj�dxdy��}dz|�'�v�r�d6|d<Wdf�n	1�s�wYtj�d{��rKz_tjj�d{d|��L}tjj(j)|�'�d}d~�}
d%|
v�r�d%|d<n/d|
v�rd6|d<dF|d,<n!d�|
v�rd6|d<dD|d,<nd�|
v�rd�|d<n	dA|
v�r!dB|d<Wdf�n	1�s,wYWnt*�yAt+�,d��Yn
t�yJYnwtj�d���r�zUtjj�d�dy��}|�'��Wdf�n	1�skwYd��v�r~d*|d<d+|d,<n(d��v�r�d�|d,<nd��v�r�d�|d,<nt-�fd�d��d�D���r�d*|d<d�|d,<Wn
t�y�Ynwd,|v�s�|d,d+k�rtj�d���rz/tjjjd�dyd�d~��}|�'��Wdf�n	1�s�wYd��v�r�d*|d<d+|d,<W�net�y�Y�n[w�nX|dd�k�r�tjj�d��}|�rzt
dT|�d���}t
dT|�d���}|�.d"��r/d"|d<|�.d%��r9d%|d<|�.d���rL|�d|��|d,<dw|d<|�.d���r\|�.d���r\d(|d<|�.d���rfd�|d<|�.d���rpd6|d<|�.d1��rzd0|d<|�r�t
dT|�d���}t
dT|�d���}
t
dT|�d���}dB|v�r�dB|d<n	dz|
v�r�d6|d<|d�k�r�d�|d,<n�|dd�k�r�d�|v�r�|d�d�v�r�d6|d<|d�d�k�r�d�|d<n�|dd�k�r-|�r,dzt
dT|�d���v�r�d6|d<ngd�t
dT|�d���v�rdr|d<nVd"t
dT|�d���v�rd"|d<nEt
dT|�d���dwk�r,tj�d���r,dk|d,<n-|ddk�rZtjj�d��}|�rOt
dT|��} | d�k�rNd|d<ntj�d���rZd|d<|�d,��rk|ddk�rkd|d<|dd�v�r�tjj�d<�}!|!�r�t
d|!d�d�gdd��}|d}
d�|
v�r�|ddwk�r�d0|d<d1|d,<tj!d�|
tj/d��}|�r�d�|d��d��|d,<ntj!d�|
tj/d���r�d1|d,<|D]}t+j0d�|dd���q�|S)�r�r�r�)r�)�systemd-detect-virt�	virt-what�	dmidecoder�r�reTz
/proc/bus/pcirfr$r	zBrandZ virtual linux�zoner�Zsystem_profilerZSPDisplaysDataTyper��virtinfor/�stdoutz
not supportedZprtdiagz-c current list -H -o namez{} {}r6�retcoderr�Z0x1ab8r�Z	parallelsrhr�Z0x15adZ
virtualboxr�)�qemur�Zoracle�xenZbochs�chroot�umlzsystemd-nspawnZ	microsoftr�Zlxc�	containerZLXCr�ZpodmanZPodman�amazonZNitroz
Amazon EC2)r�r�r�r�Zhypervr�z
ibm_power-kvmr�zibm_power-lpar_shared�LPARZsharedzibm_power-lpar_dedicatedZ	dedicatedr�zVendor: QEMUzManufacturer: QEMUz
Vendor: BochszManufacturer: BochsZBHYVEZbhyvezManufacturer: oVirtZovirtzProduct Name: RHEV Hypervisorr�z: Microsoftr�zParallels SoftwarezManufacturer: GooglezVendor: SeaBIOSr�Zvirtior�zjoyent smartdc hvmzlogical-domainZLDOM)Zcontrol�io�rootZservicez%{} -c current get -H -o value {}-roler-�trueznon-global-zonez
non-globalzkernel-zone)r	zHP-UXr�z/proc�/z/proc/1/root/.r�z/proc/vzz/proc/vz/version�openvzhnz/proc/vz/veinfoZopenvzvez/proc/self/statusz^envID:\s+(\d+)$Nz
/proc/sys/xenz/sys/bus/xenz	/proc/xenz/proc/xen/xsd_kvazXen Dom0r�rir�zXen HVM DomUz/proc/xen/capabilitiesZ	control_dzXen PV DomUz/sys/bus/xen/drivers/xenconsolezxen:ZdmesgZdomr�rTrUzQEMU Virtual CPUz(/sys/devices/virtual/dmi/id/product_name�rbr���errorsr�z
oVirt NodeZGoogleZgce�DThe content in /sys/devices/virtual/dmi/id/product_name is not validz/proc/1/cgroupz:/lxc/z:/kubepods/Z
kubernetesz:/libpod_parent/Zlibpodc3s�|]}|�vVqdSr)r$r��Zfhr_contentsr$r%�	<genexpr>�s
��
�z_virtual.<locals>.<genexpr>)z:/system.slice/dockerz	:/docker/z:/docker-ce/ZDockerz/proc/1/environ�ignorez
container=lxcr��kenvz smbios.system.productz smbios.system.makerr�r�ZVirtualr�r�z -n hw.hv_vendorr�z -n security.jail.jailed�1�jailr�r�)r��Red HatZJoyentZvmmr�z -n machdep.cpu_brand�invalidz -n machdep.xen.suspendz -n machdep.dmi.system-vendorz -n machdep.idle-mechanismz/var/run/xenconsoled.pid�zonename�globalz/.SUNWnative)r�r�r�r�z-t�system)Zignore_retcodezManufacturer: Amazon EC2z.*Product Name: ([^\r\n]*).*�rXzAmazon EC2 (r�)z.*Version: [^\r\n]+\.amazon.*ziAlthough '%s' was found in path, the current user cannot execute it. Grains output might not be accurate.)�once)1rPrr�platform�
is_windowsr]rprorL�exists�	HAS_UNAMEr2�setrs�
exceptions�CommandExecutionError�addr�rtrrrur?rB�isdir�statrr^�discardrrrrrr�rNr��access�R_OK�read�stringutils�
to_unicode�UnicodeDecodeErrorrqrr�anyrA�DOTALL�info)"r�rRZ	skip_cmdsZ_cmdsZfailed_commandsZcommand�argsr�rr��outputZ	macoutputr"r7ZrolesZroleZsubtype_cmd�choicesr r�Z	self_rootZ	init_rootZstatus_fileZvz_reZvz_match�fhrr
�productZmakerZ	hv_vendorrrr�r�r$r
r%�_virtualsR

�
�
�
�
�













�








�






































�

��




�


��




���

�
���
	
����








�����
�






����
�
���



�
��
�
�
�
�
�
��
�r1c
Cs�i}zd|dvr|WSWnty|YSwzMi}dD]*}tjj�d|��d��}tjj�|�����||<Wd�n1sCwYqd�	|d|d	|d
�|d<|d|d	|d
g|d<Wnt
tfyqYnwd
dddddddddddddd�}zGtjj�dd��}tjj�|�����}Wd�n1s�wYg}|��D]\}}	t|d�d|>@r�|�
|	�q�||d<||d <W|St
tfy�Y|Sw)!zl
    Returns detailed hypervisor information from sysfs
    Currently this seems to be used only by Xen
    r�r�)�major�minor�extraz/sys/hypervisor/version/rUNz{}.{}{}r2r3r4Zvirtual_hv_versionZvirtual_hv_version_infoZwritable_page_tablesZwritable_descriptor_tablesZauto_translated_physmapZsupervisor_mode_kernelZpae_pgdir_above_4gbZmmu_pt_update_preserve_adZgnttab_map_avail_bitsZhvm_callback_vectorZhvm_safe_pvclockZ	hvm_pirqsZdom0Zgrant_map_identityZmemory_op_vnode_supportedZARM_SMCCC_supported)rrr�r3����	�
���
�z#/sys/hypervisor/properties/features�rZvirtual_hv_featuresZvirtual_hv_features_list)�KeyErrorrrrrr&r'r%rrrr�rNrt)
r�rR�version�fnr/Zxen_feature_table�featuresZenabled_features�bitZfeatr$r$r%�_virtual_hvsp���������
�
��rEcCs�i}d}|d|vrd|d<|S|ddkrd|d<|S|ddkr(d	|d<|S|�d
d�dkr6d
|d<|S|ddkrBd|d<|S|ddkrNd|d<|Sd|d<|S)z
    Return the ps grain
    )r�r�r��MacOSrLz	ps auxwwwZps�	os_family�Solarisz/usr/ucb/ps auxwwwr�ztasklist.exer�rirz�ps -fH -p $(grep -l "^envID:[[:space:]]*0\$" /proc/[0-9]*/status | sed -e "s=/proc/\([0-9]*\)/.*=\1=")  | awk '{ $7=""; print }'r�z/usr/bin/ps auxww�	NILinuxRTz!ps -o user,pid,ppid,tty,time,commz	ps -efHww�rP)r�rRZbsd_choicesr$r$r%�_psMs.��
�����rKc	Cs|dus|rtjd|tjd�rdSd|vr?tdd�D]}ztj||d�|WSty1Yqwt�d||�	d	d
��dSt�
d|�r^t�d|�sZt�d
|�sZtj
d|tjd�r\dS|St�
d|�rqtj
d|tjd�rodS|Stj
d|tjd�s�tj
d|tjd�r�dS|S)a!
    Clean out well-known bogus values.
    If it isn't clean (for example has value 'None'), return None.
    Otherwise, return the original value.

    NOTE: This logic also exists in the smbios module. This function is
          for use when not using smbios to retrieve the value.
    NZnoner�uuidrr6)rAz!HW %s value %s is an invalid UUIDr�r6zserial|part|versionz^[0]+$z[0]?1234567[8]?[9]?[0]?z2sernum|part[_-]?number|specified|filled|applicablezasset|manufacturerz3manufacturer|to be filled|available|asset|^no(ne|t)zto be filledzRun(known|specified)|no(t|ne)? (asset|provided|defined|available|present|specified))rrrz�rangerL�UUIDrOrq�tracer�rC)rJrbZuuidverr$r$r%�_clean_valuehsP	
�
�
���	��
��rPcCs�d}d}d|vr1t�d|�rd}n|�d�D]}t�d|�r |}t�d|�r(|}q|�d|��}n|�d�D]
}t�d	|�r@|}q6|}|d
vr_t��}ddd
ddd�}|dkr_||vr_||}|S)zF
    helper function for getting the osrelease grain
    :return:
    r\ri�Serverz8^Microsoft[^\d]+(Server|Datacenter|Standard|Essentials)$Z2019r6z\d+z^R\d+$z^(\d+(\.\d+)?)|Thin|Vista|XP$)r\�
2008Server�2008ServerR2�
2012Server�2012ServerR2Z
2016Server)�Vista�7�8z8.1�10r)rrrBr�release)�caption�product_typerArZ�item�
os_releaseZserverr$r$r%�_windows_os_release_grain�s<����r_cCsdtsiSi}tjj�����t��}z|��d}|�t	d|j
�t	d|j�d��Wnty@|�ddd��t
�d�Ynwz.|��d}t|j|jd�}|�t	d|j�t	d	|j�t	d
|j
�t	d|�t	d|j�d
��Wnty�|�dddddd
��t
�d�Ynwz|��d}|�t	d|j���t	d|j�t	d|j�d��Wnty�|�dddd��t
�d�Ynwz|��d}|�dt	d|j�i�Wnty�|�ddi�t
�d�Ynwz|��d}|�dt	d|j���i�Wnt�y|�ddi�t
�d�Ynwz|��d}|�dt	d|j�t	d|j�d�i�Wnt�yH|�dddd�i�t
�d�Ynw|�dt	dt �!��i�tjj"�#�}	|�t	d|	d �t	d!|	d"�d#��tjj"�$�}
|
d$dk�r�d%�%d&t&|
d$�g�}|�d't	d'|�i�n|�d'di�Wd�|SWd�|S1�s�wY|S)(z8
    Use the platform module for as much as we can.
    rr�r�)r�r�Nz1Computer System info not available on this system)r[r\r>�
osfullname�osmanufacturerr9�	osversion)r>r`rar9rbz2Operating System info not available on this system�biosversion�string�serialnumber)rcr�re)r�rcrez&BIOS info not available on this system�timezonez*TimeZone info not available on this systemrLz9Computer System Product info not available on this systemZmotherboardzmotherboard.productnamezmotherboard.serialnumber)r�rez-Motherboard info not available on this systemr=�
windowsdomainZDomain�windowsdomaintypeZ
DomainType)rgrhZServicePackMajorri�SPZ
osservicepack)'r�rrZwinapiZCom�wmiZWMIZWin32_ComputerSystemr�rPZManufacturerr5�
IndexErrorrqrvZWin32_OperatingSystemr_ZCaptionZProductTypeZVersionZ
Win32_BIOS�NamerZSerialNumberZWin32_TimeZoneZDescriptionZWin32_ComputerSystemProductrNruZWin32_BaseBoardZProductrrrrAZ
win_osinfoZ
get_join_infoZget_os_version_inforr�)rRZwmi_cZ
systeminfo�osinfor^ZbiosinfoZtimeinfoZ
csproductinfoZmotherboardinfoZnet_infor+Zservice_packr$r$r%�_windows_platform_data�s�
����

�
����	�

��	
�������������
��������	
���
�
��
�
��
rncCs�d}td|�}i}|��D]F}|�d�\}}}|��dkr'd}t||�||<|��dkr6d}t||�||<|��dkrEd	}t||�||<|��d
krTd}t||�||<q|S)z�
    Additional data for macOS systems
    Returns: A dictionary containing values for the following:
        - model_name
        - boot_rom_version
        - smc_version
        - system_serialnumber
    z"system_profiler SPHardwareDataTyper-r}z
Model NameZ
model_namezBoot ROM VersionZboot_rom_versionzSMC Version (system)Zsmc_versionzSerial Number (system)Zsystem_serialnumber)rsr?r~rrP)r��hardwarerRr"�
field_namer�Z	field_valrJr$r$r%�_osx_platform_data�s&	�rqcCs�dd�}i}|d�}|r+|�dd�}t|�dkr%|d|d<|d|d	<n|d|d	<|d
�}|r5||d<|d�}|r?||d<|S)
z�
    Additional data for Linux Devicetree subsystem - https://www.kernel.org/doc/html/latest/devicetree/usage-model.html
    Returns: A dictionary containing values for the following:
        - manufacturer
        - produtname
        - serialnumber
    cSszz2d|��}tj�|�r0tjjj|dd��}|���d�Wd�WS1s(wYWdSWdSt	y<YdSw)Nz/proc/device-tree/rU)�mode�)
rLr]r^rrrrr%r��	Exception)r]�loc�fr$r$r%�_read_dt_string�s
$����z8_linux_devicetree_platform_data.<locals>._read_dt_stringr7r�rrrr�r�z	system-idrez
serial-number�rBr_)rwrRr7�tmpZsystemid�serialr$r$r%�_linux_devicetree_platform_data�s 	
r{cC�dt�dd�iS)z
    Return the id
    �idri�rorPr$r$r$r%�id_�srz7[^\d]+ (?P<version>\d[\d.+\-a-z]*) \((?P<codename>.+)\)z#\d[\d.+\-a-z]* \((?P<codename>.+)\)z\W(?:gnu/)?linuxZ
redhatente�RedHatZ
gentoobaseZGentooZarcharmzArch ARMr�ZArch�debian�Debianr8Zraspbian�RaspbianZ
fedoraremiZFedoraZchapeauZChapeauZkororaZKororaZ	amazonamiZAmazonZalt�ALT�
enterpriseZOELZ
oracleservZ
cloudserveZ
CloudLinuxZ
cloudlinux�	almalinux�	AlmaLinuxZpidoraZ
scientificZScientificLinuxZsynology�Synology�nilrtrIZpoky�PokyZmanjaroZManjaroZ
manjarolinZ
univentionZ
Univention�antergosZAntergosZsles�SUSEZvoidZVoidZ
slesexpandZRES�	linuxmintZMintZneonzKDE neon�pop�Pop�rocky�RockyZ
alibabacloZAlinux�mendelZMendelZAstraLinuxCE�AstraLinuxSE))�astrazAstra Linux (Orel))r�zAstra Linux (Smolensk))r�zPop!_OScCsL||ftvrt||fSt�d|���}|�dd���dd�}t�||�S)a
    Derive the 'os' grain from the 'osfullname' grain

    For deriving the 'os' grain from the os-release data,
    pass NAME as 'osfullname' and ID as 'os_id'.

    The 'os' grain that Salt traditionally uses is a shortened
    version of the 'osfullname' grain.
    rir6Nr:)�_ID_AND_NAME_TO_OS_NAME_MAP�_REPLACE_LINUX_RErrr�ru�_OS_NAME_MAPrP)r`�os_idZ
distroname�	shortnamer$r$r%�_derive_os_grains

r��UbuntuZFedBerry�CentOSz
CentOS StreamZGoOSeZ
ScientificZOVSZXCPzXCP-ngZ	XenServerZSangomazVMware Photon OSZMandrakeZMandrivaZ	VMwareESXr�ZBluewhite64Z	BluewhiteZSlamd64Z	Slackware�SLES�SusezSUSE Enterprise ServerzSUSE  Enterprise ServerZSLEDZopenSUSE�
openSUSE LeapzopenSUSE TumbleweedZSLES_SAPzManjaro ARMZEndeavourOSZTrisquelZGCELZLinaroz
elementary OSZ
elementaryZDevuanZantiXZKaliz	Parrot OSZCumulusZDeepinZIDMSZFuntooZTurnKeyZOSMCZfedoracCs|tvrt|S|��Sr))�_OS_FAMILY_ID_MAP�
capitalize)�	family_idr$r$r%�_prettify_os_family�sr�zM^(DISTRIB_(?:ID|RELEASE|CODENAME|DESCRIPTION))=(?:'|")?([\w\s\.\-_]+)(?:'|")?c	Cs~dD]}ztd|�d|���dkWStjjyYqwzttdd|���d���dkWStjjy>Yd	Sw)
zK
    Does a binary exist in linux (depends on which, type, or whereis)
    )rpztype -apr.r6rr/zwhereis -b r�rF)rsrrrr_rB)�binaryZ
search_cmdr$r$r%�_linux_bin_exists�s � ��r�c
Cs�i}zMt�d�tjj�d��6}|D])}zt�|�d���	�dd�\}}Wn	t
y/Yqw|��|d|����<qWd�W|S1sHwYW|Styh}z
t�d|�WYd}~|Sd}~ww)Nz$Attempting to parse /etc/lsb-releasez/etc/lsb-releaser�rZlsb_z$Failed to parse /etc/lsb-release: %s)
rqrOrrrr�
_LSB_REGEXrr�r��AttributeErrorrur)rr r"rJ�value�excr$r$r%�_parse_lsb_release�s*
$�������r�cCsbdddd�}i}|pd�d�}t|�dkr�|dd	kr�|d
�d�rN|dd
�\|d<|d<|d<t|�d
kr;|d
nd|d<|�|d
d
d��|d<|St|�dkr}|d
dkr}dd�|dd�D�\|d<|d<|d<d|d<|�|d�|d<|St|�dkr�t|�dkr�|d
dkr�dd�|dd�D�\|d<|d<|d<|d<|�|d�|d<|S)a�
    Parse CPE_NAME data from the os-release

    Info: https://csrc.nist.gov/projects/security-content-automation-protocol/scap-specifications/cpe

    Note: cpe:2.3:part:vendor:product:version:update:edition:lang:sw_edition:target_sw:target_hw:other
          however some OS's do not have the full 13 elements, for example:
                CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"

    :param cpe:
    :return:
    zoperating systemroZapplication)�o�h�arirVr3r�cperrrr6rlr0rANZphase�part�z2.3cs� �|]}|dkr
|ndVqdS�r,Nr$r�r$r$r%r���
�z"_parse_cpe_name.<locals>.<genexpr>r5r7r=csr�r�r$r�r$r$r%r�r�)rBr_rArP)r�r�rr$r$r%�_parse_cpe_name�s2�
�
�$�
�r�c
Cs�d}z
t�d�d}W|St�yGz&tjjjdddd��}|���dd	��	�}Wd
�n1s4wYWntyEYY|Swztjj
�|d�}Wntyad
}t
�d�Ynw|d
ur�|�d
�r�d}tdd�|D��d}ztd}Wnty�d}YnwzStjj�|d��;}d}|�|���}	|	r�||	}	|D]}
|
|	vr�|
�d�}
|
}d}	nq�|	|d
�}|�|���}	|	s�Wd
�n1s�wYWY|SWY|Sty�}zt
�d||�WYd
}~Y|Sd
}~wwtjj
�d�|v�rd}Y|Stjj
�d�|v�rd}Y|Stjj
�d�|v�r&d}Y|S|dgk�r1d}Y|Sd|v�r;d}Y|St
�dd	�|��Y|Sw)z0
    Determine init system on Linux systems
    rjz/run/systemd/system�systemdz/proc/1/cmdlinerUrrrsr6Nrz)Unable to fetch data from /proc/1/cmdlinezbin/init)supstartssysvinitssystemdcss�|]}t|�VqdSr))r_r�r$r$r%r�s�z%_linux_init_system.<locals>.<genexpr>rZfile_buffer_sizeir�r4z%Unable to read from init_bin (%s): %sZsupervisordz	dumb-initZtiniZrunitz
/sbin/my_initz7Could not determine init system from command line: (%s))rLr!rrrrrr%r�rBr]rprkrqrvr��maxror@rur@r#rrr)Zinit_systemr/Zinit_cmdlineZinit_binZsupported_initsZedge_lenZbuf_size�fp_Zedge�bufr]r�r$r$r%�_linux_init_system�s�
9���3���
��� �"�"������

����r�c	Cs�i}d}z0t�d�ddl}|��}|��D]\}}|��}d�|�d�r'dnd|�}|||<qW||fStt	fyOd}t�d	�|�
t��Y||fSw)
a&
    Determine lsb_distrib_* grains if LSB data is available.

    Returns a (lsb_grain, has_error) pair. The lsb_grain
    dictionary is expected to have following keys on success:
     * lsb_distrib_codename
     * lsb_distrib_description
     * lsb_distrib_id
     * lsb_distrib_release
    Fz&Getting lsb_release distro informationrNzlsb_{}{}Zdistrib_riTz)lsb_release python bindings not available)rqrO�lsb_releaseZget_distro_informationr�rurrA�ImportError�	NameErrorr�r�)rRZ	has_errorr�rZrJr�Z	lsb_paramr$r$r%�_linux_lsb_distrib_data)s(
�
��
�r�cCs2|s|S|g|��}d|vsd|vrdS|dS)zI
    Return the family ID which is the oldest distribution ancestor.
    r��ubuntur��rB)r�Zid_likeZids_liker$r$r%�
_family_idPsr�cCsF|ddvr|�d�S|ddvr!t�|�dd��}|r!|�d�SdS)	ar
    Apply quirks for 'oscodename' grain for faulty os-release files

    Some distributions do not (fully) follow the os-release
    specification. This function bundles all required quirks
    for the 'oscodename' grain. To be on the safe side, only
    apply the quirks for allow-listed distributions. Better
    not set the codename instead of setting it wrong.
    r)r�Z
VARIANT_ID)r�r��VERSIONri�codenameN)rP�_VERSION_RErr)r^rr$r$r%�!_os_release_quirks_for_oscodenamebs


r�cCs0|ddvr|d��}t|�dkr|dSdS)ao
    Apply quirks for 'osrelease' grain for faulty os-release files

    Some distributions do not (fully) follow the os-release
    specification. This function bundles all required quirks
    for the 'osrelease' grain. To be on the safe side, only
    apply the quirks for allow-listed distributions. Better
    not set the release instead of setting it wrong.
    r)r�r
r5rNrx)r^�	test_strgr$r$r%� _os_release_quirks_for_osreleaseys

r�cCslt|d|�d��}t|d|d�t|�|�d�pt|�|d��|�d�p*t|�d�}dd�|��D�S)	a
    Transform the given os-release data to grains.

    The os-release file is a freedesktop.org standard:
    https://www.freedesktop.org/software/systemd/man/os-release.html

    The keys NAME, ID, and PRETTY_NAME are expected to exist. All
    other keys are optional.
    rZID_LIKEr�VERSION_CODENAME�
VERSION_ID)rLrG�
oscodenamer`r9cSsi|]	\}}|r||�qSr$r$)r�rJr�r$r$r%r��sz)_os_release_to_grains.<locals>.<dictcomp>)r�rPr�r�r�rr�r�)r^r�rRr$r$r%�_os_release_to_grains�s



�r�cCsxt�\}}t�d�zt�}|�t|��|ddvr"|dur"|WSWnty.i}Ynwd|vr6|d=t|||�S)a
    Determine distribution information like OS name and version.

    Return a grain dictionary with following keys:
     * os
     * os_family
     * oscodename
     * osfullname
     * osrelease

    This function might also return lsb_distrib_* grains
    from _linux_lsb_distrib_data().

    Most Linux distributions should ship a os-release file
    and this file should be the sole source for deriving the
    OS grains. To not cause regressions, only switch the
    distribution that has been tested.
    zBGetting OS name, release, and codename from freedesktop_os_releaser)r�r�r�r�r�r�r�r�Fr9)r�rqrOr'r�r�r�_legacy_linux_distribution_data)rR�
lsb_has_errorr^r$r$r%�_linux_distribution_data�s


��r�c
sh|�rj��dd����d�rd�d<�nVd�v�rjt�d�|r�d|vr,|d���d<d	|vr6|d	�d
<d|vrA|d�d<n
d
|vrK|d
�d<d|vr�t|d�}|s]t�d�n9|�dd���dvr�d�d<|�d�dkrwd�d<n
|�d�dkr�|d�d<|�d�r�|�d�dkr�|d�d
<d|vr�|d��dkr�|d
��}t	|�dkr�|d�d
<�n�t
j�d��rPt�d�d�d<d}d}t
jj�d��?}|D]4}d |��vr�d!�d<t�d"d|����d<q�d|��vr�t�d#d|�}q�d$|��v�rt�d#d|�}q�Wd%�n	1�swY|�d
<|�rD�d
d&|7<d'|}	�d�rD|	�dv�rD�dd(|	7<��d��sNd)�d<�nt
j�d*��r�t�d+�d,�d<t
jj�d*��-}
|
D]"}|��}|d-d.k�r�|d�d
<|d�d/d��d0d��d<�qjWd%�n	1�s�wYn�t
j�d1��r�t�d2�d3�d<t
jj�d1��8}
|
D]-}t�d4�}t�d5�}
|�|�}|
�|�}|d%u�r�|���d
<|d%u�r�|���d<�q�Wd%�n	1�s�wYnst
j�d6��rjt
j�d7��rjd8�d<t�d9�t
jj�d6d:��K}i}|D]'}z|�d;��d<�\}}Wnt�y4Y�qw|d=v�rA|�d>�||<�qt	|�dk�rPt�d?�n
d@jdPi|���dA<Wd%�n	1�sewYt�dB�dCdD�t�D�\}}}d�v�r���dd����dE��r�dE�d<n
��d|����d<dA�v�r�t�fdFdD�dGD���r���d
d%���d
|����dA<��dd��rt�fdHdD�dID���r�djd/dJdK�}t	|�dk�r|dJjd0dJdK�}�ddLk�r�|d-��d-���d<n|d-�d<��dd����p|�dM<dN�dMv�r|�dM<d�v�r&t�d��d<t��d�d��dO<�S)Qz�
    Legacy heuristics to determine distribution information.

    Most Linux distributions should ship a os-release file
    and this file should be the sole source for deriving the
    OS grains. See _linux_distribution_data.
    Zlsb_distrib_descriptionrir�zAntergos Linuxr`Zlsb_distrib_idz8Failed to get lsb_distrib_id, trying to parse os-releaserr�Zlsb_distrib_releaser��lsb_distrib_codenamer
ZCPE_NAMEz*Broken CPE_NAME format in /etc/os-release!rl)Zsuse�opensuser�rLr�ZLeapr�Z
TumbleweedrAr�rr�r5rz/etc/SuSE-releasez+Parsing distrib info from /etc/SuSE-releaser�r�z\(.+\)z[^0-9]Z
patchlevelNr:rir6zn.az/etc/altlinux-releasez/Parsing distrib info from /etc/altlinux-releaseZaltlinuxrr��(rz/etc/centos-releasez-Parsing distrib info from /etc/centos-releaser�z\d+\.\d+z(?<=\()(.*?)(?=\))z/etc.defaults/VERSIONz/etc.defaults/synoinfo.confr�z9Parsing Synology distrib info from /etc/.defaults/VERSIONrUr��=)ZmajorversionZminorversionZbuildnumber�"zUUnable to determine Synology version info. Please report this, as it is likely a bug.z+{majorversion}.{minorversion}-{buildnumber}r9zHGetting OS name, release, and codename from distro id, version, codenamecss �|]}|�d��d�VqdS)r�r�N)rr�r$r$r%rc	r�z2_legacy_linux_distribution_data.<locals>.<genexpr>r�c3� �|]}|��dd�vVqdS)r�riNrJ�r�rLrQr$r%rx	s
��
�)zCentOS Linux 7zCentOS Linux 8c3r�)rLriNrJr�rQr$r%r�	s�)r�r�r�r)�maxsplitr�r�rrGr$) rPrurArqrOrr�r#rBr_rLr]r^rrrrrrr�rrCrr�rOrvr�_linux_distributionr)r�r��_OS_FAMILY_MAP)rRr^r�r�r�rAZpatchr/r"Zpatchstrr raZfind_releaseZ
find_codenamerZr�r�ZsynoinforJrb�osnamer9r�Ztest_strg_2r$rQr%r��s4


��
�������
�����






�����
�
��������



��
r�cCs�|dkrtdd���S|dvrtjjj��S|dvrFi}tdd���D]}|�d�r=|�	�\}}}t
|���||��<q%t||jdd	�S|S)
z�
    Return the osarch grain

    This grain will be used for platform-specific considerations such
    as package management. Fall back to the given CPU architecture.
    r�r-zdpkg --print-architecture)r�r�)rIr�zopkg print-architecturer�T)rJ�reverse)
rsrrrZpkgZrpmZ
get_osarchr?rArBrN�sortedrP)rGr�Zarchinfor"r�r��priorityr$r$r%�_osarch�	s
�r�c
Cs�i}|�d�}t|�D]\}}|��sqt|�||<qt|�|d<zt|dd�|d<WntttfyAt�	d|d�Ynw|dvrI|}n|}d�
||dvrT|n|dd�|d	<|S)
z�
    Derive osrelease_info, osmajorrelease, and osfinger.

    Derive osrelease_info, osmajorrelease from given
    osrelease grain. Derive osfinger from os/osfullname and
    osrelease.
    r:r<rr;zcUnable to derive osmajorrelease from osrelease_info '%s'. The osmajorrelease grain will not be set.)r�r�r�r�ZMacr�z{}-{})r�r��osfinger)rB�	enumerate�isdigitrN�tuplerk�	TypeErrorrOrqrrr)rLr`r9rRr<�idxr��os_namer$r$r%�_osrelease_data�	s.
���r�cCs4dtdd�dki}td�rtdd���|d<|S)z"
    Return the selinux grain
    �enabledr.�selinuxenabledrZ
getenforcer-Zenforced)rsr�r)�selinuxr$r$r%�_selinux�	sr�cCs�d}d}ztdd�}Wnty!tjddd�||d�YSw|�d	�d
krP|�dd���}z|d
�d�rE|d
��d
}|d
}Wn	tyOYnw|dksX|dkr^t�d|�||d�S)z"
    Return the systemd grain
    Z	UNDEFINEDrir/zsystemctl --versionz/Exception while executing `systemctl --version`T)�exc_info)rArCr�rr�zsystemd rz7Unexpected output returned by `systemctl --version`: %s)	rsrtrqr#rPr?rArBrk)Zsystemd_versionZsystemd_featuresZsystemd_outputZsystemd_infor$r$r%�_systemd�	s6
������r�cCs�i}trt��d}ntj}||�d�dd�}d|d<|d<d�|�d�d	d	d
�|�d�d	d
d�|�d�d	dd�g�|d
<||d<|S)Nr5r�rZSmartOSrLr`r:�Trr3r�r8r9�osrelease_stamp)rrLr2rx�indexrrB)rR�uname_vr$r$r%�_smartos_os_data�	s��r�c
Csji}tjj�dd��}|��}Wd�n1swYzt�d�}|�|���\}}}}Wnt	yFd|d<|d<d|d<Y|Sw|durRd	�
||f�}tr[t�
�d
}ntj}||d<|d<|dvru|�|�ru||d<|S|dvr�g}	|	�|d
d��|	�|d
d��d�
|	�|d<||d<|Sg}	|	�|�|r�|	�|�d�
|	�|d<||d<|S)N�/etc/releaserUzz((?:Open|Oracle )?Solaris|OpenIndiana|OmniOS) (Development)?\s*(\d+\.?\d*|v\d+)\s?[A-Z]*\s?(r\d+|\d+\/\d+|oi_\S+|snv_\S+)?rHrLr`rir9r6r5)zOracle Solaris)ZOmniOSrr:r�)rrrrr%rrrCr�r�rrrLr2rxrArt)
rRr�Zrel_dataZ
release_rer�Zdevelopmentr;Zosminorreleaser�r9r$r$r%�_sunos_release
sT
��	�
��	�

r�c
Cs�dgd�}t��\|d<|d<|d<|d<|d<}tjj��rDd|d<d|d	<d|d
<d|d<ttjgd
�tjdd�j	�}|�
|��n8tjj��rhd|d<d|d<d|d<d|d<d|d
<d|d<d|d	<�ntjj��r�d|d
<d|d<|�
t
|��|�
t��|�
t��|�
t|��|�
t|��d|dvr�|d�dd�}|d�d�|d<n|d�d�}t|�D]\}}|��s�q�t|�||<q�t|�|d<dj|d
|dd�|d<d|d<|Stjj���r7td�r�t�d�t�|d<td��rtd ��rt�d!�t�|d"<t�d#�t�|d<|�
t ��|�
t!��|�
t"��t#j$�%d$��r5|�
t&���nE|dd%k�rod&|d<tjj�'��rP|�
t(��nt#j$�)d'��r^|�
t*��n	d(�|d�|d
<|�
t+���n
|dd)k�rd*|d
<d+|d<n�|dd,k�r�t,d-d.�}t,d-d/�}t,d-d0�}d1|d
<d1|d<|�d2|��|d	<||d<||d3<d4|d<|�
t-|��|�
t.��|�
t/��n�|dd5k�r�t,d-d6�}t,d-d7�}	t,d-d8�}d5|d
<d5|d<||d	<||d<|	|d9<|�
t0��n|ddk�rA|d|d<|d	<|d
<zt,d-d:��d;�d|d<Wntj1j2�y8|d�d;�d|d<Ynw|�
t-|��n;|dd<v�rr|d|d<|d
<|�
t-|��|d�d;�d|d<|dd=k�rq|�
t3��n
|d|d
<d>|d<t4|�5d�|�5d��|d?<|�
t
|��|�
t6|��|�
t7|��|�
t8|��|�
t|��|�5dd@��r�|�
t9|d
|d	|d��|S)Az:
    Return grains pertaining to the operating system
    r)rmrnr��nodenamer>r=r�r8r`rLr�rG)z
/usr/sbin/cli�showrAT)r��check�proxyr9r�rQr�Rr:r<z
{os}-{ver})rL�verr��initr�zAdding selinux grainsr�Z	systemctlZ	localectlzAdding systemd grainsr�zAdding init grainz/proc/device-treer�rHr�z
Unknown {}ZVMkernelZESXir�r�r-zsw_vers -productVersionzsw_vers -productNamezsw_vers -buildVersionrFr6�osbuildZlaunchdr�Zoslevelz
oslevel -rr2�osrelease_techlevelzfreebsd-version -ur[r�r�r\Zosarchri):rr2rr�is_junosrG�
subprocess�run�PIPEr�r��is_proxyrr�rnrSr�rKrB�lstripr�r�rNr�rZis_linuxr�rqrOr�r�r�r�rcryrLr]r r{�
is_smartosr�r^r�r�rsr�r�rqr�rrr|r�rP�_hw_datar1rEr�)
rRr�rEr<r�r�r9r�r�r�r$r$r%�os_dataD
s����
�





�
����rcCs�i}i|d<tjj��r|Szt��\|dd<|dd<Wnty3d|dd<d|dd<Ynwt|dd<d|dd<trtzt	j	�
tj�
����|dd<W|Stystjj��rptjd�d�|dd<Y|SY|Sw|S)	zB
    Provides
        defaultlanguage
        defaultencoding
    �locale_infoZdefaultlanguageZdefaultencodingrjZdetectedencodingrfr�mbcs)rrrr�locale�	getlocalertZ__salt_system_encoding__�_DATEUTIL_TZ�datetime�now�dateutil�tzZtzlocal�tznamer(r�timer@rQr$r$r%r�
s>�
���	���rcCszi}tjj��r
|St��|d<tdurtjj��atdur%t	�
d�dat|d<|d�d�ddd�\|d<|d	<|S)
a<
    Return fqdn, hostname, domainname

    .. note::
        On Windows the ``domain`` grain may refer to the dns entry for the host
        instead of the Windows domain to which the host is joined. It may also
        be empty if not a part of any domain. Refer to the ``windowsdomain``
        grain instead
    Z	localhostNz`Having trouble getting a hostname.  Does this machine have its hostname and domain set properly?zlocalhost.localdomain�fqdnr:r�host�domain)rrrr�socket�gethostname�__FQDN__�networkZget_fqhostnamerqr#r~rQr$r$r%�hostnames�$rcCs,i}tjj��r
|Sdtvrtd|d<|S)z%
    Return append_domain if set
    �
append_domain)rrrrro)Zgrainr$r$r%r@srcCsndgi}t�dtjj��s+tjj��s+tjj��s+tjj��s+tjj�	�s+tjj�
�r-dnd�r5td�}|S)z�
    Return all known FQDNs for the system by enumerating all interfaces and
    then trying to reverse resolve them (excluding 'lo' interface).
    To disable the fqdns grain, set enable_fqdns_grains: False in the minion configuration file.
    �fqdnsZenable_fqdns_grainsFTr1)rorPrrrrrZis_sunosZis_aixr�Z	is_darwinrs)�optr$r$r%rOs&
�
�
�
�
�
��

rcCstjj��riSi}tjjjdd�|d<tjjjdd�|d<t�d}tj	dftj
dffD]V\}}d|}|d	|s@g||<q-tj��}zt�
|d
|�}tdd�|D��||<Wq-ttfy�tj��|}|jd
kr}tddkr}t�d||||�g||<Yq-w|S)z+
    Return ip address and FQDN grains
    T)Zinclude_loopbackZipv4Zipv6r�4�6Zfqdn_ipZipvNcSsh|]}|dd�qS)r3rr$�r�r]r$r$r%�	<setcomp>}szip_fqdn.<locals>.<setcomp>r6Z__role�masterz�Unable to find IPv%s record for "%s" causing a %s second timeout when rendering grains. Set the dns or /etc/hosts for IPv%s to clear this.)rrrrrZip_addrsZ	ip_addrs6rr�AF_INET�AF_INET6r
�utcnow�getaddrinfo�listr�UnicodeError�secondsrorqrv)rZ_fqdnZsocket_typeZipv_numrJZ
start_timer+Ztimediffr$r$r%�ip_fqdnis6


�	�r'cCs�tjj��riSi}t�}|D]J}g}||�dg�D]
}d|vr(|�|d�q||�dg�D]
}d|vr>|�|d�q1||�dg�D]
}d|vrT|�|d�qG|||<qd|iS)z�
    Provide a dict of the connected interfaces and their ip addresses
    The addresses will be passed as a list for each interface
    �inet�address�inet6�	secondary�
ip_interfaces�rrrrrrPrt�r�ifaces�faceZ	iface_ipsr(r+r$r$r%r,�s(���
r,cC�tjj��riSi}t�}|D];}g}||�dg�D]
}d|vr(|�|d�q||�dg�D]}d|vrE|�d�dkrE|�|d�q1|||<qd|iS)z�
    Provide a dict of the connected interfaces and their ip4 addresses
    The addresses will be passed as a list for each interface
    r(r)r+�type�ip4_interfacesr-r.r$r$r%r3�� ��
r3cCr1)z�
    Provide a dict of the connected interfaces and their ip6 addresses
    The addresses will be passed as a list for each interface
    r*r)r+r2�ip6_interfacesr-r.r$r$r%r5�r4r5cCs8i}t�}|D]}d||vr||d||<qd|iS)z]
    Provide a dict of the connected interfaces and their
    hw addresses (Mac Address)
    Zhwaddr�hwaddr_interfaces)r)rr/r0r$r$r%r6�s�r6cCsxtjj��s
dtvriStj�d�rtjj�	d�}ntjj�	�}dD]}||vr3dd�||D�||<q"|r:d|iSiS)zP
    Parse the resolver configuration file

     .. versionadded:: 2016.3.0
    Zproxyminionz /run/systemd/resolve/resolv.conf)ZnameserversZip4_nameserversZip6_nameserversZsortlistcSsg|]}t|��qSr$)r�)r��ir$r$r%r��r�zdns.<locals>.<listcomp>�dns)
rrrrrorLr]rr8Zparse_resolv)ZresolvrJr$r$r%r8�s�r8cCst��dkr	t�St�S)zG
    Provide the machine-id for machine/virtualization combination
    r�)rrr��_get_machine_identifierr$r$r$r%�get_machine_idsr:cCsdt��iS)z#
    Current working directory
    �cwd)rL�getcwdr$r$r$r%r;sr;cCs0tjj�tj�dd����}||�tj	j
�d�S)z
    Return the path
    �PATHri)r]Z
systempath)rrr&r'rLrMrPrrBr]�pathsep)�_pathr$r$r%r]s�r]cCsdttj�iS)z#
    Return the Python version
    �
pythonversion)r$�sys�version_infor$r$r$r%r@$sr@cC�
dtjiS)z 
    Return the Python path
    �
pythonpath)rAr]r$r$r$r%rD-�
rDcCrC)z-
    Return the python executable in use
    �pythonexecutable)rA�
executabler$r$r$r%rF6rErFcCs*tj�tj�ttjj��}dtj�|�iS)z,
    Return the path of the salt module
    �saltpath)rLr]�abspathr�__file__�pardir�dirname)Z	salt_pathr$r$r%rH?srHcCsddlm}d|iS)z$
    Return the version of salt
    r��__version__�saltversion)�salt.versionrNrMr$r$r%rOIsrOcCs.zddl}d|��iWStyiYSw)z#
    Return the zeromq version
    rN�
zmqversion)�zmqZzmq_versionr�)rRr$r$r%rQTs�rQcCsddlm}dt|�iS)zH
    Return the version_info of salt

     .. versionadded:: 0.17.0
    r��__version_info__�saltversioninfo)rPrTr$rSr$r$r%rUbsrUc(Cs�tjj��riSi}|ddkr�tj�d�r�dddddd	d
dd�}|��D]q\}}tj�d|�}tj�|�r�z5tjj	�
|d
��#}tjjj|�
���dd�||<|dkr[|d��|d<Wd�n1sewYWq%tyyt�d�Yq%ty�}z|jtks�|jtkr�	WYd}~q%d}~wwq%|Stjj�ddg�du�r
tjj���s
|ddkr�|d�d��s
tdd�tdd�tdd�tdd�tdd�tdd�d�}d d!�|��D�}tdd�}|dur�|��|d<d"D]}	td|	�}	|	du�r
|	|d#<|Sq�|Stjj�d$g�du�rJd%d&d'd(�}
|
��D]%\}}td)d*|���}
|
d+d,k�rF|
d-�d.�}t||d/�||<�q"|S|dd0k�r�tjj�d1�}|�r�d2d3d4d5d6d7d8d9�}|��D]\}}td:|�d;|���}t||�||<�qi|S|dd<k�r�tjj�d=�}d>d?d@dAdBdC�}
|
��D]\}}td:|�dD|���}|�dE��s�t||�||<�q�|S|ddFk�r�tjj�d=�}dGdHdIdJdKdLdMd9�}|��D] \}}td)|�dD|���}
|
d+d,k�r�t||
d-�||<�q�|S|ddNk�r6dO|d%<tjj�d=�}dPdQi}
|
��D]\}}td:|�dR|���}|�dS��s2t||�||<�q|S|ddk�r�|d�d��r�dT}dUD]\}}tjj�|��rf|td:|�d;|���7}|dV7}�qIdWdX�dYD�}dZdX�d[D�}d\dX�d]D�}d^dX�d_D�}d`dX�daD�}dbdX�dcD�}dddX�deD�}dfdX�dgD�}dhdX�diD�}djdX�dkD�}|D]#}|�|�} | �r�t | �!��d/k�r�| �"d/����#dldT�|d#<n�q�|D]2}|�|�} | �rt | �!��d/k�r| �!�d,dm�\}!}"|!���#dldT�|dn<|"���#dldT�|do<�q�|D]4}|�|�} | �r>t | �!��d/k�r>| �!�d,dm�\}#}$|#���#dldT�|dp<|$���#dldT�|dq<n�q|D]#}|�|�} | �rdt | �!��d/k�rd| �"d/����#dldT�|d<n�qB|D]#}|�|�} | �r�t | �!��d/k�r�| �"d/����#dldT�|d%<n�qh|D]-}|�|�} | �r�t | �!��d/k�r�| �"d/����#dldT�}%|%�r�|%|dr<|%|dP<|S�q�|S|ddsk�rFtjj�dt�}|�rAtd:|��tj$}duD]/\}&}'dvdX�|'fD�D]!}|�|�} | �rt | �!��d/k�r| �"d/����#dldT�||&<�q�q�t%�&dw�g}|D]+}|�|�} | �r=t | �!��d/k�r=| �"d/����#dldT��dx�\|d%<|dP<|S�q|St�'dy�|S)za
    Get system specific hardware data from dmidecode

    Provides
        biosversion
        biosvendor
        boardname
        productname
        manufacturer
        serialnumber
        biosreleasedate
        uuid

    .. versionadded:: 0.9.5
    r�r	z/sys/class/dmi/idZbios_versionZbios_vendorZ
board_namer�Z
sys_vendorZ	bios_dateZproduct_uuidZproduct_serial)rc�
biosvendorZ	boardnamer�r��biosreleasedaterLrerr�rrLNr	r��smbiosr�r�Zsparcr0zbios-versionzbios-vendorzsystem-product-namezsystem-manufacturerzbios-release-datezsystem-uuid)rcrVr�r�rWrLcSsi|]\}}|dur||�qSr)r$)r�rJrbr$r$r%r��r�z_hw_data.<locals>.<dictcomp>)zsystem-serial-numberzchassis-serial-numberzbaseboard-serial-numberreZfw_printenvr�zserial#Z
DeviceDesc)r�rer�r/zfw_printenv r�rr�r�rr�r
zsmbios.bios.versionzsmbios.bios.vendorzsmbios.system.makerzsmbios.system.serialzsmbios.system.productzsmbios.bios.reldatezsmbios.system.uuid)rcrVr�rer�rWrLr-r6r�r�z
hw.versionz	hw.vendorz
hw.productzhw.serialnozhw.uuid)rcr�r�rerLz -n z value is not availabler�zmachdep.dmi.board-versionzmachdep.dmi.bios-vendorzmachdep.dmi.system-vendorzmachdep.dmi.system-serialzmachdep.dmi.system-productzmachdep.dmi.bios-datezmachdep.dmi.system-uuidr�z
Apple Inc.r�zhw.modelz -b z is invalidri))z/usr/sbin/prtdiagz-v)z/usr/sbin/prtconfz-vp)z/usr/sbin/virtinfoz-ar�cSr�r$r�r�r$r$r%r�
���z_hw_data.<locals>.<listcomp>)z-(?im)^\s*Chassis\s+Serial\s+Number\n-+\n(\S+)z(?im)^\s*chassis-sn:\s*(\S+)z#(?im)^\s*Chassis\s+Serial#:\s*(\S+)cSr�r$r�r�r$r$r%r�
rY)zF(?im)^\s*System\s+PROM\s+revisions.*\nVersion\n-+\nOBP\s+(\S+)\s+(\S+)z)(?im)^\s*version:\s*\'OBP\s+(\S+)\s+(\S+)cSr�r$r�r�r$r$r%r�&
rY)z0(?im)^\s*Sun\s+System\s+Firmware\s+(\S+)\s+(\S+)cSr�r$r�r�r$r$r%r�+
�
�)z(?im)^\s*Domain\s+UUID:\s*(\S+)cSr�r$r�r�r$r$r%r�/
rY)z.(?im)^\s*System\s+Configuration:\s*(.*)(?=sun)cSr�r$r�r�r$r$r%r�4
rY)z<(?im)^\s*System\s+Configuration:\s*.*?sun\d\S+[^\S\r\n]*(.*)z*(?im)^[^\S\r\n]*banner-name:[^\S\r\n]*(.*)z+(?im)^[^\S\r\n]*product-name:[^\S\r\n]*(.*)cSr�r$r�r�r$r$r%r�=
rY)z)(?im)Chassis\s+Serial\s+Number\n-+\n(\S+)z(?i)Chassis\s+Serial#:\s*(\S+)z(?i)chassis-sn:\s*(\S+)cSr�r$r�r�r$r$r%r�F
rY)zB(?im)System\s+PROM\s+revisions.*\nVersion\n-+\nOBP\s+(\S+)\s+(\S+)z%(?im)version:\s*\'OBP\s+(\S+)\s+(\S+)cSr�r$r�r�r$r$r%r�N
rY)z+(?i)Sun\s+System\s+Firmware\s+(\S+)\s+(\S+)cSr�r$r�r�r$r$r%r�S
rZ)z(?i)Domain\s+UUID:\s+(\S+)r�rrcrW�systemfirmwareZsystemfirmwaredater0r�r�))rez+(?im)^\s*Machine\s+Serial\s+Number:\s+(\S+))r[z#(?im)^\s*Firmware\s+Version:\s+(.*)cSr�r$r�r�r$r$r%r��
r�z (?im)^\s*System\s+Model:\s+(\S+)r�r�)(rrrrrLr]rr�rrrr&r'r%rrur(rqrrrrrrZ	which_binrrArsrBrPrpr�rCr_r�rr�r�rrr#)(r�rRZsysfs_firmware_inforJZfw_fileZ
contents_filer �errrLrzZhwdataZ
grain_nameZcmd_key�resultZuboot_keyvalr
Zfbsd_hwdatarbr�r��oidZnbsd_hwdatar�r�r,Z
sn_regexesZobp_regexesZ
fw_regexesr�Zmanufacturer_regexesZproduct_regexesr!r�Zobp_revZobp_dateZfw_revZfw_dateZ
t_productnamer�r�r$r$r%ros��

��������	��
�





�
W��Y����K���	9����,���	��������	�����	�	���
�
��
�
�
�
��
��
��
�rcCsDtjj��riSt�dd�}tt�|�	���
�d�}dt|d�iS)z�
    Provides an integer based on the FQDN of a machine.
    Useful as server-id in MySQL replication or anywhere else you'll need an ID
    like this.
    r}rir?Z	server_idl)rrrrrorPrN�hashlib�sha256�encode�	hexdigest�abs)rZhash_r$r$r%�
get_server_id�
s
	rdcCr|)z�
    Provides the minion with the name of its master.
    This is useful in states to target other services running on the master.
    rrir~r$r$r$r%�
get_master�
srec
Cs�i}tjj�d�}|s
iSd|d<d|d<d|d<dD]U}zJtd|d|d	d
g�}|��D]7}|�d�red|d<d|d|�d
�<z|��dd�\}}Wn	tyVYn
w|dkrc||d|�d
�<nq.Wqt	ypYqw|S)a
    Populates grains which describe whether a server has a default gateway
    configured or not. Uses `ip -4 route show` and `ip -6 route show` and greps
    for a `default` at the beginning of any line. Assuming the standard
    `default via <ip>` format for default gateways, it will also parse out the
    ip address of the default gateway, and put it in ip4_gw or ip6_gw.

    If the `ip` command is unavailable, no grains will be populated.

    Currently does not support multiple default gateways. The grains will be
    set to the first default gateway found.

    List of grains:

        ip4_gw: True  # ip/True/False if default ipv4 gateway
        ip6_gw: True  # ip/True/False if default ipv6 gateway
        ip_gw: True   # True if either of the above is True, False otherwise
    �ipFZip_gwZip4_gwZip6_gw)rrr-r[Zrouter��defaultTZ_gwrr5�via)
rrr]rprsr?rArBrOrt)rRZip_binZ
ip_version�outr"rhZgw_ipr$r$r%�default_gateway�
s8
����rjc
Cstjj��riSzRtjjjdddd��=}|��}dgi}dd�tjj�|�D�D]}d}t	|�d	kr9|d
�
d�}|d|d|fg7<q(Wd�W|S1sSwYW|Styfi}Y|Sty�}zi}t
�d
|�WYd}~|Sd}~ww)z+
    Return the kernel boot parameters
    z
/proc/cmdlinerU�surrogateescaper�kernelparamscSsg|]}|�d��qS)r�r�rr$r$r%r��
rZz kernelparams.<locals>.<listcomp>Nrrr�rz Failed to read /proc/cmdline: %s)rrrrrrr%r,Zshlex_splitr_r�FileNotFoundErrorrrqrr)r/ZcmdlinerRr�r�r�r$r$r%rl�
s<�
��������rlr))��__doc__r
r_r�loggingrLrrrr�rArrLrrrZsalt.exceptionsrZsalt.modules.cmdmodZsalt.modules.networkZsalt.modules.smbiosZsalt.utils.argsZsalt.utils.dnsZsalt.utils.filesZsalt.utils.networkZsalt.utils.pathZsalt.utils.pkg.rpmZsalt.utils.platformZsalt.utils.stringutilsrrrr9rr�rr'r�r&r+Zdateutil.tzrr	�	getLogger�__name__rqr�rrZsalt.utils.win_osinfor�rjZsalt.utils.win_regZsalt.utils.winapi�	exceptionZ__proxyenabled__r�modulesZcmdmodZ
_run_quietZ_retcode_quietZ_run_all_quietrX�recordsrPrrrs�hasattrrZHOST_NOT_FOUNDZNO_DATArGrSrcryr|r�r�r�r�r�r�r�r�r�r�r�r�r�r1rErKrPr_rnrqr{rrZ_PRETTY_NAME_REr�rzr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr'r,r3r5r6r8r:r;r]r@rDrFrHrOrQrUrrdrerjrlr$r$r$r%�<module>s�&�,�
���
	FZ+D HpA9;)1

��������	�
���
������������������� �!�"�#�,���������	�
���
������������������� �!�"�#�$�%�&�'�(�)�*�+�,�-�.�/�0�1�2�3�4�5�6�7�8�9�:�;�<�=�>�?�@�A�B�C�D�O��(C'5<$
 1-%+&
			

0
.