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/utils/__pycache__/parsers.cpython-310.pyc
o

�N�g~��@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlZ
ddlmZddlZ
ddlZ
ddlmZddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlZ
ddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&m'Z'm(Z(e�)e*�Z+dd�Z,Gd	d
�d
e-�Z.Gdd�de/�Z0Gd
d�de0�Z1Gdd�dej2�Z3Gdd�dej4�Z4Gdd�de0d�Z5Gdd�de0d�Z6Gdd�de0d�Z7Gdd�de0d�Z8Gdd�de0d�Z9Gdd�de0d�Z:Gd d!�d!e0d�Z;Gd"d#�d#e0d�Z<Gd$d%�d%e0d�Z=Gd&d'�d'e=�Z>Gd(d)�d)e0d�Z?Gd*d+�d+e0d�Z@Gd,d-�d-e0d�ZAGd.d/�d/e0d�ZBGd0d1�d1e0d�ZCGd2d3�d3e0d�ZDGd4d5�d5e0d�ZEGd6d7�d7e0d�ZFGd8d9�d9e0d�ZGGd:d;�d;e0d�ZHGd<d=�d=e0d�ZIGd>d?�d?e0d�ZJGd@dA�dA�ZKGdBdC�dCe4e9e5e:e;e<e6e1d�
ZLGdDdE�dEeLe1d�ZMGdFdG�dGe4eAe9e5e:e;e<e6e1d�ZNGdHdI�dIe4e9e5e:e;e<e6e1d�
ZOGdJdK�dKe4e9e5e?e>eDe:eBe7e6e@eJe8e1d�ZPGdLdM�dMe4eDe9e5e?e=e:e7e6e1d�ZQGdNdO�dOe4e9e5e:eDe;e7e6eJe1d�ZRGdPdQ�dQe4eAe9eBe5e:eDe7e6e@eHe8eCe1d�ZSGdRdS�dSe4e9e5e?e:e7e6eDe@eHeJe8eKe1d�ZTGdTdU�dUe4e9e5e:e=eDe6e7e8eKe1d�
ZUGdVdW�dWe4e:e5eDe9eFeEeGeIe7e6e1d�ZVGdXdY�dYe4e9e:e5e6e1d�ZWGdZd[�d[e4e9e:e<e5e1d�ZXdS)\z�
    :codeauthor: Pedro Algarvio (pedro@algarvio.me)


    salt.utils.parsers
    ~~~~~~~~~~~~~~~~~~

    This is where all the black magic happens on all of salt's CLI tools.
�N)�partial)�DEFAULT_TARGET_DELIM)�is_writeable)�insecure_log�
verify_log�verify_log_filescCst|dd�d�S)NcSst|dd�S)N�_mixin_prio_��)�getattr)Zmf�r�F/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/parsers.py�<lambda>2sz_sorted.<locals>.<lambda>)�key)�sorted)Zmixins_or_funcsrrr�_sorted1�rc@�eZdZdd�ZdS)�MixinFuncsContainercCs.t|tj�r	|j}||vrt�||�dSdS�N)�
isinstance�types�
MethodType�__func__�list�append)�self�funcrrrr6s
�zMixinFuncsContainer.appendN)�__name__�
__module__�__qualname__rrrrrr5�rcs eZdZdZ�fdd�Z�ZS)�	MixInMetarcs2t��||||�}t|d�std�|j|���|S)N�_mixin_setupzNDon't subclass {} in {} if you're not going to use it as a salt parser mix-in.)�super�__new__�hasattr�RuntimeError�formatr)�mcs�name�bases�attrs�instance��	__class__rrr$Es

�zMixInMeta.__new__)rrrrr$�
__classcell__rrr-rr!?sr!cseZdZ�fdd�Z�ZS)�OptionParserMetacs4t��||||�}t|d�st�|_t|d�st�|_t|d�s$t�|_t|d�s-t�|_t||f�D]c}t	|dd�}|durK||jvrK|j�
|�t	|dd�}|dur`||jvr`|j�
|�t	|dd�}|duru||jvru|j�
|�t|�D]}|�d�s�qyt	||�}t	|d	d�dur�qyt	|d	d
�|_
qyq4|S)N�_mixin_setup_funcs�_mixin_process_funcs�_mixin_after_parsed_funcs�_mixin_before_exit_funcsr"�_mixin_after_parsed�_mixin_before_exit�process_rr	)r#r$r%rr1r2r3r4rr
r�dir�
startswithr)r(r)r*r+r,�baserr-rrr$Ps8





�zOptionParserMeta.__new__)rrrr$r/rrr-rr0Osr0c@r)�CustomOptioncOs$d|_tjj|||g|�Ri|��S)NT)�explicit�optparse�Option�take_action)r�action�dest�args�kwargsrrrr?xszCustomOption.take_actionN)rrrr?rrrrr;wr r;c@sveZdZejjZdZdZdZ	e
jdZdd�Z
dd�Zdd	d
�Zddd
�Zdd�Ze
jfdd�Zddd�Zdd�ZdS)�OptionParserz%prog [options]z^You can find additional help about %prog issuing "man %prog" or on https://docs.saltproject.ioN��cOs�|�dd|j���|�d|j�|jr|�d|j�|jr%|�d|j�|�dt�tjj|g|�Ri|��|jrLd|jvrN|j�	d|�
��|_dSdSdS)N�versionz%prog �usage�description�epilog�option_classz%prog)�
setdefault�VERSIONrGrHrIr;r=rD�__init__�replace�
get_prog_name)rrBrCrrrrM�s�zOptionParser.__init__cOs$tjj|g|�Ri|��}t|_|Sr)r=rD�add_option_groupr;rJ)rrBrCZoption_grouprrrrP�szOptionParser.add_option_groupc
Cs�tj�|||�\}}d|jvr5|jdur5tj��}dd�|D�}tj�||�\}}|j�|j�|�	|�|j
r<|��|||_|_
t|jdd�}tj�|durSdn|�g}|jD]}	t|d|	��d�}
|
duro|�|
�q[t|�D]/}
t�d|
�z|
�Wqtty�}zt�|�|�d	�|
t����WYd}~qtd}~ww|jD]0}t�d|�z||�Wq�ty�}zt�|�|�d	�|t����WYd}~q�d}~ww|j�d
d�dur�t�d|jd
�tj j!�"d�||fS)
N�
args_stdinTcSsg|]}|�d��qS)z
)�rstrip)�.0�argrrr�
<listcomp>�sz+OptionParser.parse_args.<locals>.<listcomp>�	log_level�errorr7�
Processing %szError while processing {}: {}Z	conf_filezConfiguration file path: %s�MainProcess)#r=rD�
parse_args�__dict__rQ�sys�stdin�	readlines�update�extend�versions_report�print_versions_report�optionsrBr
�salt�_loggingZsetup_temp_handlerrr�log�trace�	Exception�	exceptionrWr'�	traceback�
format_excr3�config�get�debug�utils�process�appendproctitle)
rrB�valuesrcZ
new_inargsZnew_options�new_argsZtemp_log_levelZprocess_option_funcsZ
option_keyZprocess_option_func�errZmixin_after_parsed_funcrrrrZ�sn

�

�

�����
�����zOptionParser.parse_argsTcCs6tjj|||d�|jD]}t�d|�||�qdS)N)�add_helprX)r=rD�_populate_option_listr1rfrg)r�option_listruZmixin_setup_funcrrrrv�s�

�z"OptionParser._populate_option_listcCs"tj�|�|jddddd�dS)Nz--versions-reportz-V�
store_truez4Show program's dependencies version number and exit.)r@�help)r=rD�_add_version_option�
add_option�rrrrrz�s
�z OptionParser._add_version_optioncCs,td�t���|dd�|�tjjj�dS)N�
T)�file�flush�	�print�joinrFra�exitrd�defaults�	exitcodes�EX_OK�rr~rrrrb�sz"OptionParser.print_versions_reportrcCs�|jD]1}t�d|�z||�Wqty4}zt�|�tjd|t��tj	d�WYd}~qd}~wwt
j��}|durB|�
�t
j��t|t�rY|rY|ddkrY|�d�}tj�|||�dS)NrXzError while processing %s: %s�Zexc_info_on_loglevel���r})r4rfrgrhrirWrjrk�logging�DEBUGrdreZget_temp_handlerrZshutdown_temp_handlerr�strr=rDr�)r�status�msgZmixin_before_exit_funcrtZtemp_log_handlerrrrr��s.�
���
	

zOptionParser.exitcCs2|�tj�|�tjjj|���d|�d��dS)z�
        error(msg : string)

        Print a usage message incorporating 'msg' to stderr and exit.
        This keeps option parsing exit status uniform for all parsing errors.
        �	: error: r}N)	�print_usager\�stderrr�rdr�r��EX_USAGErO)rr�rrrrWs
�zOptionParser.error�NN�T�rN)rrrrFZ__saltstack_version__Zformatted_versionrLrGrIrHr\�maxsizerrMrPrZrvrz�stdoutrbr�rWrrrrrD�s �


