%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_rsyslog.cpython-312.pyc

�

���f�2�
��UdZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZddl
mZddlmZddlmZddlmZmZdd	lmZd
egeed�ed�ed
�gdgd�Zeed<dddiiddgdd�Zddgd�ddgd�ddgd�d�Zej8e�Zej>d�Z ej>d�Z!defd�Z"d/d �Z#d0d!�Z$d"e%ded#e%fd$�Z&d%�Z'd1d&�Z(Gd'�d(�Z)d2d)�Z*d*ed#dfd+�Z+d,e,d"ed*ed-e-d#df
d.�Z.y)3z-Rsyslog: Configure system logging via rsyslog�N)�dedent)�	lifecycle�log�subp�util)�Cloud)�Config)�
MetaSchema)�ALL_DISTROS�Distro)�PER_INSTANCE�
cc_rsyslogz�            rsyslog:
                remotes:
                    maas: 192.168.1.1
                    juju: 10.0.4.1
                service_reload_command: auto
            a7            rsyslog:
                config_dir: /opt/etc/rsyslog.d
                config_filename: 99-late-cloud-config.conf
                configs:
                    - "*.* @@192.158.1.1"
                    - content: "*.*   @@192.0.2.1:10514"
                      filename: 01-example.conf
                    - content: |
                        *.*   @@syslogd.example.com
                remotes:
                    maas: 192.168.1.1
                    juju: 10.0.4.1
                service_reload_command: [your, syslog, restart, command]
            a            # default (no) configuration with package installation on FreeBSD
            rsyslog:
                config_dir: /usr/local/etc/rsyslog.d
                check_exe: "rsyslogd"
                packages: ["rsyslogd"]
                install_rsyslog: True
            �rsyslog)�id�distros�	frequency�examples�activate_by_schema_keys�metaz/etc/rsyslog.dz20-cloud-config.conf�auto�rsyslogdF)�
config_dir�config_filename�service_reload_command�remotes�configs�	check_exe�packages�install_rsyslogz/usr/local/etc/rsyslog.d)rrzsysutils/rsyslogz/usr/pkg/etc/rsyslog.d)�freebsd�openbsd�netbsdz[ ]*[#]+[ ]*z_^(?P<proto>[@]{0,2})(([\[](?P<bracket_addr>[^\]]*)[\]])|(?P<addr>[^:]*))([:](?P<port>[0-9]+))?$�distroc��t}tjt�}|j|vr&t	j
|||jgd��}|S)z�Construct a distro-specific rsyslog config dictionary by merging
       distro specific changes into base config.

    @param distro: String providing the distro class name.
    @returns: Dict of distro configurations for ntp clients.
    T)�reverse)�DISTRO_OVERRIDES�copy�RSYSLOG_CONFIG�osfamilyr�
mergemanydict�name)r#�dcfg�cfgs   �=/usr/lib/python3/dist-packages/cloudinit/config/cc_rsyslog.py�distro_default_rsyslog_configr/lsH���D�
�)�)�N�
#�C�
���$��� � �#�t�F�K�K�'8�!9�4�H���J�c�J�tj|�ry|�dg}||�y)aiInstall rsyslog package if not already installed.

    @param install_func: function.  This parameter is invoked with the contents
    of the packages parameter.
    @param packages: list.  This parameter defaults to ['rsyslog'].
    @param check_exe: string.  The name of a binary that indicates the package
    the specified package is already installed.
    Nr)r�which)�install_funcrrs   r.rrzs(���z�z�)������;����r0c��|dk(r$|jdd�}|jd|�Stj|d��S)Nr�rsyslog_svcnamerz
try-reloadT)�capture)�
get_option�manage_servicer)r#�command�services   r.�
reload_syslogr;�sA���&���#�#�$5�y�A���$�$�\�7�;�;��9�9�W�d�+�+r0r-�returnc�D�|jdi�}t|�}t|jd�t�rBt	j
dd��d|jd�i}d|vr|d|d<d|vr|d|d	<dgtfd	|d	tfd|dtfd
|d
tfd|dttffd|dtfd
|d
tfd|dtff}|D]?\}}}||vr|||<�t|||�r�!td|�d|�dt||�����|S)z�Return an updated config.

    Support converting the old top level format into new format.
    Raise a `ValueError` if some top level entry has an incorrect type.
    rz)The rsyslog key with value of type 'list'z22.2)�
deprecated�deprecated_versionr�rsyslog_filenamer�rsyslog_dirrrrrrrzInvalid type for key `z`. Expected type(s): z. Current type: )�getr/�
isinstance�listr�	deprecate�str�dict�bool�
ValueError�type)r-r#�mycfg�
distro_config�fillup�key�default�vtypess        r.�load_configrQ�s���
�G�G�I�r�"�E�1�&�9�M��#�'�'�)�$�d�+����B�%�	
��C�G�G�I�.�/����$�'*�+=�'>�E�#�$��C��"%�m�"4�E�,��
�B���	�}�\�2�C�8�	�M�*;�<�c�B�	�M�)�,�d�3�$��2�3�
�$�K�	
�

�m�K�0�#�6�	�]�:�.��5�	�M�*;�<�d�C�
�F�!'����W�f��e�� �E�#�J��E�#�J��/��(���-B�6�(�K!�!%�e�C�j�!1� 2�4��
�	��Lr0c�F�g}t|�D]�\}}t|t�r6d|vrtj	d|dz��4|d}|jd|�}n|}|}|j
�}|stj	d|dz��|tjj||�}d}||vrd}|j|�	d}	|jd	�sd	}	tj|||	z|�
���|S#t$rtjtd|�Y��wxYw)N�contentz%No 'content' entry in config entry %s��filenamezEntry %s has an empty filename�ab�wb��
)�omodezFailed to write to %s)�	enumeraterCrG�LOG�warningrB�strip�os�path�join�append�endswithr�
write_file�	Exception�logexc)
r�	def_fname�cfg_dir�files�cur_pos�entrSrUrZ�endls
          r.�apply_rsyslog_changesrm�s)��
�E�!�'�*� @�����c�4� ���#����;�W�q�[����)�n�G��w�w�z�9�5�H��G� �H��>�>�#����K�K�8�'�A�+�F���7�7�<�<���2�����5� ��E��L�L��"�	@��D��#�#�D�)����O�O�H�g��n�E�B�= @�D�L���	@��K�K��4�h�?�	@�s�0C8�8$D �D c��	tj|�\}}|j�}|j�j�}d}t	|�dk(r|}n"t	|�dk(r|\}}ntd|z��t
j
|�}|std|z��|jd�}|jd�xs|jd�}|jd�}	|jd	�r|jd
�std|z��|r|s|}t|||||	��}
|
j�|
S#t$r|d}}Y��&wxYw)
NrT�zline had multiple spaces: %szInvalid host specification '%s'�proto�addr�bracket_addr�port�[�]z"host spec had invalid brackets: %s�r+�matchrprqrs)�
COMMENT_RE�splitr^rI�len�HOST_PORT_RErw�group�
startswithrc�SyslogRemotesLine�validate)�liner+�data�comment�toksrw�	host_portrprqrs�ts           r.�parse_remotes_liner��sD��%�"�(�(��.�
��g��-�-�/���:�:�<����D��E�
�4�y�A�~��	�	�T��a�����y��7�$�>�?�?����i�(�D���:�Y�F�G�G��J�J�w��E��:�:�f��;����N�!;�D��:�:�f��D����s��D�M�M�#�$6��=��D�E�E��t����
��e�$�T�	�A��J�J�L��H��?�%��t�g��%�s�(E�
E�Ec�(�eZdZ	dd�Zd�Zd�Zd�Zy)r~Nc��|sd}||_||_|sd}|dk(rd}n|dk(rd}||_||_|rt	|�|_yd|_y)Nz*.*�udp�@�@@�tcp)r+rwrprq�intrs)�selfr+rwrprqrss      r.�__init__zSyslogRemotesLine.__init__s]����E���	���
���E��C�<��E�
�d�]��E���
���	���D�	�D�I��D�Ir0c���|jr	t|j�|jstd��y#t$r}td|jz�|�d}~wwxYw)Nzport '%s' is not an integerzaddress is required)rsr�rIrq)r��es  r.rzSyslogRemotesLine.validate&sa���9�9�
��D�I�I���y�y��2�3�3����
� �1�D�I�I�=�����
�s�;�	A"�A�A"c��d|j�d|j�d|j�d|j�d|j�d�S)Nz[name=z match=z proto=z	 address=z port=rurv)r�s r.�__repr__zSyslogRemotesLine.__repr__2s/���I�I��J�J��J�J��I�I��I�I�
�	
r0c�T�|jdz}|jdk(r|dz
}n|jdk(r|dz
}d|jvr|d|jzdzz
}n||jz
}|jr|d	|jzz
}|jr|d
|jzz
}|S)N� r�r�r�r��:rtruz:%sz # %s)rwrprqrsr+)r��bufs  r.�__str__zSyslogRemotesLine.__str__;s����j�j�3����:�:����3�J�C�
�Z�Z�5�
 ��4�K�C��$�)�)���3����?�S�(�(�C��4�9�9��C��9�9��5�4�9�9�$�$�C��9�9��7�T�Y�Y�&�&�C��
r0)NNNNN)�__name__�
__module__�__qualname__r�rr�r��r0r.r~r~s��AE��*
4�
�r0r~c	�^�|syg}|�|j|�|j�D].\}}|s�		|jtt||�����0|�|j|�dj|�dzS#t$r"}t
j
d|||�Yd}~�~d}~wwxYw)N)r+z!failed loading remote %s: %s [%s]rY)rb�itemsrFr�rIr\r]ra)r�header�footer�linesr+r�r�s       r.�remotes_to_rsyslog_cfgr�Os������E�
��
���V���m�m�o�L�
��d���	L��L�L��/��4�@�A�B�	L���
���V���9�9�U��d�"�"��	�	L��K�K�;�T�4��K�K��	L�s�%B�	B,�
B'�'B,�cloudc��	|jjdd�|jjdd�|jj	�tjtj�5|jjdd�tjd�ddd�y#tj$rYywxYw#1swYyxYw)z�
    This helper function bundles the necessary steps to disable BSD base syslog
    ``rc(8)`` reads its configuration on start, so after disabling syslogd, we
    need to tell rc to reload its config
    �enabled�syslogdN�disable�onestopzOsyslogd is running before cloud-init! Please report this as bug to the porters!)	r#r8r�ProcessExecutionError�reload_init�
contextlib�suppressr\�error)r�s r.� disable_and_stop_bsd_base_syslogr�as����
���#�#�I�y�9�
�L�L���	�9�5�	�L�L����	�	�	�T�7�7�	8�
�	���#�#�I�y�9��	�	�
8�	
�
�
���%�%�����

�
�s�B2�72C�2C�C�Cr+�argsc��d|vrtjd|�yt||j�}|d}|dr |j	t|ddd���|jj
dd�}|d	d
ur(t|jj|d|d�
�tj�r'|jjd|�t|�|dstjd�yt|d|d|d��}|stjd�y	t|j|d��}|rKt'j(�t'j*|j,�tjd||�yy#tj $r+}	d}tj#dt%|	��Yd}	~	��d}	~	wwxYw)Nrz;Skipping module named %s, no 'rsyslog' key in configurationrrz# begin remotesz
# end remotes)r�r�r5rTrr)rr�enablez.Empty config rsyslog['configs'], nothing to dorr)rrgrhz0restart of syslog not necessary, no changes mader)r9FzFailed to reload syslog %sz%s configured %s files)r\�debugrQr#rbr�r7r�install_packagesr�is_BSDr8r�rmr;rr�r]rFr�
reset_logging�
setup_loggingr-)
r+r-r�r�rKrr:�changes�	restartedr�s
          r.�handler�ys�������	�	�I�4�	
�	���U�\�\�*�E��I��G��Y�����"��i� �(�&�
�	
��l�l�%�%�&7��C�G��
��4�'���L�L�)�)��:�&��K�(�	
��{�{�}�
���#�#�H�g�6�(��/�����	�	�B�C��#��i� ��)�*��l�#��G���	�	�D�E��:�!��L�L�%�(@�"A�
�	��	�������%�)�)�$�	�	�	�*�D�'�:���	�%�%�:��	����0�#�a�&�9�9��:�s�-F�G�(!G�G)Nr)r)N)NN)/�__doc__r�r'�loggingr_�re�textwrapr�	cloudinitrrrr�cloudinit.cloudr�cloudinit.configr	�cloudinit.config.schemar
�cloudinit.distrosrr�cloudinit.settingsr
r�__annotations__r(r&�	getLoggerr�r\�compilerxr{r/rr;rGrQrmr�r~r�r�rFrDr�r�r0r.�<module>r�s���4����	�	��0�0�!�#�.�1�+���}���
�	
�	�
�	
�"	�
�		
�7%�L!*�{�U+��j�+�\#�-�$�������	��1��K��
1�'�(��
/�'�(��
���g����!��
�R�Z�Z��
(�
��r�z�z�����&���",�,�T�,�6�,�d�,�^&�R#
�L<�<�~#�$
�E�
�d�
�0=;��=;�6�=;�%�=;�t�=;��=;r0

Zerion Mini Shell 1.0