D

�
rDc@s&eZdZdZejZdd�Zdd�ZdS)�MergeConfigMixInz�
    This mix-in will simply merge the CLI-passed options, by overriding the
    configuration file loaded settings.

    This mix-in should run last.
    cCs*t|d�st|d�sdS|j�|j�dS)N�setup_configrl)r%r3r�(_MergeConfigMixIn__merge_config_with_clir|rrrr"1szMergeConfigMixIn._mixin_setupcCsL|jD]K}|jdurq|j�|j�}t|j|j|�}|j|jvr+|dur*||j|j<q|dur<t|dd�r<||j|j<q|j|jvrNt|j|j|j|j�q|jD]Q}|jD]K}|jdur_qW|j�|j�}t|j|j|�}|j|jvr|dur~||j|j<qW|dur�t|dd�r�||j|j<qW|j|jvr�t|j|j|j|j�qWqRdS)Nr<F)	rwrAr�rmr
rcrl�setattr�
option_groups)r�option�default�value�grouprrrZ__merge_config_with_cli;s>

��


����z(MergeConfigMixIn.__merge_config_with_cliN)	rrr�__doc__r\r�rr"r�rrrrr�&s

r�)�	metaclassc@� eZdZdZdd�Zdd�ZdS)�
SaltfileMixIni��cC�|jdddd�dS)Nz
--saltfileziSpecify the path to a Saltfile. If not passed, one will be searched for in the current working directory.�r�ry�r{r|rrrr"vs

�zSaltfileMixIn._mixin_setupc

Cs�|jjdurtj�dd�|j_|jjdurNztj�t��d�}Wnty+d}Ynwtj�	|�r7||j_ntj�tj�
d�dd�}tj�	|�rM||j_n|jj}|jjsXdStj�	|jj�sk|�d|jj�d��tj�|jj�|j_t
�d|jj�zt�|�}Wn,tjjy�}z|�|j�|�tjjj|���d	|j�d
��WYd}~nd}~ww|s�dS|��|vr�dS||��}|jD]6}|jdur�q�|j|vr�q�|j�|j�}t|j|j|�}||kr�|�|j�q�t|j|j||j�d|_q�|j D]D}|jD]=}|jdu�r�q|j|v�r�q|j�|j�}t|j|j|�}||k�r3|�|j��qt|j|j||j�d|_�q�q|D]}	t|j|	||	��qGdS)NZ
SALT_SALTFILEZSaltfile��~z.salt�'z' file does not exist.
zLoading Saltfile from '%s'r�r}T)!rc�saltfile�os�environrm�pathr��getcwd�OSError�isfile�
expanduserrW�abspathrf�inforlZ_read_conf_filerd�
exceptionsZSaltConfigurationError�messager�r�r��
EX_GENERICrOrwrAr
�popr�r<r�)
rr�Zsaltfile_configrWZ
cli_configr�r�r�r�rrrr�process_saltfile�s��
����






��zSaltfileMixIn.process_saltfileN)rrrrr"r�rrrrr�ss
r�c@seZdZdZdZdd�ZdS)�HardCrashMixin�(NcCs$tj�dd�}|jdd|dd�dS)NZSALT_HARD_CRASHFz--hard-crashrxzORaise any original exception rather than exiting gracefully. Default: %default.)r@r�ry�r�r�rmr{)rZ
hard_crashrrrr"�s
�zHardCrashMixin._mixin_setup)rrrr�_config_filename_r"rrrrr��sr�c@r�)�NoParseMixin�2cCs$tj�dd�}|jd|ddd�dS)NZ
SALT_NO_PARSEr�z
--no-parsezpComma-separated list of named CLI arguments (i.e. argname=value) which should not be parsed as Python data typeszargname1,argname2,...)r�ry�metavarr�)r�no_parserrrr"s
�zNoParseMixin._mixin_setupcCsT|jjr$zdd�|jj�d�D�|j_WdSty#g|j_YdSwg|j_dS)NcS�g|]}|���qSr)�strip�rS�xrrrrUs�z1NoParseMixin.process_no_parse.<locals>.<listcomp>�,)rcr��split�AttributeErrorr|rrr�process_no_parses��zNoParseMixin.process_no_parseN)rrrrr"r�rrrrr��sr�c@s8eZdZdZdZejZdZdd�Z	dd�Z
d
dd	�ZdS)�ConfigDirMixIni����NZSALT_CONFIG_DIRcCs>tj�|jd�}|s|j}t�dtj�|j	dd|dd�dS)NzSYSPATHS setup as: %sz-cz--config-dirzDPass in an alternative configuration directory. Default: '%default'.r�)
r�r�rm�_default_config_dir_env_var_�_default_config_dir_rfrn�syspaths�
CONFIG_DIRr{)r�
config_dirrrrr"s
�zConfigDirMixIn._mixin_setupc
Cs�tj�|jj�|j_tj�|jj�stj�d�	|jj��tj�
|jj�|j_t|d�r[t|d�s4i|_z|j�
|���WdStyZ}z|�d|���WYd}~dSd}~wwdS)Nz/WARNING: CONFIG '{}' directory does not exist.
r�rlzFailed to load configuration: )r�r�r�rcr��isdirr\r��writer'r�r%rlr_r�r�rW�r�excrrr�process_config_dir*s$��

���z!ConfigDirMixIn.process_config_dircCs |dur|j}tj�|jj|�Sr)r�r�r�r�rcr�)r�
configfilerrr�get_config_file_path?sz#ConfigDirMixIn.get_config_file_pathr)rrrrr�r�r�r�r�r"r�r�rrrrr�sr�c@s�eZdZejdZdZdZdZdZ	dZ
dZdd	�Zd
d�Z
dd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�
LogLevelMixIn�d�warningN�log_filerVZlog_level_logfile)�-l�--log-levelcs�jdurtd��jj���t��dd�}�_��|�|j	�j
�jtt
jj�d�d�dd�t
jjD���jd�t���d���fd	d
�}|j	d�jddd
|d�j�d�d�|j	d�jtt
jj�d�d�dd�t
jjD���jd�t���d��j��j�dS)Nz'Please set {}._default_logging_logfile_zLogging OptionszOLogging options which override any settings defined on the configuration files.z{Console logging log level. One of {}. Default: '{}'. 
 The following log levels are INSECURE and may log sensitive data: {}z, cS�g|]}d|�d��qS�r�r�rS�nrrrrUi�z.LogLevelMixIn._mixin_setup.<locals>.<listcomp>)rA�choicesrycs2tj�|�stj�tjj|�}t|j�j|�dSr)r�r��dirnamer��curdirr�rr�_logfile_config_setting_name_)r��optr��parserrBrCr|rr�_logfile_callbackosz5LogLevelMixIn._mixin_setup.<locals>._logfile_callbackz
--log-file�callback�stringzLog file path. Default: 'z'.)rAr�r@�typer�ryz--log-file-levelz{Logfile logging log level. One of {}. Default: '{}'. 
 The following log levels are INSECURE and may log sensitive data: {}cSr�r�rr�rrrrU�r�)�_default_logging_logfile_r&r'r.rr=�OptionGroupZlogging_options_grouprPr{�_console_log_level_cli_flags�_loglevel_config_setting_name_rrdreZ
LOG_LEVELSr�ZSORTED_LEVEL_NAMES�_default_logging_level_rr��&_logfile_loglevel_config_setting_name_r3r�&_LogLevelMixIn__setup_logging_routines)rr�r�rr|rr"RsZ
��
�


���


��zLogLevelMixIn._mixin_setupcCsX|j�|j�|j�|j�|j�|j�|j�|j�|j�|j�|j�|j�dSr)	r3r�+_LogLevelMixIn__setup_console_logger_config�+_LogLevelMixIn__setup_logfile_logger_config�$_LogLevelMixIn__setup_logging_config�_LogLevelMixIn__verify_logging�_LogLevelMixIn__setup_loggingr4� _LogLevelMixIn__shutdown_loggingr|rrrZ__setup_logging_routines�sz&LogLevelMixIn.__setup_logging_routinescCsXt|j|jd�s*|j�|jd�rt|j|j|j�|j��dSt|j|j|j�dSdSr)r
rcr�rlrmr�r�r|rrr�process_log_level�s���zLogLevelMixIn.process_log_levelcCs"tj��tj��tj��dSr)rdre�shutdown_loggingr\r�rr�r|rrrZ__shutdown_logging�s

z LogLevelMixIn.__shutdown_loggingcCsvt|j|jd�s7|j�|jd�rt|j|j|j�|j��dSt|j|j|j�|j|jvr9|j�|j�dSdSdSr)r
rcr�rlrmr�r�r�r|rrr�process_log_file�s ���zLogLevelMixIn.process_log_filecCs�t|j|jd�s=|j�|jd�rt|j|j|j�|j��dSt|j|j|j�|j|j��|j|jvr?|j�|j�dSdSdSr)	r
rcr�rlrmr�r�r�r�r|rrr�process_log_level_logfile�s&���	�z'LogLevelMixIn.process_log_level_logfilecCsl|j�d|j�dtjj��}|j�dd�dur|j�dd�|j�d|j�dd��}||jd<||jd<dS)N�log_fmt_console�log_fmt�log_datefmt_console�log_datefmt�%Y-%m-%d %H:%M:%S)rlrmrdre�DFLT_LOG_FMT_CONSOLEr�)rZlogfmt�datefmtrrrZ__setup_console_logger_config�s��
z+LogLevelMixIn.__setup_console_logger_configc
Csv|j|jvr|j�|j�s|j�|j�t|j|j|j�}t|j|j|j�}d�	|�
��dd��}||jvrB|j�|�sB|j�|�|j|jvrV|j�|j�sV|j�|j�|jdr�|jddvr�|j|jdkr�|dur�tj
j�d��t|g|jd	�Wd�n1s�wY|dur�|j}d
�	|�
��dd��}||jvr�|j�|�s�|j�|�|j�dd�dur�|j�dd�|j�d|j�d|j�d
tjj���}|j�dd�dur�|j�dd�|j�dd�dur�|j�dd�|j�d|j�d|j�dd���}t|dd��sltj
j��}|jd	|k�rl|jd}tj
jj||��d��rltj
j��}	tj�|	��r:|	ntj�d�}
tj�|
��sMt�|
d�tj� |j�}t!�"dt#|�t#|�t#|��tj�$|
|�d��}|j�dd�}|j�dd�}
tj
j%�&��s�|dk�r�t!�'d�d}|
dk�r�t!�'d�d}
||j|j<||j|j<||jd<||jd<||jd<|
|jd<dS)Nzcli_{}_log_file�-�_Z
verify_envrV)�quietr��userzcli_{}_log_file_fmtZlog_fmt_logfiler�r�Zlog_datefmt_logfiler�rrT)Zcheck_parentZ
publisher_acl)Z	whitelistz~/.salti�z`The user '%s' is not allowed to write to '%s'. The log file will be stored in '~/.salt/'%s'.log'z.log�log_rotate_max_bytesr�log_rotate_backup_countz3'log_rotate_max_bytes' is only supported on Windowsz6'log_rotate_backup_count' is only supported on Windows)(r�rlrmr�r
rcr�r�r�r'rOrNrdro�filesZ	set_umaskrrerrrZget_userZstringutilsZcheck_whitelist_blacklist�keysZxdgZxdg_config_dirr�r�r�r��makedirs�basenamerfrnr�r��platform�
is_windowsr�)rZloglevelZlogfileZcli_log_pathZcli_log_file_fmtZlog_file_fmtZlog_file_datefmt�current_userZaclZxdg_dirZ
user_salt_dirZlogfile_basenamer	r
rrrZ__setup_logfile_logger_config�s�����������
�
�
��






z+LogLevelMixIn.__setup_logfile_logger_configcCsjt�|j�}t|jdd�du|d<|j|d<t|jdd�dkr(d�|d�|d<tj�	|�tj�
�dS)	N�daemonFZconfigure_console_loggerZlog_file_key�output�yamlz# {}r�)�copy�deepcopyrlr
rcr�r'rdreZset_logging_options_dictZfreeze_logging_options_dict)rZlogging_optsrrrZ__setup_logging_config}s�
�z$LogLevelMixIn.__setup_logging_configc
CsRztj��WdStjjy(}z|�tjjjt	|��WYd}~dSd}~wwr)
rdre�
setup_loggingr�ZLoggingRuntimeErrorr�r�r��EX_UNAVAILABLEr�r�rrrZ__setup_logging�s$��zLogLevelMixIn.__setup_loggingcCst|j�dSr)rrlr|rrrZ__verify_logging��zLogLevelMixIn.__verify_logging)rrrr\r�rr�r�r�r�r�r�r"r�r�r�r�r�r�r�r�r�r�rrrrr�Es*
�:

r�c@�eZdZdZdd�ZdS)�RunUserMixin�cCs |jddd|���d�d�dS)N�-u�--userzSpecify user to run �.)ry)r{rOr|rrrr"�s
�zRunUserMixin._mixin_setupN�rrrrr"rrrrr��rc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd dd�ZdS)!�DaemonMixIn�cCsL|jddddd|���d�d�|jdd	tj�tj|���d
��dd�dS)
N�-dz--daemonFrxzRun the z
 as a daemon.�r�r@ryz
--pid-file�pidfilez.pidz9Specify the location of the pidfile. Default: '%default'.�rAr�ry)r{rOr�r�r�r�ZPIDFILE_DIRr|rrrr"�s�
�zDaemonMixIn._mixin_setupc
Cs�t|d�rb|j�d�rd|��rfzt�|jd�WdStya}z;d}tjj	�
�r:tjj��}tjj�
|�r9d}nt��s@d}|rVtjd|jd|tjd�WYd}~dSWYd}~dSd}~wwdSdSdS)Nrlr&FTz$PIDfile(%s) could not be deleted: %sr�)r%rlrm�
check_pidfiler��unlinkr�rdrorr�
win_functionsZget_current_userZis_admin�getuidrfr�r�r�)rrtZ	log_errorrrrrr6�s2������zDaemonMixIn._mixin_before_exitcCs&ddlm}||jd|jd�dS)Nr)�set_pidfiler&r)�salt.utils.processr,rl)rr,rrrr,�szDaemonMixIn.set_pidfilecC�ddlm}||jd�S)z1
        Report whether a pidfile exists
        r)r(r&)r-r(rl)rr(rrrr(��zDaemonMixIn.check_pidfilecCr.)z5
        Return a pid contained in a pidfile
        r)�get_pidfiler&)r-r0rl)rr0rrrr0�r/zDaemonMixIn.get_pidfilecCsL|jjr$tj��tjj��t�	�tjj
_tj��tjj�
d�dSdS)NrY)rcrrdrer�rorpZ	daemonizer��getpidZin_mainprocessZ__pid__rrqr|rrr�daemonize_if_required�s

�z!DaemonMixIn.daemonize_if_requiredcCsl|��r4|��}tjj��s!|��r|�|�rt��|krdSdS|��r4|�|�r4tjj	�
�|kr4dSdS)zd
        Check if a pid file exists and if it is associated with
        a running process.
        TF)r(r0rdrorr�
is_daemonizedr��getppidr*Zget_parent_pid)r�pidrrr�
check_running�s"��	���zDaemonMixIn.check_runningcCs:tj�|jd�}tj�|dd|d�}tjj�|�S)zS
        This will stop from more than on prcoess from doing the same task
        r&rZprocess_responsibility_�)	r�r�r�rlr�rdrorpZclaim_mantle_of_responsibility)rZresponsibility_filerrr�claim_process_responsibilitys
�z(DaemonMixIn.claim_process_responsibilitycCsddlm}||�S)Nr)�
os_is_running)r-r9)rr5r9rrrr3szDaemonMixIn.is_daemonizedcCs$t�tj|j�t�tj|j�dSr)�signal�SIGTERM�_handle_signals�SIGINTr|rrr�_install_signal_handlerssz$DaemonMixIn._install_signal_handlerscCs|��dSr)rZr|rrr�prepareszDaemonMixIn.preparecCs|��|��dSr)r?r>r|rrr�startszDaemonMixIn.startcCsV|jj}|tjkr|d7}n	|tjkr|d7}t�t��d|�|j|�d�d�dS)Nz received a SIGINT.z received a SIGTERM.z%s Exiting.z Exited.)�exitmsg)	r.rr:r=r;r��	getLoggerr��shutdown)r�signumZsigframer�rrrr< s


zDaemonMixIn._handle_signalsrNcCs|�||�dSr)r�)r�exitcoderArrrrC)rzDaemonMixIn.shutdownr�)rrrrr"r6r,r(r0r2r6r8r3r>r?r@r<rCrrrrr"�s 
	r"c@�,eZdZdZdZdd�Zdd�Zdd�ZdS)	�TargetOptionsMixInrNcCs�t�|dd�}|_|�|�|jddddddd	�|jd
ddddd
�|jdddddd
�|jdddddd
�|jdddddd
�|jdddddd
�|jdddddd
�t�|dd�}|_|�|�|jdtd d!�|��dS)"NzTarget OptionszTarget selection options.�-Hz--hostsFrxZ
list_hostszDList all known hosts to currently visible or other specified rosters�r�r@rAryz-Ez--pcrezZInstead of using shell globs to evaluate the target servers, use pcre regular expressions.r%�-L�--listzrInstead of using shell globs to evaluate the target servers, take a comma or whitespace delimited list of servers.z-Gz--grainz�Instead of using shell globs to evaluate the target use a grain value to identify targets, the syntax for the target is the grain key followed by a globexpression: "os:Arch*".�-Pz--grain-pcrez�Instead of using shell globs to evaluate the target use a grain value to identify targets, the syntax for the target is the grain key followed by a pcre regular expression: "os:Arch.*".z-Nz--nodegroupzwInstead of using shell globs to evaluate the target use one of the predefined nodegroups to identify a list of targets.�-Rz--rangez�Instead of using shell globs to evaluate the target use a range expression to identify targets. Range expressions look like %cluster.zAdditional Target Optionsz(Additional options for minion targeting.z--delimiterz^Change the default delimiter for matching in multi-level data structures. Default: '%default'.r�)r=r��target_options_grouprPr{Zadditional_target_options_groupr�_create_process_functions�rr�rrrr"3s�
�
��
�����
�
�	zTargetOptionsMixIn._mixin_setupc�F�jjD]}�fdd�}d|j��}t�|�s t�|t||��qdS)Ncst�j|j�r
|j�_dSdSr)r
rcrA�selected_target_option)r�r|rrrp�s�z=TargetOptionsMixIn._create_process_functions.<locals>.processr7)rNrwrAr%r�r�rr�rp�funcnamerr|rrO�s
��z,TargetOptionsMixIn._create_process_functionsc�R�fdd��jjD�}t|�dkr!��d�d�dd�|D�����j�jd<dS)Ncs"g|]
}t�j|j�dur|�qSr��r
rcrA�rSr�r|rrrU��
�z:TargetOptionsMixIn._mixin_after_parsed.<locals>.<listcomp>r7�EThe options {} are mutually exclusive. Please only choose one of them�/cSr�r�Zget_opt_stringrWrrrrU��rR)rNrw�lenrWr'r�rRrl�rZgroup_options_selectedrr|rr5�s
����z&TargetOptionsMixIn._mixin_after_parsed)rrrrrRr"rOr5rrrrrG-sbrGc@seZdZdd�Zdd�ZdS)�ExtendedTargetOptionsMixIncCsnt�|�|j}|jdddddd�|jdddd	dd
d�|jdd
dddd�|jdddddd�|��dS)N�-Cz
--compoundFrxa?The compound target option allows for multiple target types to be evaluated, allowing for greater granularity in target matching. The compound target is space delimited, targets other than globs are preceded with an identifier matching the specific targets argument type: salt 'G@os:RedHat and webser* or E@database.*'.r%z-Iz--pillar�
pillar_targetz�Instead of using shell globs to evaluate the target use a pillar value to identify targets, the syntax for the target is the pillar key followed by a glob expression: "role:production*".�r�rAr@ryz-Jz
--pillar-pcrez�Instead of using shell globs to evaluate the target use a pillar value to identify targets, the syntax for the target is the pillar key followed by a pcre regular expression: "role:prod.*".�-Sz--ipcidrz4Match based on Subnet (CIDR notation) or IP address.)rGr"rNr{rOrPrrrr"�s@
��
��z'ExtendedTargetOptionsMixIn._mixin_setupcCs|jjr	d|_dSdS)NZpillar)rcrarRr|rrr�process_pillar_target�s
�z0ExtendedTargetOptionsMixIn.process_pillar_targetN)rrrr"rdrrrrr_�s4r_c@r)�TimeoutMixIn�
cCs6t|d�std�|jj���|jddt|jdd�dS)N�default_timeoutz8You need to define the 'default_timeout' attribute on {}�-t�	--timeoutz[Change the timeout, if applicable, for the running command (in seconds). Default: %default.)r�r�ry)r%r&r'r.rr{�intrgr|rrrr"�s
��
�zTimeoutMixIn._mixin_setupNr rrrrre�r!rec@r)�ArgsStdinMixInrfcCs|jdddddd�dS)Nz--args-stdinFrQrxzURead additional options and/or arguments from stdin. Each entry is newline separated.rbr�r|rrrr"s
�zArgsStdinMixIn._mixin_setupNr rrrrrkr!rkc@r)�ProxyIdMixInr�cCs|jddddd�dS)Nz	--proxyid�proxyidzId for this proxy.�r�rAryr�r|rrrr"s
�zProxyIdMixIn._mixin_setupN�rrrZ_mixin_prior"rrrrrlr!rlc@r)�ExecutorsMixInrfcCs,|jdddddd�|jddddd	d�dS)
Nz--module-executorsZmodule_executorsZ
EXECUTOR_LISTzNSet an alternative list of executors to override the one set in minion config.�rAr�r�ryz--executor-optsZ
executor_optsZ
EXECUTOR_OPTSzjSet alternate executor options if supported by executor. Options set by minion config are used by default.r�r|rrrr"s�

�zExecutorsMixIn._mixin_setupNrorrrrrpr!rpc@r)�
CacheDirMixInr�cCs|jddddd�dS)Nz
--cachedirz/var/cache/salt/ZcachedirzCache Directoryrnr�r|rrrr"8s
�zCacheDirMixIn._mixin_setupNrorrrrrr5r!rrc@s@eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dS)�OutputOptionsMixInr�FNcst��dd�}�_��|�|jdddd�����d�|jdd	d
dtdd�|jd
ddddd�|jddddddd�|jdddddd�|jdddddd�|jd d!dd"d#�|jd$d%dd&d#��jjD]}�fd'd(�}d)|j	��}t
�|�s�t�|t||��qgdS)*N�Output Options�'Configure your preferred output format.z--outz--outputrzEPrint the output from the '{}' command using the specified outputter.�rAryz--out-indentz--output-indentZ
output_indentz�Print the output indented by the provided value in spaces. Negative values disables indentation. Only applicable in outputters that support indentation.�rAr�r�ryz
--out-filez
--output-file�output_filez'Write the output to the specified file.r'z--out-file-appendz--output-file-appendrx�output_file_appendFz(Append the output to the specified file.)r@rAr�ryz
--no-colorz--no-colourzDisable all colored output.r%z
--force-colorz--force-colourzForce colored output.z--state-outputz--state_outputz�Override the configured state_output value for minion output. One of 'full', 'terse', 'mixed', 'changes' or 'filter'. Default: '%default'.r�z--state-verbosez--state_verbosezgOverride the configured state_verbose value for minion output. Set to True or False. Default: %default.cs2�j�|j�}t�j|j|�durdS|j�_dS)NF)r�rmrAr
rc�selected_output_option)r�r�r|rrrp�sz0OutputOptionsMixIn._mixin_setup.<locals>.processr7)
r=r��output_options_grouprPr{r'rOrjrwrAr%r�r)rr�r�rprTrr|rr"Hs�
�
��������
�

��zOutputOptionsMixIn._mixin_setupcCs|jj|_dSr)rcrrzr|rrr�process_output�rz!OutputOptionsMixIn.process_outputc
Cs�|jjdurS|jjdurUtj�|jj�rWztjj�	|jjd��
Wd�WdS1s,wYWdSt
yR}z|�|jj�d|���WYd}~dSd}~wwdSdSdS)NF�wz: Access denied: )rcrxryr�r�r�rdrorZfopenr�rWr�rrr�process_output_file�s&�&���z&OutputOptionsMixIn.process_output_filecCsL|jjdks|jjdkrd|j_dS|jjdks|jjdkr$d|j_dSdS)N�True�trueT�False�falseF)rcZ
state_verboser|rrr�process_state_verbose�s�z(OutputOptionsMixIn.process_state_verbosecrU)Ncs4g|]}t�j|j�r|j�d�s|jdkr|�qS)Z_outr)r
rcrA�endswithrWr|rrrU�s�
�
�z:OutputOptionsMixIn._mixin_after_parsed.<locals>.<listcomp>r7rYrZcSr�rr[rWrrrrU�r\rz)r{rwr]rWr'r�rzrlr^rr|rr5�s
����z&OutputOptionsMixIn._mixin_after_parsed)rrrrZ_include_text_out_rzr"r|r~r�r5rrrrrsAsZ	rsc@r�)�ExecutionOptionsMixInrfcCsBt�|d�}|_|jddddd�|jddddd�|jd	d
dddd
d�|jddddd�|jddddd�|jdddddd�|jdddddd�|jddd d!d"d#�|jd$d%ddd&d�|jd'd(ddd)d�|jd*d+ddd,d�|jd-d.ddd/d�|jd0ddd1d�|jd2dd3d�|jd4d5d6dd7d8d�|�|�dS)9NzExecution OptionsrJz
--locationz#Specify which region to connect to.r��-az--actionz�Perform an action that may be specific to this cloud provider. This argument requires one or more instance names to be specified.�-fz
--function�z<FUNC-NAME> <PROVIDER>z�Perform a function that may be specific to this cloud provider, that does not apply to an instance. This argument requires a provider to be specified (i.e.: nova).)�nargsr�r�ry�-pz	--profilez/Create an instance using the specified profile.�-mz--mapz�Specify a cloud map file to use for deployment. This option may be used alone, or in conjunction with -Q, -F, -S or -d. The map can also be filtered by a list of VM names.rHz--hardFrxz�Delete all VMs that are not defined in the map file. CAUTION!!! This operation can irrevocably destroy VMs! It must be explicitly enabled in the cloud config file.r%r$z	--destroyz"Destroy the specified instance(s).z--no-deployTZdeploy�store_falsez2Don't run a deploy script after instance creation.rbrLz
--parallelz1Build all of the specified instances in parallel.rz--update-bootstrapz=Update salt-bootstrap to the latest stable bootstrap release.�-y�--assume-yes�6Default "yes" in answer to all confirmation questions.z-kz
--keep-tmpz8Do not remove files from /tmp/ after deploy.sh finishes.z--show-deploy-argszCInclude the options used to deploy the minion in the data returned.z
--script-argszIScript arguments to be fed to the bootstrap script when deploying the VM.�-bz--bootstrapr7z<HOST> [MINION_ID] [OPTIONS...]zBootstrap an existing machine.)r=r�Zexecution_groupr{rPrPrrrr"�s�
���
���
����������z"ExecutionOptionsMixIn._mixin_setupcCsD|jjr|jj\|_|_|j�d�sd|jvr |�d�dSdSdS)Nr�=z<--function expects two arguments: <function-name> <provider>)rc�functionZ
function_nameZfunction_providerr9rWr|rrr�process_functionPs��z&ExecutionOptionsMixIn.process_functionN)rrrrr"r�rrrrr��s|r�c@rF)	�CloudQueriesMixInrNcCs�t�|d�}|_|jdddddd�|jdd	ddd
d�|jddddd
d�|jddddd�|jddddd�|�|�|��dS)Nz
Query Optionsz-Qz--queryFrxzbExecute a query and return some information about the nodes running on configured cloud providers.r%�-Fz--full-queryzaExecute a query and return all information about the nodes running on configured cloud providers.rcz--select-queryzdExecute a query and return select information about the nodes running on configured cloud providers.�--list-providersz'Display a list of configured providers.z--list-profiles�storez�Display a list of configured profiles. Pass in a cloud provider to view the provider's associated profiles, such as digitalocean, or pass in "all" to list all the configured profiles.)r=r��cloud_queries_groupr{rPrOrPrrrr"^sN
��
�
�
��
zCloudQueriesMixIn._mixin_setupcrQ)Ncs�t�j|j�rJd}|jdkr|d7}n2|jdkr|d7}n(|jdkr-d}�jr,��d�n|jdkrEd}t�j�}|�d�d	krE��d
�|�_dSdS)NZ
list_nodesZ
full_queryZ_fullZselect_query�_selectZlist_providersz0'--list-providers' does not accept any argumentsZ
list_profilesr�zC'--list-profiles' does not accept '--list-providers' as an argument)r
rcrArBrW�varsrm�selected_query_option)r��queryZoption_dictr|rrrp�s,




��

�
�z<CloudQueriesMixIn._create_process_functions.<locals>.processr7)r�rwrAr%r�rrSrr|rrO�s
��z+CloudQueriesMixIn._create_process_functionscrU)Ncs4g|]}t�j|j�durt�j|j�dur|�qS)FNrVrWr|rrrU�s�z9CloudQueriesMixIn._mixin_after_parsed.<locals>.<listcomp>r7rYrZcSr�rr[rWrrrrU�r\r�)r�rwr]rWr'r�r�rlr^rr|rr5�s
����z%CloudQueriesMixIn._mixin_after_parsed)rrrrr�r"rOr5rrrrr�Ys8r�c@r�)�CloudProvidersListsMixInr#cCsPt�|d�}|_|jdddd�|jdddd�|jdddd�|�|�dS)	NzCloud Providers Listingsz--list-locationsz�Display a list of locations available in configured cloud providers. Pass the cloud provider that available locations are desired on, such as "linode", or pass "all" to list locations for all configured cloud providers.r�z
--list-imagesz�Display a list of images available in configured cloud providers. Pass the cloud provider that available images are desired on, such as "linode", or pass "all" to list images for all configured cloud providers.z--list-sizesz�Display a list of sizes available in configured cloud providers. Pass the cloud provider that available sizes are desired on, such as "AWS", or pass "all" to list sizes for all configured cloud providers.)r=r��providers_listings_groupr{rPrPrrrr"�s(
��
�
�
z%CloudProvidersListsMixIn._mixin_setupcsJ�fdd��jjD�}t|�dkr#��d�d�dd�|D����dSdS)Ncs"g|]
}t�j|j�dur|�qSrrVrWr|rrrU�rXz@CloudProvidersListsMixIn._mixin_after_parsed.<locals>.<listcomp>r7rYrZcSr�rr[rWrrrrU�r\)r�rwr]rWr'r�)rZlist_options_selectedrr|rr5�s
�����z,CloudProvidersListsMixIn._mixin_after_parsedN)rrrrr"r5rrrrr��s&r�c@r)�ProfilingPMixIn�cCsFt�|d�}|_|jddddd�|jddd	d
dd�|�|�dS)
NzProfiling supportz--profiling-pathZprofiling_pathz
/tmp/statszFFolder that will hold all stats generations path. Default: '%default'.r'z--enable-profilingZprofiling_enabledFrxz>Enable generating profiling stats. See also: --profiling-path.�rAr�r@ry)r=r�Zprofiling_groupr{rPrPrrrr"s$
���zProfilingPMixIn._mixin_setupNr rrrrr�r!r�c@r�)�CloudCredentialsMixInr#cCs4t�|d�}|_|jdddddd�|�|�dS)NzCloud Credentialsz--set-passwordr�z<USERNAME> <PROVIDER>z�Configure password for a cloud provider and save it to the keyring. PROVIDER can be specified with or without a driver, for example: "--set-password bob rackspace" or more specific "--set-password bob rackspace:openstack" Deprecated.)r�r�r�ry)r=r�Zcloud_credentials_groupr{rPrPrrrr" s
��
z"CloudCredentialsMixIn._mixin_setupcCs|jjrtd��dS)NzwThis functionality is not supported; please see the keyring module at https://docs.saltproject.io/en/latest/topics/sdb/)rcZset_passwordr&r|rrr�process_set_password5s
��z*CloudCredentialsMixIn.process_set_passwordN)rrrrr"r�rrrrr�sr�c@r)�
EAuthMixInr#c	Csrt�|d�}|_|jdddddddd	�|jd
ddd
ddd�|jddddd�|jddddd�|�|�dS)NzExternal Authenticationr�z--authz--eauthz--external-authr�Zeauthz1Specify an external authentication system to use.rnz-Tz--make-tokenFZmktokenrxz�Generate and save an authentication token for re-use. The token is generated and made available for the period defined in the Salt Master.rbz
--username�usernamer7z%Username for external authentication.)rAr�ryz
--password�passwordz%Password for external authentication.)r=r�Zeauth_groupr{rPrPrrrr"@sD
��	���zEAuthMixIn._mixin_setupNr rrrrr�=r!r�c@r�)�JIDMixinr#cCr�)Nz--jidz0Pass a JID to be used instead of generating one.r�r�r|rrrr"ns

�zJIDMixin._mixin_setupcCs@|jjdurtjj�|jj�s|�d|jj�d��dSdSdS)Nr�z' is not a valid JID)rcZjidrdroZis_jidrWr|rrr�process_jidus
�zJIDMixin.process_jidN)rrrrr"r�rrrrr�jsr�c@�&eZdZdZdZejdZdd�ZdS)�MasterOptionParserz1The Salt Master, used to control the Salt Minions�masterr�cC�t�|���Sr�rl�
master_configr�r|rrrr��rzMasterOptionParser.setup_configN)	rrrrHr�rl�DEFAULT_MASTER_OPTSr�r�rrrrr�{s

r�c@r�)�MinionOptionParserz<The Salt Minion, receives commands from a remote Salt Master�minionr�cCstj|��ddd�S)NTF)�cache_minion_idZignore_config_errors)rl�
minion_configr�r|rrrr��s
�zMinionOptionParser.setup_configN)	rrrrHr�rl�DEFAULT_MINION_OPTSr�r�rrrrr��s

r�c@r�)�ProxyMinionOptionParserz~The Salt Proxy Minion, connects to and controls devices not able to run a minion.
Receives commands from a remote Salt Master.�proxyr�cCs8z|jj}Wntyd}Ynwtj|��d|d�S)NF�r��	minion_id)rrrmr�rl�proxy_configr�)rr�rrrr��s�
�z$ProxyMinionOptionParser.setup_configN)	rrrrHr�rlZDEFAULT_PROXY_MINION_OPTSr�r�rrrrr��s
�
r�c@s4eZdZdZdZdZejdZejeZ	dd�Z
dS)�SyndicOptionParserz�The Salt Syndic daemon, a special Minion that passes through commands from a
higher Master. Scale Salt to thousands of hosts or across many different networks.r�Zsyndic_log_filerVcCst�|��|�d��S)Nr�)rlZ
syndic_configr�r|rrrr��s�zSyndicOptionParser.setup_configN)rrrrHr�r�rlr�r�r�r�rrrrr��s�
�r�c@sreZdZdZdZdZdZejdZ	ejdZ
ze��Wne
y*e�d�Ynwdd	�Zd
d�Zdd
�ZdS)�SaltCMDOptionParser�z�Salt allows for commands to be executed across a swath of remote systems in
parallel, so they can be both controlled and queried with ease.�1%prog [options] '<target>' <function> [arguments]r�rVr�z1Cannot access current working directory. Exiting!c	Cs�|jdddddd�|jddddd	d�|jd
dddd�|jddd
ddd�|jddtdd�|jdddddd�|jdddddd�|jddddd�|jdd d!d"d#d$d%�|jd&dd'td(d)�|jd*dd+td,d)�|jd-d.d/d0d%�|jd1d"d2d3d4�|jd5d"d6d3d4�|jd7id8d9d4�|jd:d;d<d=ddd>d�|jd?d@dAdBdC�|jdDdEdddFd�|jdGd"dHdId4�|jdJdKdddLdM�|jdNdOdddPdM�|jdQdRdddSdM�dS)TN�-s�--staticFrx�>Return the data from minions as a group after they all return.r%r�z
--progressz@Display a progress graph. Requires "progressbar" python package.z
--failhardz-Stop batch execution upon first "bad" return.�--async�asyncz0Run the salt command but don't wait for a reply.rbz--subsetrz�Execute the routine on a random subset of the targeted minions. The minions will be verified that they have the named function before executing.�r�r�ry�-v�	--verbosez>Turn on command verbosity, display jid and active job queries.z--hide-timeoutZshow_timeoutTr�zHide minions that timeout.r�z
--show-jidz7Display jid without the additional output of --verbose.r�z--batchz--batch-sizer�Zbatchz�Execute the salt job in batch mode, pass either the number of minions to batch at a time, or the percentage of minions to have running.rnz--batch-waitZ
batch_waitzpWait the specified time in seconds after each job is done before freeing the slot in the batch for the next one.�r�rAr�ryz--batch-safe-limitZbatch_safe_limitz`Execute the salt job in batch mode if the job would have executed on at least this many minions.z--batch-safe-size�Zbatch_safe_sizez=Batch size to use for batch jobs created by batch-safe-limit.�--return�RETURNERz�Set an alternative return method. By default salt will send the return data from the command back to the master, but the return data can be redirected into any number of systems, databases or applications.�r�r�ryz--return_configZ
RETURNER_CONFz--return_kwargsZRETURNER_KWARGSz-Set any returner options at the command line.r$�--doc�--documentation�doc�[Return the documentation for the specified module or for all modules if none are specified.z--args-separator�args_separatorr�z�Set the special argument used as a delimiter between command arguments of compound commands. This is useful when one wants to pass commas as arguments to some of the commands in a compound command.r'z	--summaryZcli_summaryz1Display summary information about a salt command.�
--metadata�METADATA�-Pass metadata into Salt, used to search jobs.�
--output-diff�state_output_diff�+Report only those states that have changed.�rAr@r�ryz
--config-dump�config_dumpz$Dump the master configuration valuesz--preview-target�preview_targetzHShow the minions expected to match a target. Does not issue any command.)r{rj�floatr|rrrr"s(�����
�����
�
����������
�z SaltCMDOptionParser._mixin_setupcCs4t|j�dkr-|jjs-|jjs-z|��Wnty,tj�	d�t�
tjj
j�Ynw|jjrMt�|���}tj�	tjjj|dd��t�
tjj
j�|jjrW|j�d�|jjr�|jse|j�dd�t|j�dkrs|j�dd	�|jdd	kr�|j�dd	�t|j�d
kr�|�d�|jjr�z#d|jdvr�|jd�d
d��d�|jd<n
|jd��|jd<Wn)ty�|�
dd�Ynwz
|jd|jd<Wnty�|�
dd�Ynw|j�r�z#d|jdv�r�|jd�d�|jd<gg|jd<d}|jdd��|jj�t|jd�dk�r@|jdd�D]"}||jjk�r3|d7}|jd�g��q|jd|�|��qn||jdd�D]I}|jj|v�r�|�|jj�}t |�D]'\}}|�rl|jd|�|�|t|�dk�r�|d7}|jd�g��q[�qG|jd|�|��qGt|jd�t|jd�k�r�|�
dd�nt|jd�t|jd�k�r�|�
dd�t!t|jd��D]}tjjj"|jd||jj#d�|jd|<�q�WdS|jd|jd<|jdd�|jd<tjjj"|jd|jj#d�|jd<WdSt�y|�
dd�YdSwdS)Nr7z/Invalid options passed. Please try -h for help.F)Zdefault_flow_styleZnot_a_valid_commandr�*r�zsys.doc�z:You can only get documentation for one method at one time.r�� r��tgt�*z4
Cannot execute command without defining a target.

�funrTz@Cannot execute compound command without defining all arguments.
zCCannot execute compound command with more arguments than commands.
)r�z
Incomplete options passed.

)$r]rBrcr�r��
print_helprhr\r�r�r�rdr�r�r�r�rlr�r�rorZ	safe_dumpr�r�insertrWrrNr��
IndexError�countr��	enumerate�rangeZparse_inputr�)rZcfgZ	cmd_indexrTZsub_argsZ
sub_arg_indexZsub_arg�irrrr5�s�����

 ��������������z'SaltCMDOptionParser._mixin_after_parsedcCr�r�rl�
client_configr�r|rrrr�4	rz SaltCMDOptionParser.setup_configN)rrrrgrHrGr�rlr�r�r�r�r�r�r\r�r"r5r�rrrrr��s"�

�:pr�c@�HeZdZdZdZdZdZejdZ	ejdZ
dd�Zd	d
�Zdd�Z
d
S)�SaltCPOptionParserz�salt-cp is NOT intended to broadcast large files, it is intended to handle text
files. salt-cp can be used to distribute configuration files.z&%prog [options] '<target>' SOURCE DESTr�r�rVr�cCsFt�|d�}|jddddddd�|jd	d
ddd
dd�|�|�dS)NzFile Optionsr`z	--chunkedF�chunkedrxzZUse chunked files transfer. Supports big files, recursive lookup and directories creation.rbz-nz--no-compressionT�gzipr�zDisable gzip compression.)r=r�r{rP)rZfile_opts_grouprrrr"T	s$��zSaltCPOptionParser._mixin_setupcCs�t|j�dkr|��|�d�|jjr2d|jdvr'|jd�d�|jd<n|jd��|jd<n|jd|jd<dd�|jdd�D�|jd	<|jd|jd
<dS)Nr7�Insufficient argumentsr�rr�cSsg|]}tj�|��qSr)r�r��realpathr�rrrrUx	r�z:SaltCPOptionParser._mixin_after_parsed.<locals>.<listcomp>r��srcrA)r]rBr�rWrcrr�rlr|rrrr5k	s
z&SaltCPOptionParser._mixin_after_parsedcCr�rr�r|rrrr�{	rzSaltCPOptionParser.setup_configN)rrrrHrGrgr�rlr�r�r�r"r5r�rrrrr�8	s
�

r�cs~eZdZdZdZdZdZejeZ	dd�Z
�fdd�Zej
e_
d	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zdd�Z�ZS)�SaltKeyOptionParserz3salt-key is used to manage Salt authentication keysr�)r�Zkey_logfilecCs<t�|d�}|�d�|jdddddd�|jd	d
ddd
d�|jddddd�|jdddddd�|jddddd�|jdddddd�|jddddd�|jddddd�|jd ddd!d�|jd"ddd#d�|jd$d%dd&d�|jd'd(ddd)d�|jd*d+dd,d�|jd-d.ddd/d�|jd0d1dd2d�|jd3d4ddd5d�|�|�|jd6d7ddd8d�|jd9d:ddd;d�|jd<d=d>d�|jd?dd@d�t�|dA�}|�|�|jdBddCd�|jdDdEdFd�|jdGdHtdIdJ�|jdKdddLd�|jdMdtdNdJ�|jdOdtdPdJ�|jdQdtdRdJ�|jdSdddTd�dS)UNZActions�resolver�rKr�ZARGa
List the public keys. The args 'pre', 'un', and 'unaccepted' will list unaccepted/unsigned keys. 'acc' or 'accepted' will list accepted/signed keys. 'rej' or 'rejected' will list rejected keys. 'den' or 'denied' will list denied keys. Finally, 'all' will list all keys.r�rJz
--list-allFrxz3List all public keys. Deprecated: use "--list all".r%r�z--acceptz�Accept the specified public key (use --include-rejected and --include-denied to match rejected and denied keys in addition to pending keys). Globs are supported.r�z-Az--accept-allzAccept all pending keys.�-rz--rejectz�Reject the specified public key. Use --include-accepted and --include-denied to match accepted and denied keys in addition to pending keys. Globs are supported.rMz--reject-allzReject all pending keys.z
--include-allzwInclude rejected/accepted keys when accepting/rejecting. Deprecated: use "--include-rejected" and "--include-accepted".z--include-acceptedz%Include accepted keys when rejecting.z--include-rejectedz%Include rejected keys when accepting.z--include-deniedz-Include denied keys when accepting/rejecting.r�z--printzPrint the specified public key.rLz--print-allzPrint all public keys.r$z--deletez.Delete the specified key. Globs are supported.z-Dz--delete-allzDelete all keys.r�z--fingerz&Print the specified key's fingerprint.r�z--finger-allzPrint all keys' fingerprints.z-q�--quietzSuppress output.r�z--yesz;Answer "Yes" to all questions presented. Default: %default.z--rotate-aes-keyTz�Setting this to False prevents the master from refreshing the key session when keys are deleted or rejected, this lowers the security of the key deletion/rejection operation. Default: %default.z--preserve-minionsz�Setting this to True prevents the master from deleting the minion cache when keys are deleted, this may have security implications if compromised minions auth with a previous deleted minion ID. Default: %default.zKey Generation Optionsz
--gen-keysz3Set a name to generate a keypair for use with salt.z--gen-keys-dirrzjSet the directory to save the generated keypair, only works with "--gen-keys" option. Default: '%default'.z	--keysize�z�Set the keysize for the generated key, only works with the "--gen-keys" option, the key size must be 2048 or higher, otherwise it will be rounded up to 2048. Default: %default.r�z--gen-signaturea<Create a signature file of the masters public-key named master_pubkey_signature. The signature can be send to a minion in the masters auth-reply and enables the minion to verify the masters public-key cryptographically. This requires a new signing-key-pair which can be auto-created with the --auto-create parameter.�--privz0The private-key file to create a signature with.z--signature-pathz4The path where the signature file should be written.z--pubz.The public-key file to create a signature for.z
--auto-createz8Auto-create a signing key-pair if it does not yet exist.)r=r�Zset_conflict_handlerr{rPrjr�)rZ
actions_groupZkey_options_grouprrrr"�	sP
�������
���������

����
��	�����
�z SaltKeyOptionParser._mixin_setupcsR|jjr"t�|jjtj�s"tj�|jj�st�	|jj�|jj|j_t
���dSr)rc�gen_keysr��accessr��R_OKr�r��gen_keys_dirr
r#r�r|r-rrr��
sz&SaltKeyOptionParser.process_config_dircCs&t�|���}|jjr|jj|d<|S)NZpki_dir)rlr�r�rcr�r�)rZkeys_configrrrr��
sz SaltKeyOptionParser.setup_configcC�^t|jd�r)t|jjt�r+|jj��dkrd|j_dS|jj��dkr-d|j_dSdSdSdS)N�rotate_aes_keyr�Tr�F)r%rcrr�r��lowerr|rrr�process_rotate_aes_key�
���z*SaltKeyOptionParser.process_rotate_aes_keycCr�)N�preserve_minionsr�Tr�F)r%rcrr�r�r�r|rrr�process_preserve_minions�
r�z,SaltKeyOptionParser.process_preserve_minionscCs8|jjsdS|jj�d�s|�d|jj�d��dSdS)N)�accZpreZunZrejZden�allr�z%' is not a valid argument to '--list')rcrr9rWr|rrr�process_list�
s
�z SaltKeyOptionParser.process_listcCs8|jjdkr
|�d�dS|jjdkr|�d�dSdS)Nr�z%The minimum value for keysize is 2048i�z&The maximum value for keysize is 32768)rcZkeysizerWr|rrr�process_keysize�
s
�z#SaltKeyOptionParser.process_keysizecCs|jjr
|j�|j�dSdSr)rcr�r3r�%_SaltKeyOptionParser__create_keys_dirr|rrr�process_gen_keys_dir�
s
��z(SaltKeyOptionParser.process_gen_keys_dircCs*tj�|jd�st�|jd�dSdS)Nr�)r�r�r�rlr
r|rrrZ__create_keys_dir�
s�z%SaltKeyOptionParser.__create_keys_dir)rrrrHr�r�r�rlr�r�r"r�r�rr�r�rrrrrr/rrr-rr�	s&
�s		r�c@sLeZdZdZdZdZejdZejdZ	dd�Z
dd	�Zd
d�Zdd
�Z
dS)�SaltCallOptionParserzFsalt-call is used to execute module functions locally on a Salt Minion�&%prog [options] <function> [arguments]r�rVr�c	CsX|jddddddd�|jdd	gd
dd�|jd
ddddddd�|jddddd�|jddddd�|jddddd�|jdddd�|jd dd!d�|jd"dd#d�|jd$ddd%d�|jd&dd'dd(d)�|jd*d+dd,d-d.�|jd/dd0d1d�|jd2ddd3d�|jd4ddd5d�|jd6ddd7d�|jd8d9d:d;td<d=�|jd>d?ddd@dA�dS)BNz-gz--grains�
grains_runFrxz4Return the information generated by the salt grains.r�r�z
--module-dirsrz�Specify an additional directory to pull modules from. Multiple directories can be provided by passing `-m/--module-dirs` multiple times.r%r$r�r�r�r�z--masterr�r�z�Specify the master to use. The minion must be authenticated with the master. If this option is omitted, the master options from the minion config will be used. If multi masters are set up the first listed master that responds will be used.rnr�r�zISet salt-call to pass the return data to one or many returner interfaces.r�z--localz9Run salt-call locally, as if there was no master running.z--file-rootz)Set this directory as the base file root.r�z
--pillar-rootz+Set this directory as the base pillar root.z--states-dirz3Set this directory to search for additional states.z--retcode-passthroughz@Exit with the salt call retcode and not the salt binary retcode.r�Zprint_metadatazuPrint out the execution metadata as well as the return. This will print out the outputter data, the return code, etc.rbz--set-metadata�metadatar�r�rqz--id�idzkSpecify the minion id to use. If this option is omitted, the id option from the minion config will be used.�
--skip-grains�Do not load grains.z--refresh-grains-cachez$Force a refresh of the grains cache.z--no-return-eventz/Do not produce the return event back to master.rhri�<Zauth_timeoutzNChange the timeout, if applicable, for the running command. Default: %default.r�r�r�r�r�)r{rjr|rrrr"�
s������	��������	����
�z!SaltCallOptionParser._mixin_setupcCs�|js|jjs|jjs|��|�d�dSt|j�dkrJ|jjr&|�d�|jjr6t|j�dkr6|�d�|jd|jd<|jdd�|jd<dSdS)Nz$Requires function, --grains or --docr7z)-g/--grains does not accept any arguments�9You can only get documentation for one method at one timerr�rT)rBrcr	r�r�rWr]rlr|rrrr5|s

�z(SaltCallOptionParser._mixin_after_parsedcCs>|jjrtj|jdd�d|jjd�}|Stj|��dd�}|S)Nr�)r�Tr�)r�)rcrmrlr�r�r�)r�optsrrrr��s
�	��z!SaltCallOptionParser.setup_configcCs\|jjD]'}d|vr|j�dg��dd�|�d�D��q|j�dg��tj�	|��qdS)Nr��module_dirscss�|]	}tj�|�VqdSr)r�r�r�r�rrr�	<genexpr>�s�
�z;SaltCallOptionParser.process_module_dirs.<locals>.<genexpr>)
rcrrlrKr`r�rr�r�r�)rZ
module_dirrrr�process_module_dirs�s�
��z(SaltCallOptionParser.process_module_dirsN)rrrrHrGr�rlr�r�r�r"r5r�rrrrrr�
s�


rc@r�)�SaltRunOptionParserr7z�salt-run is the frontend command for executing Salt Runners.
Salt Runners are modules used to execute convenience functions on the Salt Masterrr�rVr�c	Csp|jdddddddd�|jd	ddd
d�|jdddd
d�t�|dd�}|_|�|�|jddddd�dS)Nr$r�r�r�FrxzyDisplay documentation for runners, pass a runner or runner.function to see documentation on only that runner or function.r�r�z:Start the runner operation and immediately return control.r%rr
rtrur�z&Do not display the results of the run.)r{r=r�r{rPrPrrrr"�s>�
��
�

�z SaltRunOptionParser._mixin_setupcCsv|jjrt|j�dkr|�d�|jr|jd|jd<nd|jd<t|j�dkr4|jdd�|jd<dSg|jd<dS)Nr7rrr�r�rT)rcr�r]rBrWrlr|rrrr5�s

z'SaltRunOptionParser._mixin_after_parsedcCr�rr�r|rrrr��rz SaltRunOptionParser.setup_configN)rrrrgrHrGr�rlr�r�r�r"r5r�rrrrr�s�

&
rc@sDeZdZdZdZdZejdZejeZ	dd�Z
dd�Zd	d
�ZdS)�SaltSSHOptionParserr�r�Zssh_log_filerVc	Cs�|jdddddddd�|jd	d
ddd
�|jddddd
�|jddddddd�|jdddtdd�|jddddd
�|jdddd d
�|jd!d"dd#d
�|jd$d%ddd&d'�|jd(d)ddd*d'�|jd+d,ddd-d.d/�|jd0d1ddd2d'�|jd3d4d5d6ddd7d�|jd8d9d:d;�|jd<d=d>d;�|jd?ddd@dAd/�t�|dBdC�}|jdDdEdFdG�|jdHdIdJdKdL�|�|�t�|dMdN�}|jdOdPdQdG�|jdRdSddTd
�|jdUdVdWdddXd�|jdYdZddd[d�|jd\d]d^d_d
�|jd`daddbd
�|jdcddddded�|jdfdgdddhd�|jdidjdddkd�|jdldmdddnd�|jdodpdddqd�|�|�t�|drds�}|jdtdudvdwdx�|jdydzd{d|dx�|�|�dS)}Nr�z--rawz--raw-shellZ	raw_shellFrxzIDon't execute a salt routine on the targets, execute a raw shell command.r�z--rosterZrosterZflatz�Define which roster system to use, this defines if a database backend, scanner, or custom roster system is used. Default: 'flat'.r'z
--roster-fileZroster_filer�z�Define an alternative location for the default roster file location. The default roster file is called roster and is found in the same directory as the master config file.z	--refreshz--refresh-cacheZ
refresh_cachez�Force a refresh of the master side data cache of the target's data. This is needed if a target's grains have been changed and the auto refresh timeframe has not been reached.z--max-procsZ
ssh_max_procs�z�Set the number of concurrent minions to communicate with. This value defines how many processes are opened up at a time to manage connections, the more running processes the faster communication should be. Default: %default.rwz--extra-filerefsZextra_filerefsz4Pass in extra files to include in the state tarball.z--min-extra-modulesZmin_extra_modszUOne or comma-separated list of extra Python modules to be included into Minimal Salt.z--thin-extra-modulesZthin_extra_modszROne or comma-separated list of extra Python modules to be included into Thin Salt.r�r�z'Turn on command verbosity, display jid.r%r�r�r�z-wz--wipeZssh_wipez<Remove the deployment of the salt files when done executing.rIz-Wz--rand-thin-dirzeSelect a random temp dir to deploy on the remote system. The dir will be cleaned after the execution.rhz--regen-thinz--thinZ
regen_thinzoTrigger a thin tarball regeneration. This is needed if custom grains/modules/states have been added or updated.z
--python2-binZpython2z2Path to a python2 binary which has salt installed.r�z
--python3-binZpython3z2Path to a python3 binary which has salt installed.z--pre-flightZssh_run_pre_flightz3Run the defined ssh_pre_flight script in the rosterzSSH OptionszParameters for the SSH client.z--remote-port-forwardsZssh_remote_port_forwardsz�Setup remote port forwarding using the same syntax as with the -R parameter of ssh. A comma separated list of port forwarding definitions will be translated into multiple -R parameters.rvz--ssh-optionZssh_optionsrz�Equivalent to the -o ssh command option. Passes options to the SSH client in the format used in the client configuration file. Can be used multiple times.)rAr@ryzAuthentication Optionsz$Parameters affecting authentication.r�Zssh_privzSsh private key file.z
--priv-passwdZssh_priv_passwdz$Passphrase for ssh private key file.z-iz--ignore-host-keysZignore_host_keysz}By default ssh host keys are honored and connections will ask for approval. Use this option to disable StrictHostKeyChecking.z--no-host-keysZno_host_keysz=Removes all host key checking functionality from SSH session.rZssh_user�rootz;Set the default user to attempt to use when authenticating.z--passwd�
ssh_passwdz?Set the default password to attempt to use when authenticating.z	--askpass�ssh_askpasszlInteractively ask for the SSH password with no echo - avoids password in process args and stored in history.z--key-deployZssh_key_deployz�Set this flag to attempt to deploy the authorized ssh key with all minions. This combined with --passwd can make initial deployment of keys very fast and easy.z--identities-onlyZssh_identities_onlyzyUse the only authentication identity files configured in the ssh_config files. See IdentitiesOnly flag in man ssh_config.z--sudoZssh_sudozRun command via sudo.z--update-rosterZssh_update_rosterzbIf hostname is not found in the roster, store the information into the default roster file (flat).zScan Roster Optionsz!Parameters affecting scan roster.z--scan-portsZ22Zssh_scan_portsz9Comma-separated list of ports to scan in the scan roster.rnz--scan-timeoutg{�G�z�?Zssh_scan_timeoutz,Scanning socket timeout for the scan roster.)r{rjr=r�rP)rZ	ssh_groupZ
auth_groupZ
scan_grouprrrr"s���
��
���	�	����
������
�

�������
��
��

���z SaltSSHOptionParser._mixin_setupcCs|js|��|�d�|jjr.d|jdvr#|jd�d�|jd<n|jd��|jd<n|jd|jd<|jdd�|jd<|jdrJ|jdsS|��|�d�|jjrf|jd�dd�	|jj��|jj
r�t�d�|j_|j
D]}|jD]}|jd	kr�d
|_nqyqtdSdS)Nr�r�rr�r7�argvz--no-parse=z
Password: rT)rBr�rWrcrr�rlr�rr�r�getpassrr�rwrAr<)rr�r�rrrr5/
s2




���z'SaltSSHOptionParser._mixin_after_parsedcCr�rr�r|rrrr�N
rz SaltSSHOptionParser.setup_configN)
rrrrGr�r�rlr�r�r�r"r5r�rrrrr�s
�rcs\eZdZdZdZdZejdZejdZ	e
jfdd�Zd�fd	d
�	Z
dd�Zd
d�Z�ZS)�SaltCloudParserz�Salt Cloud is the system used to provision virtual machines on various public
clouds via a cleanly controlled profile and mapping systemz8%prog [options] <-m MAP | -p PROFILE> <NAME> [NAME2 ...]ZcloudrVr�cCs.td�tjdd��|d�|�tjjj�dS)Nr}T)Zinclude_salt_cloud)r~r�r�rrrrbo
sz%SaltCloudParser.print_versions_reportNc
sVzddlm}|��Wnty#}z|�|�WYd}~nd}~wwt��||�S)Nr)�
libcloudfuncs)Z
salt.cloudrZcheck_libcloud_version�ImportErrorrWr#rZ)rrBrrrr�r-rrrZu
s��zSaltCloudParser.parse_argscCsPdtjvrddl}td�|�|j�|�tjjj	�|j
r&|j
|jd<dSdS)NZDUMP_SALT_CLOUD_CONFIGrz7Salt Cloud configuration dump (INCLUDES SENSIBLE DATA):�names)r�r��pprintr�rlr�rdr�r�r�rB)rr rrrr5
s
�z#SaltCloudParser._mixin_after_parsedc
CsFzt�|���WStjjy"}z|�|�WYd}~dSd}~wwr)rlZcloud_configr�rdr�ZSaltCloudConfigErrorrWr�rrrr��
s��zSaltCloudParser.setup_configr�)rrrrHrGr�rlZDEFAULT_CLOUD_OPTSr�r�r\r�rbrZr5r�r/rrr-rrR
s�


�
rc@sBeZdZdZdZdZdZdZej	eZ
dd�Zdd	�Zd
d�Z
dS)
�	SPMParserzD
    The CLI parser object used to fire up the Salt SPM system.
    zBSPM is used to manage 3rd party formulas and other Salt componentsz%%prog [options] <function> <argument>ZspmZspm_logfilecCs@|jdddddd�|jdddddd�|jd	d
dddd�dS)Nr�r�Frxr�r%r�z--forcer�r�z"Display more detailed information.r�r|rrrr"�
s*��
�zSPMParser._mixin_setupcCs@t|j�dkr|jr|jddvr|��|�d�dSdSdS)Nr7r)Zupdate_repor�)r]rBr�rWr|rrrr5�
s�zSPMParser._mixin_after_parsedcC�tj�|���Sr)rdrlZ
spm_configr�r|rrrr��
rzSPMParser.setup_configN)rrrr�rHrGr�r�rlZDEFAULT_SPM_OPTSr�r"r5r�rrrrr!�
s
r!c@s.eZdZdZdZdZdZejeZ	dd�Z
dS)�
SaltAPIParserzD
    The CLI parser object used to fire up the Salt API system.
    zFThe Salt API system manages network API connectors for the Salt Masterr�Zapi_logfilecCr"r)rdrlZ
api_configr�r|rrrr��
s�zSaltAPIParser.setup_configN)rrrr�rHr�r�rlZDEFAULT_API_OPTSr�r�rrrrr#�
s�
r#)Yr�rrr�r=r�r:r\rjr�	functoolsrZ
salt._loggingrdZsalt.configrlZsalt.defaults.exitcodesZsalt.exceptionsZ
salt.syspathsr�Zsalt.utils.argsZsalt.utils.dataZsalt.utils.filesZsalt.utils.jidZsalt.utils.platformr-Zsalt.utils.stringutilsZsalt.utils.userZsalt.utils.win_functionsZsalt.utils.xdgZsalt.utils.yamlZsalt.versionrFZ
salt.defaultsrZsalt.utils.validate.pathrZsalt.utils.verifyrrrrBrrfrrrr�r!r0r>r;rDr�r�r�r�r�r�rr"rGr_rerkrlrprrrsr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr!r#rrrr�<module>s�


(	'My-R	:		n: -
�
�
�
!�
 �
U�
G�
Q�
Y�
X�
V�
?�
8
