Current File : //proc/self/root/usr/lib/python3/dist-packages/cloudinit/__pycache__/util.cpython-312.pyc
�

��+h�j�	��
�ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
ZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZmZddl m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'dd	l(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6dd
l7m8Z8ddl9Z9ddl:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEddlFmGZGdd
lHmIZImJZJe*rddlKmLZLdaMej�eO�ZPej�diZRdej�zej�zZUdZVdZWd�ZXe#�d��ZYe#�d��ZZd�de5e[e\fde[fd�Z]d�de5e[e\fde\fd�Z^e?j�d�de\de\fd��Z`d�ZaGd�d �ZbGd!�d"ec�ZdGd#�d$ec�Zed%�Zfd�d&�Zgd�d'�Zhd�d(�Zid�d)�Zjd�d*�Zkdd+�de.fd,�Zld-�Zmd.�Znd/�Zod�d1�Zpd2�Zqd3e[derfd4�Zse#�d5��Zte#�d6��Zue#�d7��Zve#�d8��Zwe#�d9��Zxe#�d:��Zyd�d<�Zzd�d=�Z{d�d>�Z|d�d?�Z}e#�d@��Z~dA�Ze#�dB��Z�d�dC�Z�d�dD�Z�dE�Z�d�dF�Z�d�dGe4e1derfdH�Z�ej<dI��Z�ej<dJ��Z�dK�Z�dL�Z�d�dM�Z�d�dN�Z�derffdO�Z�d�dP�Z�dd+�derfdQ�Z�dd+�derfdR�Z�d�dS�Z�d�dT�Z�dU�Z�GdV�dWe2�Z�d�dX�Z�d�dY�Z�e?j�dZ�de�fd[��Z�d\�Z�d]�Z�d^�Z�d_�Z�	d�d`�Z�	d�da�Z�	d�db�Z�	d�dc�Z�	d�dd�Z�d�de�Z�df�Z�dd;dg�dhe5e[e�jFfdie3e,e�gdfdje�de\fdk�Z�dd;dg�dhe5e[e�jFfdie3e,e�gdfdje�de[fdl�Z�e#�dm��Z�dn�Z�de�fdo�Z�d�dp�Z�d�dq�Z�d�dr�Z�dse.e[e+fdte3e[de0e3e[fdu�Z�dse.e[e+ffdv�Z�d�dwe[de[fdx�Z�dy�Z�dz�Z�d{�Z�d�d|�Z�e?j�d}�erffd~��Z�d�Z�d�d��Z�ej<d���Z�d��Z�				d�d��Z�d��Z�d��Z�d�d��Z�d��Z�d��Zd��Z�e#�d���Z�d��Z�d��Z�	d�d;d��dte�d�e�ddfd��Z�d��Z�d��Z�d�e[de�fd��Z�d�e[de�fd��Z�d�e[de[fd��Z�d�e[de[fd��Z�d�e[de0e[fd��Z�e?j�d��			d�d0ddd��d�e�d�e�fd���Z�d��Z�d�d��Z�d�d��Z�d�d��Z�d��Z�d��Z�d��Z�d��Z�e#�d���Z�d��Z�	d�d�e[d�e[de.e[e[ffd��Z�d��Z�d��Z�d��Z�ePd;fd��Z�d��Z�d��Z�d��Z�d��Z�d�d��Z�ePd;fd��Z�d�e[de�fd��Z�d��Z�dde�j�j�fd��Z�d�d��Z�d��Z�d�d��Z�d��Z�d��Z�d��Z�d��Z�d�d��Z�d�d��Z�d„Z�dÄZ�d�dĄZ�d�d�derfdDŽZ�ede/de+dffdȄ�Z�y)��N)�	b64decode)�deque)�contextmanager�suppress)�ENOENT)�	lru_cache)�Path)�
ModuleType)�IO�
TYPE_CHECKING�Any�Callable�Deque�Dict�	Generator�List�Mapping�
NamedTuple�Optional�Sequence�Union�cast)�parse)�features�importer�mergers�net�performance�settings�subp�
temp_utils�
type_utils�
url_helper�version)�logexc)�CFG_BUILTIN�PER_ONCE)�Paths�_z_-.())�true�1�on�yes)�off�0�no�falsec��ttttj�j
j
d�dd��S)N�.�)�tuple�map�int�os�uname�release�split���0/usr/lib/python3/dist-packages/cloudinit/util.py�kernel_versionr?`s2����S�"�(�(�*�,�,�2�2�3�7���;�<�=�=r=c�h�tjddgd��}|jj�S)z�Return the sanitized string output by `dpkg --print-architecture`.

    N.B. This function is wrapped in functools.lru_cache, so repeated calls
    won't shell out every time.
    �dpkgz--print-architectureT��capture)r �stdout�strip)�outs r>�get_dpkg_architecturerGds-���)�)�V�3�4�d�
C�C��:�:����r=c�4�ddddd�}i}	tjddgd�	�}|jj�D]2}|jd
�\}}}||vs�|j	�|||<�4|j�D�cgc]	}||vs�|��}}|r%tjddj|��|Scc}w#tj$rA}	tjd
|	�td�|j�D��}Yd}	~	|Sd}	~	wwxYw)N�codename�description�idr:)�Codename�DescriptionzDistributor ID�Release�lsb_releasez--allTrB�:z.Missing fields in lsb_release --all output: %s�,z#Unable to get lsb_release --all: %sc3�$K�|]}|df���
y�w)�UNAVAILABLENr<)�.0�vs  r>�	<genexpr>zlsb_release.<locals>.<genexpr>�s����>�1�Q�
�&�>�s�)r rD�
splitlines�	partitionrE�values�LOG�warning�join�ProcessExecutionError�dict)
�fmap�datarF�line�fnamer)�val�k�missing�errs
          r>rOrOos���$���	�D��D�?��i�i���0�$�?���J�J�)�)�+�	0�D� �N�N�3�/�M�E�1�c���}�$'�I�I�K��T�%�[�!�	0�#�k�k�m�=��q��}�1�=��=���K�K�@�����!�
��K��>���%�%�?����9�3�?��>����
�>�>���K��	?�s6�AC�*C�	B>�B>�)C�>C�D�6D�D�blob�returnc�J�t|t�r|S|j|��S�N)�encoding)�
isinstance�str�decode)rgrks  r>�
decode_binaryro�s!���d�C�(�4�L�d�k�k�8�k�.L�Lr=�textc�J�t|t�r|S|j|��Srj)rl�bytes�encode)rprks  r>�encode_textrt�s!���d�E�*�4�N����X��0N�Nr=zBase64 decodingr`c��t|t�stdt|�z��	t	|d��S#t
j$r|cYSwxYw)z�base64 decode data

    If data is base64 encoded bytes, return b64decode(data).
    If not, return data unmodified.

    @param data: data as bytes. TypeError is raised if not bytes.
    zdata is '%s', expected bytesT)�validate)rlrr�	TypeError�typer�binascii�Error)r`s r>�maybe_b64decoder{�sM���d�E�"��6��d��C�D�D�����-�-���>�>�����s�6�A�
Ac���|jd��}|j�dk(rOt|t�r?|j	�}|r|j
r
|j
}nd}|j
|d�S|S)NT)rnrp�utf-8�surrogateescape)�get_payload�get_content_maintyperlrr�get_charset�input_codecrn)�part�cte_payload�charsetrks    r>�fully_decoded_payloadr��sy���"�"�$�"�/�K�� � �"�f�,���U�2��"�"�$���w�*�*��*�*�H��H��!�!�(�,=�>�>��r=c� �eZdZdd�Zd�Zd�Zy)�SeLinuxGuardc��|	tjd�|_||_||_y#t$r
d|_Y�!wxYw)N�selinux)r�
import_moduler��ImportError�path�	recursive)�selfr�r�s   r>�__init__zSeLinuxGuard.__init__�sF��	
�	 �#�1�1�)�<�D�L���	�"�����	 ��D�L�	 �s�-�A�Ac�R�|jr|jj�ryy�NTF)r��is_selinux_enabled)r�s r>�	__enter__zSeLinuxGuard.__enter__�s���<�<�D�L�L�;�;�=��r=c��|jr|jj�sytjj	|j�sytjj|j�}	tj|�}|jj||tj�tjd||j�	|jj||j��y#t$rYywxYw#t$r,}tjd||j|�Yd}~yd}~wwxYw)Nz,Restoring selinux mode for %s (recursive=%s)�r�z,restorecon failed on %s,%s maybe badness? %s)r�r�r8r��lexists�realpath�lstat�matchpathcon�stat�ST_MODE�OSErrorrZ�debugr��
restoreconr[)r��	excp_type�
excp_value�excp_tracebackr��stats�es       r>�__exit__zSeLinuxGuard.__exit__�s����|�|�4�<�<�#B�#B�#D���w�w���t�y�y�)���w�w����	�	�*��	��H�H�T�N�E��L�L�%�%�d�E�$�,�,�,?�@�	�	�	�:���N�N�	
�
	��L�L�#�#�D�D�N�N�#�C���	��	���	��K�K�>������	
�
��	�s+�<AD� 'D�	D�D�	E� "E�EN�F)�__name__�
__module__�__qualname__r�r�r�r<r=r>r�r��s��	#��r=r�c��eZdZy)�MountFailedErrorN�r�r�r�r<r=r>r�r�����r=r�c��eZdZy)�DecompressionErrorNr�r<r=r>r�r��r�r=r�c�X�tj�}|dk(r	||i|��tjd�yt
jd|t
j|��y#t$r<t	t
dt
j|��tjd�YywxYw)Nrz&Failed forking and calling callback %s�z(Forked child %s who will run callback %s)	r8�fork�_exit�	Exceptionr%rZr"�obj_namer�)�child_cb�args�kwargs�fids    r>�fork_cbr��s���
�'�'�)�C�
�a�x�		��d�%�f�%��H�H�Q�K�	�	�	�6������)�	
���	���8��#�#�H�-�
�

�H�H�Q�K�
	�s�A$�$AB)�(B)c��t|t�r|duSt}|rt|�|z}t	|�j�j
�|vryyr�)rl�bool�TRUE_STRINGS�listrm�lowerrE�rc�addons�	check_sets   r>�is_truer�sN���#����d�{���I�
���O�f�,�	�
�3�x�~�~�����9�,��r=c��t|t�r|duSt}|rt|�|z}t	|�j�j
�|vryy)NFT)rlr��
FALSE_STRINGSr�rmr�rEr�s   r>�is_falser�sN���#����e�|���I�
���O�f�,�	�
�3�x�~�~�����9�,��r=c�D�|syt|t�r|St||�S�NF)rlr�r�)rcr�s  r>�translate_boolr�s&�����#����
��3���r=c���tj�}|s!tjtjz}djt
|�D�cgc]}|j|���c}�Scc}w�N�)�random�SystemRandom�string�
ascii_letters�digitsr\�range�choice)�strlen�select_from�r�_xs    r>�rand_strr�(sQ������A���*�*�V�]�]�:��
�7�7�E�&�M�B�b�A�H�H�[�)�B�C�C��Bs�A/c�@�|sd}	td��dz|z}||vr	|S�)Nr��)r�r))r�)�
dictionary�postfix�newkeys   r>�
rand_dict_keyr�/s6�����
���#�c�)�G�3����#���M�	r=��instance_data_filec	��ddlm}m}m}m}	t|�}|rAtjj|�r"	||||�}tjd||�t|i��S#t$ricYSwxYw#|$r!}tjd||�Yd}~�?d}~w|$rY�I|$r+}tjd||t|��Yd}~�sd}~wwxYw)z>Read a yaml config with optional template, and convert to dictr)�JinjaLoadError�JinjaSyntaxParsingException�
NotJinjaError�render_jinja_payload_from_filez?Applied instance data in '%s' to configuration loaded from '%s'z4Failed to render templated yaml config file '%s'. %sNz:Could not apply Jinja template '%s' to '%s'. Exception: %s��default)�!cloudinit.handlers.jinja_templater�r�r�r��load_text_file�FileNotFoundErrorr8r��existsrZr�r[�repr�	load_yaml)rbr�r�r�r�r��config_filer�s        r>�	read_confr�9s������$�U�+���b�g�g�n�n�-?�@�	�8���"��K�

�I�I�1�"��	
�0�[�"�-�-��E���	��� +�	��K�K�F���
�
��
�	�
��	��K�K� �"���Q��
�
��	�s:�A)�!A:�)A7�6A7�:C�?B�C�%C�)!C�Cc�$�tt|��S�N)�sorted�
uniq_merge)�listss r>�uniq_merge_sortedr�ms���*�e�$�%�%r=c���g}|D]T}t|t�r1|j�jd�}|D�cgc]}|s�|��	}}|j	|��Vt|�Scc}w)NrQ)rlrmrEr;�extend�	uniq_list)r��
combined_list�a_list�as    r>r�r�ysk���M��%���f�c�"��\�\�^�)�)�#�.�F�!'�-�A�1�a�-�F�-����V�$�%��]�#�#��.s�A'�A'c��tj�D]\}}|j||�}�g}|D]}|tvs�|j	|��|D]}|j|d�}�|j�}|Sr�)�FN_REPLACEMENTS�items�replace�
FN_ALLOWED�appendrE)�fnrdrU�removalss    r>�clean_filenamer�s����%�%�'����1�
�Z�Z��1�
����H�
����J���O�O�A������
�Z�Z��2�
���	����B�
�Ir=Tc��	tjt|��5}tjddd|�5}|r+t|j
��cddd�cddd�S|j
�cddd�cddd�S#1swYnxYwddd�y#1swYyxYw#t$r#}|r|cYd}~Stt|��|�d}~wwxYw)N�rbr�)
�io�BytesIOrt�gzip�GzipFilero�readr�r�rm)r`�quietrn�buf�ghr�s      r>�decomp_gzipr�s���4�
�Z�Z��D�)�
*�	!�c�4�=�=��$��3�4
�	!�
��$�R�W�W�Y�/�		!�	!�	!��w�w�y�
	!�	!�	!�	!��	!�	!�	!���4���K�$�S��V�,�!�3��	4�so�B*�B�B	�	B�	B*�'B	�6	B�?	B*�	B	�B�B*�B'�#B*�'B*�*	C�3C�6C�<C�Cc��|sy|jdd�}|dj�}t|�dk(r|dj�}nd}|r|dk(s|j�dk(rd}|r|dk(s|j�dk(rd}||fS)N�NNrPr�rr4z-1�none)r;rE�lenr�)�ug_pair�	ug_parted�u�gs    r>�extract_usergroupr�s������
�
�c�1�%�I��!�����A�
�9�~����a�L��� ������T�	�Q�W�W�Y�&�0�����T�	�Q�W�W�Y�&�0���
�q�6�Mr=�root_dirc�h�t�}tjtjj	|d��D]q}tjj|�s�#tjj
|�dd}|j�}|s�X|jd�dk(s�m|||<�s|S)Nz*.pyr���r3���)	r^�globr8r�r\�isfile�basenamerE�find)r�entriesrb�modnames    r>�get_modules_from_dirr#�s����f�G����2�7�7�<�<��&�9�:�%���w�w�~�~�e�$���'�'�"�"�5�)�!�B�/���-�-�/���w�|�|�C�(�B�.�$�G�E�N�
%��Nr=c�.�dtj�vS)adeprecated: prefer Distro object's `is_linux` property

    Multiple sources of truth is bad, and already know whether we are
    working with Linux from the Distro class. Using Distro offers greater code
    reusablity, cleaner code, and easier maintenance.
    �Linux��platform�systemr<r=r>�is_Linuxr)�s���h�o�o�'�'�'r=c�b�dtj�vrytj�dk(ryy)N�BSDT�	DragonFlyFr&r<r=r>�is_BSDr-�s)������!�!������K�'��r=c�"�t�ddk(S)N�variant�freebsd��system_infor<r=r>�
is_FreeBSDr3�����=��#�y�0�0r=c�"�t�ddk(S)Nr/�	dragonflyr1r<r=r>�is_DragonFlyBSDr7�s���=��#�{�2�2r=c�"�t�ddk(S)Nr/�netbsdr1r<r=r>�	is_NetBSDr:�s���=��#�x�/�/r=c�"�t�ddk(S)Nr/�openbsdr1r<r=r>�
is_OpenBSDr=�r4r=Fc�*�||vr|St||�Sr�)r���yobj�keyr�s   r>�get_cfg_option_boolrB�s��
�$�����$�s�)�$�$r=c�R�||vr|S||}t|t�st|�}|Sr�)rlrm)r@rAr�rcs    r>�get_cfg_option_strrD�s/��
�$����
�s�)�C��c�3���#�h���Jr=c�0�tt|||���S)Nr�)r7rDr?s   r>�get_cfg_option_intrF�s���!�$��W�=�>�>r=c�l�|sd}tjj|�siSt|�}d}d|vrd}t	j
||�}|rc|j
�}d|dvr|d|d<|dj�jd�d|d<|dd	k(rd
|d<|d|d|dd�SiS)
z�Return a dictionary of distro info fields from /etc/redhat-release.

    Dict keys will align with /etc/os-release keys:
        ID, VERSION_ID, VERSION_CODENAME
    z/etc/redhat-releasezA(?P<name>.+) release (?P<version>[\d\.]+) \((?P<codename>[^)]+)\)�	Virtuozzoz)(?P<name>.+) release (?P<version>[\d\.]+)�namerIz linuxrzred hat enterprise�redhatr$)�ID�
VERSION_ID�VERSION_CODENAME)	r8r�r�r��re�match�	groupdictr�rX)�release_file�redhat_release�redhat_regexrO�groups     r>�_parse_redhat_releaserU�s����,��
�7�7�>�>�,�'��	�#�L�1�N�	#���n�$�C���H�H�\�>�2�E�����!���%��-�'� %�f�
�E�*���f�
�+�+�-�7�7��A�!�D��f�
���=�0�0�$�E�&�M���-��	�*� %�j� 1�
�	
�
�Ir=c��d}d}d}i}d}tjjd�rtt	d��}|sd}t�}|r�|j
dd�}|j
dd�}d|vsd|vrtj�}n�|d	k(s|d
k(r|j
dd�}ni|dk(r|s|j
dd�}nO|j
d
d�}|s;tjd|j
dd��}|r|j�d}|dk(r�d}nt�r7tj�j�}tj�}n>d}	tj �}d}|D]}|s�d}�	|st$j'd�|S|||fS#t"$rY�7wxYw#d}|D]}|s�d}�	|st$j'd�wwxYw)Nr�F�/etc/os-releaseTrKrL�sles�suse�alpine�photon�PRETTY_NAME�	virtuozzorMz[^ ]+ \((?P<codename>[^)]+)\)�VERSIONrI�rhelrJ)r�r�r�r�zPUnable to determine distribution, template expansion may have unexpected results)r8r�r��load_shell_contentr�rU�getr'�machinerNrOrPr-r(r�r:�distr�rZr[)	�distro_name�distro_version�flavor�
os_release�os_release_rhelrOrc�found�entrys	         r>�get_linux_distrork s����K��N�
�F��J��O�	�w�w�~�~�'�(�'��7H�(I�J�
����*�,�
�� �n�n�T�2�.��#����b�9���[� �F�k�$9�
�%�%�'�F�
�H�
$��x�(?��^�^�M�2�6�F�
�K�
'���^�^�M�2�6�F��^�^�$6��;�F�����4��N�N�9�b�1����"�_�_�.�z�:�F��&� �"�K�	���o�o�'�-�-�/��!�)�)�+����	��=�=�?�D��E��
����E�
�����<�������0�0���	��	���E��
����E�
�����<���s*�!F!�!	F-�*F0�,F-�-F0�0
G�;Gc��|dj�}d}|dk(r;|ddj�}|dvr|}|S|dvrd}|S|d	k(rd
}|S|dvrd}|Sd}|S|d
vr|}|S)Nr(�unknown�linuxrcr)�	almalinuxrZ�aosc�arch�
azurelinux�centos�
cloudlinux�debian�	eurolinux�fedora�mariner�miraclelinux�	openeuler�opencloudos�openmandrivar[r_�rockyrY�	tencentosr])�ubuntu�	linuxmint�mintrrJr_)�opensusez
opensuse-leapzopensuse-microoszopensuse-tumbleweed�sle_hpcz	sle-microrXrY)�windows�darwinr0r9r<r6)r�)�infor(r/�
linux_dists    r>�_get_variantr�^s���
�(�^�
!�
!�
#�F��G�
����&�\�!�_�*�*�,�
��
�
�.!�G�6�N�5�:�
:��G�2�N�1�8�
#��G�.�N�-�
�
��G��N��G��N�
��
����Nr=c�
�tj�tj�tj�tj�t	tj
��t
�d�}t|�|d<|S)N)r'r(r:�pythonr9rcr/)r'r(r:�python_versionr�r9rkr�)r�s r>r2r2�sc���%�%�'��/�/�#��#�#�%��)�)�+��h�n�n�&�'� �"�
�D�#�4�(�D��O��Kr=c��||vr|S||�gS||}t|t�r|D�cgc]}|��}}|St|t�st|�}|gScc}w)a�
    Gets the C{key} config option from C{yobj} as a list of strings. If the
    key is present as a single string it will be returned as a list with one
    string arg.

    @param yobj: The configuration object.
    @param key: The configuration key to get.
    @param default: The default to return if key is not found.
    @return: The configuration option as a list of strings or default if key
        is not found.
    )rlr�rm)r@rAr�rcrU�cvals      r>�get_cfg_option_listr��si���$�����C�y���	�
�s�)�C��#�����a��������c�3���#�h���5�L��	 s�	Ac�t�t|t�r|jd�}|}|D]}||vr|cS||}�|S)a�Return the value of the item at path C{keyp} in C{yobj}.

    example:
      get_cfg_by_path({'a': {'b': {'num': 4}}}, 'a/b/num') == 4
      get_cfg_by_path({'a': {'b': {'num': 4}}}, 'c/d') == None

    @param yobj: A dictionary.
    @param keyp: A path inside yobj.  it can be a '/' delimited string,
                 or an iterable.
    @param default: The default to return if the path does not exist.
    @return: The value of the item at keyp."
    is not found.�/)rlrmr;)r@�keypr��cur�toks     r>�get_cfg_by_pathr��sK���$����z�z�#���
�C�����c�>��N��#�h����Jr=c�@�t||�\}}t||�||fSr�)�get_output_cfg�redirect_output)�cfg�mode�outfmt�errfmts    r>�fixup_outputr��s(��%�c�4�0��V�V��F�F�#��F��r=c���ttjjd��rtjd�y|stj}|stj}d�}|�r+tjd||�|jdd�\}}|dk(s|dk(rd	}|dk(rd
}t||�}n\|dk(rItj|dtj|�
�}	ttt |	j"�}nt%d|z��|r2tj&|j)�|j)��||k(rJtjd||�tj&|j)�|j)��y|r�tjd||�|jdd�\}}|dk(s|dk(rd	}|dk(rd
}t||�}n\|dk(rItj|dtj|�
�}	ttt |	j"�}nt%d|z��|r3tj&|j)�|j)��yyy)N�_CLOUD_INIT_SAVE_STDOUTz5Not redirecting output due to _CLOUD_INIT_SAVE_STDOUTc��tjd�	tjd�j}tj
|�y#t$rYywxYw)a�Reconfigure umask and group ID to create output files securely.

        This is passed to subprocess.Popen as preexec_fn, so it is executed in
        the context of the newly-created process.  It:

        * sets the umask of the process so created files aren't world-readable
        * if an adm group exists in the system, sets that as the process' GID
          (so that the created file(s) are owned by root:adm)
        ��admN)r8�umask�grp�getgrnam�gr_gid�setgid�KeyError)�group_ids r>�set_subprocess_umask_and_gidz5redirect_output.<locals>.set_subprocess_umask_and_gid�sJ��	�����	 ��|�|�E�*�1�1�H�

�I�I�h���	�	��	�s�A�	A�AzRedirecting %s to %s� r��>�>>�ab�wb�|T)�shell�stdin�
preexec_fnz"Invalid type for output format: %sz!Invalid type for error format: %s)r�r8�environrarZr��sysrD�stderrr;�open�
subprocess�Popen�PIPErrr
r�rw�dup2�fileno)
r�r��o_out�o_errr�r��arg�owith�new_fp�procs
          r>r�r��s���r�z�z�~�~�7�8�9��	�	�I�J����
�
����
�
�� �&��	�	�(�%��8��l�l�3��*���s��3�;�$�$�,��E��s�{����#�u�%�F�
�S�[��#�#��� �o�o�7�	�D��"�S�'�4�:�:�.�F��@�6�I�J�J���G�G�F�M�M�O�U�\�\�^�4��V���I�I�,�e�V�<��G�G�F�M�M�O�U�\�\�^�4��
��	�	�(�%��8��l�l�3��*���s��3�;�$�$�,��E��s�{����#�u�%�F�
�S�[��#�#��� �o�o�7�	�D��"�S�'�4�:�:�.�F��?�&�H�I�I���G�G�F�M�M�O�U�\�\�^�4��+r=�sourcesc���|rtt|��}i}|D]W}|s�tj|�}|stj�}tj
|�}|j
||�}�Y|S)aFMerge multiple dicts according to the dict merger rules.

    Dict merger rules can be found in cloud-init documentation. If no mergers
    have been specified, entries will be recursively added, but no values
    get replaced if they already exist. Functionally, this means that the
    highest priority keys must be specified first.

    Example:
    a = {
        "a": 1,
        "b": 2,
        "c": [1, 2, 3],
        "d": {
            "a": 1,
            "b": 2,
        },
    }

    b = {
        "a": 10,
        "c": [4],
        "d": {
            "a": 3,
            "f": 10,
        },
        "e": 20,
    }

    mergemanydict([a, b]) results in:
    {
        'a': 1,
        'b': 2,
        'c': [1, 2, 3],
        'd': {
            'a': 1,
            'b': 2,
            'f': 10,
        },
        'e': 20,
    }
    )r��reversedr�dict_extract_mergers�default_mergers�	construct�merge)r��reverse�
merged_cfgr��mergers_to_apply�mergers      r>�
mergemanydictr�@sz��T��x��(�)���J��7���&�;�;�C�@��#�#*�#:�#:�#<� ��&�&�'7�8�F����j�#�6�J�7��r=c#��K�tj�}	tj|�|��tj|�y#tj|�wxYw�wr�)r8�getcwd�chdir)�ndir�currs  r>r�r�xs<����
�9�9�;�D��
������
�
�����������s�A!�A�A!�A�A!c#�K�tj|�}	|��tj|�y#tj|�wxYw�wr�)r8r�)�n_msk�olds  r>r�r��s3����
�(�(�5�/�C���	�
����
������
�s�A
�3�A
�A
�
A
c�,�dj||d|��S)Nz{0:{fill}{align}{size}}�^)�fill�align�size)�format)rpr��max_lens   r>�centerr��s#��$�+�+��4�s��,��r=c�Z�tjd|�tj|�y)NzRecursively deleting %s)rZr��shutil�rmtree�r�s r>�del_dirr��s���I�I�'��.�
�M�M�$�r=c���	t|||��\}}}}||d<||d<||d<||d<y#tj$r(}|jtjk(rYd}~y�d}~wwxYw)	z�
    returns boolean indicating success or failure (presense of files)
    if files are present, populates 'fill' dictionary with 'user-data' and
    'meta-data' entries
    )�base�ext�timeout�	user-data�vendor-data�	meta-dataznetwork-configTNF)�read_seededr#�UrlError�code�	NOT_FOUND)	r�r�r�r��md�ud�vd�networkr�s	         r>�read_optional_seedr��sx��
�)�t��g�N���B��G���[�� ��]����[��!(��
���������6�6�Z�)�)�)��
���s�'*�A%�A �A � A%c�&�i}|sddg}n^tjj|jd�d�tjj|j	d�d�g}t|�}|D�cgc]'}|s�tjj
|�s�&|��)}}d}|D]a}tjjtjj|d��s�Atjj|d�}nd}|D]a}tjjtjj|d��s�Atjj|d�}n|r|r||d<||d<|S|r||d<|Scc}w)	Nz/var/lib/cloud/data/sslz /var/lib/cloud/instance/data/sslr`�sslzcert.pemzkey.pem�	cert_file�key_file)r8r�r\�
get_ipath_cur�	get_cpathr��isdirr)�paths�ssl_details�ssl_cert_paths�dr�r�s      r>�fetch_ssl_detailsr��s\���K��%�.�
��
�G�G�L�L��,�,�V�4�e�<��G�G�L�L�����0�%�8�
�� ��/�N�!/�J�A�1������q�9I�a�J�N�J��I�
���
�7�7�>�>�"�'�'�,�,�q�*�5�6������Q�
�3�I����H�
���
�7�7�>�>�"�'�'�,�,�q�)�4�5��w�w�|�|�A�y�1�H����X�#,��K� �"*��J����
�#,��K� ����!Ks�7F�?F�Fc���|}t|�}	tjdt|�|�t	j
|�}|�tjd�|}n1t
||�s%td|�dtj|��d���|}|S#tjttf$r�}d}d}t|d�rt|d�r
t|d�}n$t|d�rt|d�rt|d�}|r2|d	j|jd
z|j d
z|��z
}n|dj|�
�z
}tj#|�Yd}~|Sd}~wwxYw)NzKAttempting to load yaml from string of length %s with allowed root types %sz-loaded blob returned None, returning default.zYaml load allows z root types, but got � insteadzFailed loading yaml blob�context_mark�problem_markz5. Invalid format at line {line} column {col}: "{err}"r�)ra�colrfz. {err})rf)rorZr�r�yaml�	safe_loadrlrwr"r��	YAMLError�
ValueError�hasattr�getattrr�ra�columnr[)rgr��allowed�loaded�	convertedr��msg�marks        r>r�r��s^��
�F����D�!��	�	�
6���I��		
��N�N�4�(�	����I�I�E�F��I��I�w�/���J�/�/�	�:�<��
���"�M��!
�N�N�I�z�2��(�����1�n�%�'�!�^�*D��1�n�-�D�
�Q��
'�G�A�~�,F��1�n�-�D���G�N�N����Q��D�K�K�!�O��O��
�C�
�9�#�#��#�*�*�C����C����M��!�s�BB�E'�1B+E"�"E'c�^�|jd�dk\r@|jdd|z�}|jdd|z�}|jdd|z�}nWtjr/|ddk7r't	j
|�jdk(r|dz
}|�d�|��}|�d�|��}|�d�|��}d}tj|||�	�}d}	|j�rt|ji�
�}	tj|||�	�}
d}|
j�r|
j}d}	tj|||�	�}
|
j�r
|
j}ntjd�	|	|||fS#tj$r }tjd|�Yd}~�4d}~wwxYw)
Nz%srr�r�r�rr�r�)r��retriesr�zError in vendor-data responsez!Error in vendor-data response: %s)r r�r�%NOCLOUD_SEED_URL_APPEND_FORWARD_SLASHr�urlparse�queryr#�read_file_or_url�okr��contentsrZr�r�)r�r�r�r�ud_url�vd_url�md_urlr��md_respr��ud_respr�r��vd_respr�s               r>r�r��s����y�y���!�����d�K�#�$5�6�����d�M�C�$7�8�����d�K�#�$5�6���9�9��B�x�3��5�>�>�$�#7�#=�#=��#C�����!�;��4��!�=�#�6��!�;��4���G��)�)�����G�
�B��z�z�|�
�w�'�'��
4���)�)�����G�
�B��z�z�|�
�
�
��	
�B�
7��-�-��G�W�
���:�:�<��!�!�B��I�I�5�6�
�r�2�w�������:��	�	�5�q�9�9��:�s�(E9�9F,�F'�'F,c	�n�ttj|�d��}|D�cgc]}|jd�s�|��}}|D�cgc]B}tjjtjj
||��s�A|��D}}g}|D]?}tjj
||�}	|jt||����At|�Scc}wcc}w#t$rtjd|�Y�xt$r!}tjd||�Yd}~��d}~wwxYw)zRead configuration directory.T�r�z.cfgr��1REDACTED config part %s, insufficient permissions�Error accessing file %s: [%s]N)r�r8�listdir�endswithr�rr\rr��PermissionErrorrZr[r�r�)�confdr��confs�f�cfgsrr�r�s        r>�read_conf_dr)s��
�2�:�:�e�$�d�3�E��4�1����F�!3�Q�4�E�4��H�1�����������U�A�0F�!G�Q�H�E�H��D��B���w�w�|�|�E�2�&��	B��K�K���'9��
�B� �����/
5��
I���	��K�K�C�T�
��	B��K�K�7��q�A�A��	B�s5�C �C �AC%�	C%�7C*�*D4�D4�D/�/D4c��t�}i}	t||��}|j|�d}d|vrU|d}|rut|t�s$td|�dtj|�����t|�j�}n'tjj|�d	��r|�d	�}|r=tjj|�rt!||��}|j#|�t%|�S#t$rtjd|�Y��t$r"}tjd||�Yd}~��d}~wwxYw)
aRead yaml file along with optional ".d" directory, return merged config

    Given a yaml file, load the file as a dictionary. Additionally, if there
    exists a same-named directory with .d extension, read all files from
    that directory in order and return the merged config. The template
    file is optional and will be applied to any applicable jinja file
    in the configs.

    For example, this function can read both /etc/cloud/cloud.cfg and all
    files in /etc/cloud/cloud.cfg.d and merge all configs into a single dict.
    r�r r!Nr��conf_dzConfig file z( contains 'conf_d' with non-string type z.d)rr�rr$rZr[r�rlrmrwr"r�rEr8r�r�r)�
appendleftr�)�cfgfiler�r(r�r�r%�	confd_cfgs       r>�read_conf_with_confdr/>s"����D��C�	���4F�G��	
���C���E��3���H�
����e�S�)���
� 3� 3�E� :�<���
�E�
�(�(�*��	�����'��"�~�	&��)�2���������u�%���:L�M�	����	�"������9�
����?��	
��A����3�W�a�@�@��A�s�
C8�8E�E�!D>�>Ec�,�tt|���S)N��cmdline)r��read_cc_from_cmdliner1s r>�read_conf_from_cmdliner4ms���)�'�:�;�;r=c��|�
t�}d|��}d}d}t|�}t|�}t|�}g}|j|�}|dk\r|j|||z�}|dkr|}|jt	j
|||z|j
��jdd��|j|||z�}|dk\r�dj|�S)Nr�z cc:�end_ccrz\n�
)	�get_cmdlinerr rr�unquote�lstripr�r\)	r2�	tag_begin�tag_end�begin_l�end_l�clen�tokens�begin�ends	         r>r3r3rs������-���'��m�G��I��G��)�n�G���L�E��w�<�D�
�F��L�L��#�E�
�1�*��l�l�7�E�G�O�4����7��C��
�
��M�M�'�%�'�/�C�8�?�?�A�B�J�J��t�
�	
�
���Y��e��4���1�*��9�9�V��r=c�l�|jd�}|dks||dz
dk7r|S|jdd�S)Nr7rr��
z
)r r�)r�poss  r>�dos2unixrF�s?��
�-�-��
�C�
�a�x�8�C�!�G�$��,������F�D�)�)r=c�,�eZdZUeed<eed<eed<y)�HostnameFqdnInfo�hostname�fqdn�
is_defaultN)r�r�r�rm�__annotations__r�r<r=r>rHrH�s���M�

�I��r=rHc�l�d}d|vr.t|d�}t|d|jd�d�}ntd|vr4|djd�dkDr|d}|dd|jd�}n<|j	d|��j
}d|vr|d}n|j	|�	�\}}t
|||�S)
a�Get hostname and fqdn from config if present and fallback to cloud.

    @param cfg: Dictionary of merged user-data configuration (from init.cfg).
    @param cloud: Cloud instance from init.cloudify().
    @param metadata_only: Boolean, set True to only query meta-data,
        returning None if not present in meta-data.
    @return: a namedtuple of
        <hostname>, <fqdn>, <is_default> (str, str, bool).
        Values can be none when
        metadata_only is True and no cfg or metadata provides hostname info.
        is_default is a bool and
        it's true only if hostname is localhost and was
        returned by util.get_hostname() as a default.
        This is used to differentiate with a user-defined
        localhost hostname.
    FrJrIr3rNT)rJ�
metadata_only)rN)rmrDr;r �get_hostnamerIrH)r��cloudrNrKrJrIs      r>�get_hostname_fqdnrQ�s���"�J�
��}��3�v�;���%�c�:�t�z�z�#��q�7I�J������Z��!5�!5�c�!:�Q�!>��z�?�D��:��'7����3��8�H��%�%���&���h�
��S� ��z�?��',�'9�'9�"/�(:�(�$��*��H�d�J�7�7r=c�"�d}	t|�j�D]^}|jd�}|dk\r|d|}|j�}|s�1|j	�}t|�dkr�P||ddvs�X|d}|S	|S#t$rY|SwxYw)a�
    For each host a single line should be present with
      the following information:

        IP_address canonical_hostname [aliases...]

      Fields of the entry are separated by any number of  blanks  and/or  tab
      characters.  Text  from a "#" character until the end of the line is a
      comment, and is ignored. Host  names  may  contain  only  alphanumeric
      characters, minus signs ("-"), and periods (".").  They must begin with
      an  alphabetic  character  and  end  with  an  alphanumeric  character.
      Optional aliases provide for name changes, alternate spellings, shorter
      hostnames, or generic hostnames (for example, localhost).
    N�#r�r4r�)r�rWr rEr;r�IOError)rI�filenamerJra�hashpos�tokss      r>�get_fqdn_from_hostsrY�s����D�
�"�8�,�7�7�9�	�D��i�i��n�G��!�|��A�g����:�:�<�D���
�:�:�<�D��4�y�1�}���4���8�#��A�w����K�)	�(�K���
���K�
�s�A0B�5B�=B�	B�
Bz
Resolving URLc	�T�tj|�}|j}t��t	�}d}i}|D]{}	tj|dddt
jt
j�}g||<|D]8\}}	}
}}||j|�d|d���|j|d��:�}|a|rtjd|�	tt �5t#j$|j&j)d��r
	ddd�y	ddd�tj|d�}|ddd}
|
tvS#t
jt
jf$rY��9wxYw#1swY�\xYw#t
jt
jf$rYy	wxYw)
a�determine if a url's network address is resolvable, return a boolean
    This also attempts to be resilent against dns redirection.

    Note, that normal nsswitch resolution is used here.  So in order
    to avoid any utilization of 'search' entries in /etc/resolv.conf
    we have to append '.'.

    The top level 'invalid' domain is invalid per RFC.  And example.com
    should also not exist.  The '__cloud_init_expected_not_found__' entry will
    be resolved inside the search list.
    N)zdoes-not-exist.example.com.zexample.invalid.�!__cloud_init_expected_not_found__rz: zdetected dns redirection: %sz[]T�F)rrrI�_DNS_REDIRECT_IP�set�socket�getaddrinfo�SOCK_STREAM�AI_CANONNAMEr�add�gaierror�errorrZr�rrr�
is_ip_address�netlocrE)�url�
parsed_urlrI�badips�badnames�
badresults�iname�result�_fam�_stype�_proto�cname�sockaddr�addrs              r>�
is_resolvableru�s�������$�J����D������
��
�
��
	�E�	
��+�+��4��A�v�'9�'9�6�;N�;N���%'�
�5�!�=C�,�9�D�&�&�%���u�%�,�,�����-L�M��J�J�x��{�+�,�
	�"����I�I�4�j�A�
�
�j�
!�	�� � ��!2�!2�!8�!8��!>�?��	�	�?�	��#�#�D�$�/���a�y��|�A����+�+�+���O�O�V�\�\�2�
��
��	�	��
�O�O�V�\�\�*����sB�A8E�F� 0E5�F�0F�#E2�1E2�5E>�:F�#F'�&F'c�.�tj�}|Sr�)r_�gethostname)rIs r>rOrO*s���!�!�#�H��Or=c�f�	tj|�dS#tj$rYywxYw�Nr)r_�
gethostbyaddr�herror)�ips r>rzrz/s3����#�#�B�'��*�*���=�=����s��0�0c��t|�S)z5determine if this url is resolvable (existing or ip).)ru)rhs r>�is_resolvable_urlr~6s
�����r=c��|�ytjd|�|D](}	t|�rtjd|�|cS�*y#t$rY�7wxYw)zc
    Search through a list of mirror urls for one that works
    This needs to return quickly.
    Nz%search for mirror in candidates: '%s'zfound working mirror: '%s')rZr�r~r�)�
candidates�cands  r>�search_for_mirrorr�;sj��
����I�I�5�z�B����	� ��&��	�	�6��=���'�����	��	�s�"A�	A�Ac��g}|s+tjd�tjd�zS|jd�rI|jd�}d|zd|zfD�cgc]#}tjj|�r|��%}}|S|dk(rtjd�}|S|dk(rtjd�}|Scc}w)Nz/dev/msdosfs/*z/dev/iso9660/*�LABEL=z
/dev/msdosfs/z
/dev/iso9660/�	TYPE=vfat�TYPE=iso9660)r�
startswithr:r8r�r�)�criteria�oformat�tag�no_cacher��devlist�label�ps        r>�find_devs_with_freebsdr�Ns����G���y�y�)�*�T�Y�Y�7G�-H�H�H����8�$�����)��&��-���/F�G�
���w�w�~�~�a� �
�
��
��N�	
�[�	 ��)�)�,�-���N�
�^�	#��)�)�,�-���N��
s�(Cc��g}d}d}d}|rD|jd�r|jd�}|jd�r|jd�}tjgd�dg��}	|	jj	�D]V}
|s|rtjd|
gddg��\}}|rd	|z|vr�/|d
k(rd|vr�9|dk(rd|vr�C|jd
|
z��X|S)Nr�r�zTYPE=��sysctl�-nzhw.disknamesr��rcs�	mscdlabelr�z
label "%s"�iso9660zISO filesystem�vfat�/dev/)r�r:r rDr;r)r�r�r�r�r�r�r��_type�
mscdlabel_outrF�devr)s            r>�find_devs_with_netbsdr�bs����G��E��E��M�����x�(��O�O�H�-�E����w�'��O�O�G�,�E�
�)�)�4�1�#�
>�C��z�z���!�	&���E�#�y�y�+�s�);�!�Q��H��M�1��l�U�*�=�@���I��"2�-�"G���F�?�/�=�@�����w��}�%�	&��Nr=c�v�tjgd�dg��}g}|jj�jd�D]Z}|j	d�s�|dk(r�|j|dddz�|j
d	�r�D|j|ddd
z��\|D�cgc]}d|z��	c}Scc}w)Nr�rr�rQrPzfd0:rr��cd�ir�)r rD�rstripr;r#rr�)	r�r�r�r�r�rFr�rjr�s	         r>�find_devs_with_openbsdr�|s����)�)�4�1�#�
>�C��G����"�"�$�*�*�3�/�-���~�~�c�"���F�?�����u�S�b�z�C�'�(�����%��N�N�5��"�:��+�,�-�")�)�A�G�a�K�)�)��)s�'B6c��tjgd�dg��}t|jj�d��D�cgc]&}|j	d�s|j	d�s|��(}}|dk(r"|D�cgc]}|j	d	�s�|��}}n>|d
vr"|D�cgc]}|j	d	�r�|��}}n|rt
j
d|�|D�cgc]}d|z��	c}Scc}wcc}wcc}wcc}w)
N)r�r�z
kern.disksrr�Trr��vnr�)r��acd)zLABEL=CONFIG-2r�zUnexpected criteria: %sr�)r r�rDr;r�rZr�)r�r�r�r�r�rFr�r�s        r>�find_devs_with_dragonflybsdr��s����)�)�2���
<�C���
�
�(�(�*�D�9��
��|�|�D�!�!�,�,�t�*<�	
��G���>�!�%�E�����m�)D�1�E��E�	�4�	4�%�K��a�l�l�=�.I�1�K��K�	��	�	�+�X�6�!(�)�A�G�a�K�)�)����F��K��*s$�+C'�8C,�C,�C1�5C1�C6c���t�rt|||||�St�rt|||||�St	�rt|||||�St
�rt|||||�Sdg}g}|r|jd|z�|r|jd|z�|r|jddg�|r|jd|z�|r|j|�||z}	tj|ddg�	�\}}	g}|j�D]&}|j�}|s�|j|��(|S#tj$r!}
|
jtk(rd
}n�Yd}
~
�ld}
~
wwxYw)z�
    find devices matching given criteria (via blkid)
    criteria can be *one* of:
      TYPE=<filesystem>
      LABEL=<label>
      UUID=<uuid>
    �blkidz-t%sz-s%s�-c�	/dev/nullz-o%srr4r�r�N)r3r�r:r�r=r�r7r�rr�r r]�errnorrWrE)
r�r�r�r�r��
blk_id_cmd�options�cmdrF�_errr�r!ras
             r>�find_devs_withr��sr���|�%�h���h��M�M�	��$�X�w��X�t�L�L�	��%�h���h��M�M�	�	�*��g�s�H�d�
�	
���J��G��	���v��*�+�
����v��~�&��	����k�*�+��	���v��)�*�����t��
�w�
�C���i�i��!�Q��0���d��G���� �!���z�z�|����N�N�4� �!��N���%�%���7�7�f���C��
���s�D3�3E'�E"�"E'c�B�|�g}nt|�}gd�}|r|jddg�|j|�tj|dd��}i}|jj	�D]-}|jd�\}}}t
|�||<|||d<�/|S)	z�Get all device tags details from blkid.

    @param devs: Optional list of device paths you wish to query.
    @param disable_cache: Bool, set True to start with clean cache.

    @return: Dict of key value pairs of info for the device.
    )r��-o�fullr�r�Tr�)rCrnrP�DEVNAME)r�r�r rDrWrXr`)	�devs�
disable_cacher�rF�retrar�r)r`s	         r>r�r��s����|����D�z��
!�C���
�
�D�+�&�'��J�J�t��
�)�)�C��i�
8�C�
�C��
�
�%�%�'�"���~�~�c�*���Q��%�d�+��C��!��C����"�
�Jr=c�D�g}|D]}||vr�|j|��|Sr�)r)�in_list�out_listr�s   r>r�r��s3���H�
�����=���O�O�A��	�
�Or=��read_cbrrbr�rc���tjdd��}tjd||�|5t	j
�5}	t
|d�5}t|||��ddd�|j�}ddd�ddd�tjdt�||j�|S#1swY�VxYw#t$r|s�Y�gwxYw#1swY�\xYw#1swY�`xYw)Nr��skip)�log_modezReading from %s (quiet=%s)r)�chunk_cbzReading %s bytes from %s%s)r�TimedrZr�rrr��pipe_in_outr��getvaluer�output)rbr�r�timer�ofh�ifhrs       r>�load_binary_filer�	s���
���b�6�2�E��I�I�*�E�5�9�	�&�
�Z�Z�\�	&�S�
��%��&�<�#���S�7�;�<�
�|�|�~�H�	&�&��I�I�*�C��M�5�%�,�,�O��O�<�<��$�
����
��		&�	&��&�&�s_�C"�C�C�B8�#C�+C�;C"�8C�=C�C�C�C�C�C	�C"�"C+c�0�tt|||���S)Nr�)ror�)rbr�rs   r>r�r�s���)�%���N�O�Or=c��t�r#	td�}|jdd�dd}|S	td�j
�}|S#t$r#}tjd|�d}Yd}~|Sd}~wwxYw#t$rd}Y|SwxYw)Nz/proc/1/cmdline�r�rz"failed reading /proc/1/cmdline: %sr�z
/proc/cmdline)�is_containerr�r�r�rZr[rE)rr2r�s   r>�_get_cmdliner�'s����~�	�%�&7�8�H��&�&�v�s�3�C�R�8�G��N�	�$�_�5�;�;�=�G��N���	��K�K�<�a�@��G��N��	���	��G��N�	�s(� A
�A9�
	A6�A1�1A6�9B�Bc�`�dtjvrtjdSt�S)N�DEBUG_PROC_CMDLINE)r8r�r�r<r=r>r8r8:s&���r�z�z�)��z�z�.�/�/��>�r=c�n�d}	t|�j�}|dk(S#ttf$rYywxYw)Nz/proc/sys/crypto/fips_enabledr+F)r�rErUr�)�	fips_procrs  r>�fips_enabledr�AsB��/�I��!�)�,�2�2�4���3�����W����	�s�"�4�4c��d}	|j|�}t|�dk(rn*|j|�|t|�z
}|r||��J|j�|Sry)rr�write�flush)�in_fh�out_fh�
chunk_sizer��bytes_pipedr`s      r>r�r�Msa���K�
��z�z�*�%���t�9��>�����T���s�4�y� ����[�!���L�L�N��r=c�t�|dvr|dvrytjd|||�tj|||�y)N)Nrz%Changing the ownership of %s to %s:%s)rZr�r8�chown)rb�uid�gids   r>�	chownbyidr�\s7��
�j��S�J�.���I�I�5�u�c�3�G��H�H�U�C��r=c���d}d}	|rtj|�j}|rtj|�j
}t|||�y#t$r}td|z�|�d}~wwxYw)NrzUnknown user or group: %s)	�pwd�getpwnam�pw_uidr�r�r�r�r�r�)rb�userrTr�r�r�s      r>�chownbynamer�dsu��
�C�
�C�@���,�,�t�$�+�+�C���,�,�u�%�,�,�C��e�S�#����@��1�Q�7�8�a�?��@�s�AA�	A3�A.�.A3r�r�c�l�ddg}|rd|vr|S|d}||vr||}nd|vr|S|d}t|t�r||g}t|t�r,t|�dkDr|d|d<t|�dkDr|d|d<t|t�rd|vr|d|d<d|vr|d|d<|ddk(r|d|d<gd�}t|�D]s\}}|s�	|j
�}d	}	|D]8}
|j|
�s�|
�d
|t|
�dj���}d}	n|	sd�d
|j���}|||<�u|S)
a�Get the output configuration for a given mode.

    The output config is a dictionary that specifies how to deal with stdout
    and stderr for the cloud-init modules. It is a (frustratingly) flexible
    format that can take multiple forms such as:
        output: { all: "| tee -a /var/log/cloud-init-output.log" }
    or
        output:
            init:
                output: "> /var/log/cloud-init.out"
                error: "> /var/log/cloud-init.err"
            config: "tee -a /var/log/cloud-config.log"
            final:
                - ">> /var/log/cloud-final.out"
                - "/var/log/cloud-final.err"

    Mode can be one of the configuration stages. If you pass a
    non-existent mode, it will assume the "all" mode configuration if
    defined.

    Stderr can be specified as &1 to indicate that it should
    be the same as stdout.

    If a file is specified with no redirection, it will default to
    appending to the file.

    If not overridden, output is provided in
    '/etc/cloud/config/cloud.cfg.d/05_logging.cfg' and defaults to:
        {"all": "| tee -a /var/log/cloud-init-output.log"}

    :param cfg: The base configuration that may or may not contain the
        'output' configuration dictionary
    :param mode: The mode to get the output configuration for.
    :return: A list of two strings (or Nones), the first for stdout for the
        specified mode and the second for stderr.
    Nr��allrr�rez&1)r�r�r�Fr�Tr�)	rlrmr�rr^�	enumerater:r�rE)r�r�r��outcfg�modecfg�swlistr�r�rcri�ss           r>r�r�qs���N!%�d�|�C��(�#�%��
�
��]�F��v�~���,������J���-���'�3���� ���'�4� ��w�<�!���Q�Z�C��F��w�<�!���Q�Z�C��F��'�4� ��w���X�&�C��F��g���W�%�C��F��1�v��~��Q���A��
�F��#��
���1����h�h�j�����	�A��~�~�a� �!"�C��A���M�$7�$7�$9�:�����		�
�!�3�9�9�;�/�C���A��
��Jr=c�x�g}g}|rt|t�s|S|jd�}|r|j|�t	|d�D]~}|s�tjd|�}|s�|jd�}|j�}t|�dk(r|j|��`ddg|ddk(s�k|j|d���|D]V}tj|�d	��D]9}	tjj|	�s�#|	|k7s�)|j|	��;�Xtt||z��S)
a=Return a list of log file paths from the configuration dictionary.

    Obtains the paths from the 'def_log_file' and 'output' configuration
    defined in the base configuration.

    If not provided in base configuration, 'def_log_file' is specified in
    'cloudinit/settings.py' and defaults to:
        /var/log/cloud-init.log
    If not overridden, output is provided in
    '/etc/cloud/config/cloud.cfg.d/05_logging.cfg' and defaults to:
        {"all": "| tee -a /var/log/cloud-init-output.log"}

    @param cfg: The cloud-init merged configuration dictionary.
    �def_log_fileNz (?P<type>\||>+)\s*(?P<target>.*)�targetr��teez-ar4�*)rlr^rarr�rNrOrTr;rrr8r�rr�r^)
r��logs�rotated_logs�default_log�fmtrOr��parts�logfile�rotated_logfiles
          r>�get_config_logfilesr��s.���D��L��j��d�+����'�'�.�)�K�����K� ��c�4�(�"�������<�c�B�������X�&��������u�:��?��K�K����T�]�e�B�Q�i�
'��K�K��a��!�"��5��#�y�y�G�9�A��7�	5�O��w�w�~�~�o�.�?�g�3M��#�#�O�4�		5�5���D�<�'�(�)�)r=�routinec��tj|�}|jt|��|j	�}|�|d|S|Sry)�hashlib�new�updatert�	hexdigest)rgr��mlen�hasher�digests     r>�	hash_blobrsF��
�[�[��
!�F�
�M�M�+�d�#�$�
�
�
�
�F����a��~���
r=c�P�	tj|�ryy#t$rYywxYwr�)r�r�r��rIs r>�is_userr�-����<�<�������������	%�%c�P�	tj|�ryy#t$rYywxYwr�)r�r�r�rs r>�is_groupr	rrc�^�tjd||�tj||�y)NzRenaming %s to %s)rZr�r8�rename��src�dests  r>rrs!���I�I�!�3��-��I�I�c�4�r=c�*�|D]}t||��yr�)�
ensure_dir)�dirlistr�r�s   r>�ensure_dirsr"s��
����1�d��r=zLoading jsonc��tjt|��}t|t	|��sCdj|D�cgc]
}t
|���c}�}td|�dt|��d���|Scc}w)N�, �(z) root types expected, got r)	�json�loadsrorlr5r\rmrwrx)rp�
root_types�decoded�t�expected_typess     r>�	load_jsonr'si���j�j��t�,�-�G��g�u�Z�0�1����J�#?�q�C��F�#?�@����t�G�}�
.�
�	
��N��$@s�A9c���tjj|�}|tjj|�k(r|Stjj|�r|St	|�S)z�Get the last directory in a path that does not exist.

    Example: when path=/usr/a/b and /usr/a does not exis but /usr does,
    return /usr/a
    )r8r��dirnamer��get_non_exist_parent_dir)r��p_paths  r>rr3sP���W�W�_�_�T�
"�F�
�������(�(���
�7�7�=�=�� ��K�+�F�3�3r=c� �tjj|�s�t|�}tjj	|�}d}|dk(rd}t||��5tj|�ddd�t||�|s|rht|||�t|j|�ddd�}t|�}|jD] }	|j|	�}t|||��"yyt||�y#1swY��xYw)NTr�Fr�r�)
r8r�r�rrr��makedirs�chmodr�r	r;r��joinpath)
r�r�r�rT�non_existed_parent_dir�dir_name�selinux_recursive�sub_relative_dir�sub_pathr�s
          r>rrDs���
�7�7�=�=���!9�$�!?���7�7�?�?�4�(�� ���s�?� %��
�(�.?�
@�	��K�K���	�
�d�D���5��.��e�<� $�D�J�J�/E�$F�q�$I�!�"�$M�N���2�3�H�(�.�.�
3��#�,�,�T�2���H�d�E�2�
3�
�	�d�D��	�	�s� D�D
c#�K�	|��|rd|g}tj|�yy#|rd|g}tj|�wwxYw�w)N�umount)r )r+�
umount_cmds  r>�	unmounterr-_sL����"����"�F�+�J��I�I�j�!���6�"�F�+�J��I�I�j�!��s�A�%�A�A�Ac��i}	tjjd�rtd�j	�}d}n1tj
d�}|jj	�}d}tjd�}|D]�}|dk(r)|j�}t|�dk7r�'|\}}}	}
}}nt|j|�}
|
�t|
j��dkr�a|
jd�}|
jd�}|
jd	�}	|
jd�}
|jd
d�}|	||
d�||<��tj!d
||�|S#t"t$f$rt'td�Y|SwxYw)Nz/proc/mountsr��mountz*^(/dev/[\S]+) on (/.*) \((.+), .+, (.+)\)$�r\r�r4rTz\040r�)�fstype�
mountpoint�optszFetched %s mounts from %szFailed fetching mount points)r8r�r�r�rWr rDrN�compiler;r�search�groupsrTr�rZr�rUr�r%)�mounted�
mount_locs�methodrF�mountre�mpline�wordsr��mpr1r3�_freq�_passno�ms              r>�mountsrAism���G�$4�
�7�7�>�>�.�)�'��7�B�B�D�J��F��)�)�G�$�C����.�.�0�J��F��*�*�J�K�� �	�F����������u�:��?��:?�7��b�&�$��w��N�N�6�*���9��A�H�H�J��!� 3���g�g�a�j���W�W�Q�Z���������w�w�q�z�����G�S�)�B� � ���G�C�L�'	�0	�	�	�-�w��?��N��
�W��4��s�2�3��N�4�s�EE"�"F�Fc��t|t�r|g}nKt|ttf�rt|�}n)|�d}n$t	djt
|�����t�r|�?dg}n;t�r.|�gd�}t|�D]\}}|dk(rd||<|dvs�d	||<�nd
g}t�}tj�5}	d}
tjj|�|vr&|tjj|�d}nyd}|D]\}d}	gd
�}
|r|
j!d|g�|
j#|�|
j#|	�t%j$|
|��|	}
|	}nst1d|�d|	�d|����|j3d�s|dz
}t5|
�5|�	||�}n	|||�}|cddd�cddd�S#t&t(f$r6}|r(t*j-d||dj/
�|�|}Yd}~��d}~wwxYw#1swYnxYw	ddd�y#1swYyxYw)a2
    Mount the device, call method 'callback' passing the directory
    in which it was mounted, then unmount.  Return whatever 'callback'
    returned.  If data != None, also pass data to callback.

    mtype is a filesystem type.  it may be a list, string (a single fsname)
    or a list of fsnames.
    Nz6Unsupported type provided for mtype parameter: {_type})r��auto)�ufs�cd9660�msdosr�rE)r��msdosfsrFr�Fr2)r/r��roz-t)�
update_envzbFailed to mount device: '%s' with type: '%s' using mount command: '%s', which caused exception: %sr�zFailed mounting z to z	 due to: r�)rlrmr�r5rwr�rxr)r-r�rAr!�tempdirr8r�r�r�rr rUr�rZr�r\r�r#r-)�device�callbackr`�mtype�update_env_for_mount�	log_error�mtypes�indexr7�tmpdr+r2�failure_reason�mountcmd�excr�s                r>�mount_cbrV�sd��"�%������	�E�D�%�=�	)��e���	�����D�K�K��5�k�
L�
�
�	
��z��>��X�F�	���>�/�F�%�f�-�	(�L�E�5��	�!� (��u�
��+�+� '��u�
�		(�����h�G�	�	�	�	�,����
�7�7���F�#�w�.� ����!1�!1�&�!9�:�<�H�J�!�N��
)��!�
�)�4�H�� ����u�
�6��O�O�F�+��O�O�D�)��I�I�h�3G�H�!�F�!%�J��
)�0�&��t�^�5����"�"�3�'��#��J�
�v�
�	��|��z�*���z�4�0���	�	�O,�,��$ ��)�)� ��	�	�9�#�!��H�H�X�.���&)�N��)��*	�	��	�O,�,�,�sP�	AH4�AG�3:H4�-H�	H4�H�%,H�H4�H�H4�H'	�#H4�4H=c�4�tjt�Sr�)�obj_copy�deepcopyr&r<r=r>�get_builtin_cfgrZ�s�����[�)�)r=c�l�tjd|�tjj	|�S)NzTesting if a link exists for %s)rZr�r8r��islinkr�s r>�is_linkr]�s$���I�I�/��6�
�7�7�>�>�$��r=c��tjd||�|r�tjj	|�rvtjjtjj
|�dtd�z�}tj||�tj||�ytj||�y)Nz$Creating symbolic link from %r => %r�tmpr�)
rZr�r8r�r�r\rr��symlinkr�)�source�link�force�tmp_links    r>�sym_linkre�s~���I�I�4�d�F�C��������&��7�7�<�<������� 5�u�x��{�7J�K��
�
�
�6�8�$�
�
�
�8�T�"���J�J�v�t�r=c�z�tjd|�	tj|�y#t$rYywxYw)NzAttempting to remove %s)rZr�r8�unlinkr�r�s r>�del_filerhs3���I�I�'��.�
�
�	�	�$����
��
�s�.�	:�:c�^�tjd||�tj||�y)NzCopying %s to %s)rZr�r��copyrs  r>rjrjs!���I�I� �#�t�,�
�K�K��T�r=c�|�	tjdtj��}|S#t$rd}Y|SwxYw)Nz%a, %d %b %Y %H:%M:%S %z�??)�time�strftime�gmtimer�)�tss r>�time_rfc2822rqs@���
�]�]�5�t�{�{�}�
E���I����
��
�I��s�(,�;�;c� ��ddl�ddl�G�fd�d�j�}�j�jjd��}�j
�}�j|�|_dt�sdndg}�jd	z|�}|�}|j|�jt|���j|��j|�dd�d
k7r|j|jdzzSt!d��)
a�Use sysctl(3) via ctypes to find kern.boottime

    kern.boottime is of type struct timeval. Here we create a
    private class to easier unpack it.
    Use sysctl(3) (or sysctl(2) on OpenBSD) because sysctlbyname(3) does not
    exist on OpenBSD. That complicates retrieval on NetBSD, which #defines
    KERN_BOOTTIME as 83 instead of 21.
    21 on NetBSD is KERN_OBOOTTIME, the kern.boottime up until NetBSD 5.0

    @return boottime: float to be compatible with linux
    rNc�J��eZdZdW�jfdW�jfgZy)�boottime.<locals>.timeval�tv_sec�tv_usecN)r�r�r��c_int64�_fields_)�ctypess�r>�timevalrt,s����v�~�~�.��F�N�N�0K�L�r=rz�cr���Sr4rg��.Az/Unable to retrieve kern.boottime on this system)ry�ctypes.util�	Structure�CDLL�util�find_library�c_size_t�sizeof�valuer:�c_intr�r�byrefrurv�RuntimeError)rz�libcr��
mib_values�mibr
rys      @r>�boottimer�s������M�&�"�"�M��;�;�v�{�{�/�/��4�5�D��?�?��D����w�'�D�J�	��+��2��J��6�<�<�!��j�
)�C�
�)�C������L�L��Z��)��L�L����L�L����
�
	
��	��z�z�C�K�K�)�3�3�3�
�H�
I�Ir=c�2�d}d}	tjjd�r%d}td�}|r@|j	�d}	|Sd}tt
j�t�z
�}|S#t$rttd|z�Y|SwxYw)Nrlrmz/proc/uptimerryz&Unable to read uptime using method: %s)r8r�r�r�r;rmrmr�r�r%rZ)�
uptime_strr9rs   r>�uptimer�Gs����J�
�F�G�
�7�7�>�>�.�)�#�F�%�n�5�H��%�^�^�-�a�0�
���
�F��T�Y�Y�[�8�:�5�6�J�����G��s�<�v�E�F���G�s�AA6�
*A6�6B�Bc�"�t||dd��y)Nr�)�omoder���
write_file)r��contents  r>�append_filer�Zs���t�W�D�t�4r=)�
preserve_moder�c�$�t|dd||��y)Nr�r�)r�r�r�r�r�)r�r�r�s   r>�ensure_filer�^s����b��4�}�r=c�D�	t|�S#ttf$rYywxYwr�)r7rrw)�possible_ints r>�safe_intr�fs)����<� � ���	�"����s�

��c��t|�}|r.|r+t|�5tj||�ddd�yyy#1swYyxYwr�)r�r�r8r#)r�r��	real_modes   r>r#r#msG�����I��	�
�$�
�	&��H�H�T�9�%�	&�	&��t�	&�	&�s	�=�A�grp_namec��d}	tj|�j}|S#t$rtjd|�Y|SwxYw)zt
    Returns the group id of a group name, or -1 if no group exists

    @param grp_name: the name of the group
    rz"Group %s is not a valid group name)r�r�r�r�rZr�)r�r�s  r>�get_group_idr�tsQ��
�C�B��l�l�8�$�+�+���J���B��	�	�6��A��J�B�s�%�A�Ar�c�f�tjtj|�j�S)z�
    Returns the octal permissions of the file/folder pointed by the path,
    encoded as an int.

    @param path: The full path of the file/folder.
    )r��S_IMODEr8�st_moder�s r>�get_permissionsr��s!���<�<�����
�-�-�.�.r=c�~�tj|�}tj|j�j
S)zw
    Returns the owner of the file/folder pointed by the path.

    @param path: The full path of the file/folder.
    )r8r�r��getpwuid�st_uid�pw_name�r��sts  r>�	get_ownerr���*��
�����B��<�<��	�	�"�*�*�*r=c�~�tj|�}tj|j�j
S)zw
    Returns the group of the file/folder pointed by the path.

    @param path: The full path of the file/folder.
    )r8r�r��getgrgid�st_gid�gr_namer�s  r>�	get_groupr��r�r=�usernamec�*�g}tj�D],}||jvs�|j|j��.tj|�j}|jtj|�j�|S)zp
    Returns a list of all groups to which the user belongs

    @param username: the user we want to check
    )	r��getgrall�gr_memrr�r�r��pw_gidr�)r�r6rTr�s    r>�get_user_groupsr��sp���F�����)���u�|�|�#��M�M�%�-�-�(�)��,�,�x�
 �
'�
'�C�
�M�M�#�,�,�s�#�+�+�,��Mr=zWriting file)�ensure_dir_existsr�rTr�c	�J�|r	t|�}|r+ttjj|�||��d|j
�vrt|�}d}n
t|�}d}	d|z}	tjd|||	t|�|�t|��5t||�5}
|
j|�|
j!�d	d	d	�d	d	d	�t#||�y	#t$rY��wxYw#t$rd|z}	Y��wxYw#1swY�AxYw#1swY�ExYw)
a)
    Writes a file with the given content and sets the file mode as specified.
    Restores the SELinux context if possible.

    @param filename: The full path of the file to write.
    @param content: The content to write to the file.
    @param mode: The filesystem mode to set on the file.
    @param omode: The open mode used when opening the file (w, wb, a, etc.)
    @param preserve_mode: If True and `filename` exists, preserve `filename`s
                          current mode instead of applying `mode`.
    @param ensure_dir_exists: If True (the default), ensure that the directory
                              containing `filename` exists before writing to
                              the file.
    @param user: The user to set on the file.
    @param group: The group to set on the file.
    )r�rT�brr�
charactersz%oz%rzWriting to %s - %s: [%s] %s %sr�N)r�r�rr8r�rr�rtrorwrZr�rr�r�r�r�r#)rVr�r�r�r�r�r�rT�
write_type�mode_r�fhs           r>r�r��s ��:�	�"�8�,�D���2�7�7�?�?�8�,�4�u�E�
�e�k�k�m���g�&���
���(��!�
�������I�I�(��
���G���
�
�8�	$��
�(�E�
"�	�b��H�H�W���H�H�J�	��
�(�D���7�	��	����������	�	����sG�C*�*C9�
D�+"D
�
D�*	C6�5C6�9D
�	D
�
D	�D�D"c���tj|�D]X}tjj||�}tjj	|�rt|��Nt
|��Zy)z�
    Deletes all contents of a directory without deleting the directory itself.

    @param dirname: The directory whose contents should be deleted.
    N)r8r"r�r\r�r�rh)r�node�
node_fullpaths   r>�delete_dir_contentsr��sP���
�
�7�#�$�������W�d�3�
�
�7�7�=�=��'��M�"��]�#�$r=c��tj�}t|�}|d|j��d|��z
}|dt	�zz
}|S)Nr�z by cloud-init v. z on %s)r$�version_stringrm�titlerq)�comment_charr��ci_ver�headers    r>�make_headerr��sE��
�
#�
#�
%�F�
��
�F�
�4�:�:�<��@�@�F�
�h���'�'�F��Mr=c	�$�t|ttf�s!tdt	j
|�z��d}|r|dz
}ddz}d}|D]�}t|ttf�rRg}|D]/}|j
dt|�jd|�z��1|�d	j|��d
�}|dz
}�kt|t�r
|�|�d
�}|dz
}��|���tdt	j
|��d
|����tjd|�|S)Nz8Input to shellify was type '%s'. Expected list or tuple.r�z
#!/bin/sh
z%s%s%s%s)�'�\r�r�rz'%s'r�r�r7r�zUnable to shellify type 'z&'. Expected list, string, tuple. Got: zShellified %s commands.)rlr5r�rwr"r�rrmr�r\rZr�)�cmdlist�
add_headerr��escaped�	cmds_mader��fixedr's        r>�shellifyr�		s$���g��t�}�-��F��"�"�7�+�
-�
�	
�
�G���=� ���0�0�G��I�����d�T�5�M�*��E��
F�����V�s�1�v�~�~�c�7�'C�D�E�
F�")�3�8�8�E�?�;�G���N�I�
��c�
"�")�4�0�G���N�I�
�\���'�0�0��6��>��
�!�*�I�I�'��3��Nr=c��|r|j|�r|t|�d}|r |j|�r|dt|�}|Sr�)r�rr#)ra�prefix�suffixs   r>�strip_prefix_suffixr�.	sE��
�$�/�/�&�)��C��K�M�"��
�$�-�-��'��N�s�6�{�l�#���Kr=c��tj|d��y	tj|�y#tj$rYywxYw)NrFT)r �whichr])r�s r>�_cmd_exits_zeror�6	sG���z�z�#�a�&��!����	�	�#�����%�%����s�1�A�Ac��tgd��S)N)zsystemd-detect-virtz--quietz--container�r�r<r=r>�_is_container_systemdr�@	s���L�M�Mr=c��tdg�S)Nzlxc-is-containerr�r<r=r>�_is_container_old_lxcr�D	s���.�/�0�0r=c��t�sygd�}tj|d��ytj|�\}}|j�dk(S)NF)r�z-qnzsecurity.jail.jailedrr+)r3r r�rE)r�rFr)s   r>�_is_container_freebsdr�H	sG���<��
3�C��z�z�#�a�&��!��
�Y�Y�s�^�F�C���9�9�;�#��r=c��tttf}|D]}|�s�y	td�}d|vryd|vry	tjjd�r tjjd�sy	td�j�}|D]>}|jd�s�|j�jd	d�\}}|d
k7s�>y	y#tt
f$rY��wxYw#tt
f$rYywxYw)zH
    Checks to see if this code running in a container of some sort
    Tr��	container�LIBVIRT_LXC_UUIDz/proc/vzz/proc/bcz/proc/self/statuszVxID:rPr/F)r�r�r��get_proc_envrUr�r8r�r�r�rWr�rEr;)�checks�helper�pid1env�linesra�_keyrcs       r>r�r�R	s��	����F�����8���	
��q�/���'�!����(��)�
�w�w�}�}�Z� ������z�)B��	
��2�3�>�>�@���	 �D����w�'�"�j�j�l�0�0��a�8���s��#�:��		 ���%
�W��
��
��
�W��
���
�s:�C�C�9/C,�)(C,�C,�C,�C)�(C)�,C>�=C>c�@�tjjd�S)z2Check to see if we are running in a lxd container.z
/dev/lxd/sock)r8r�r�r<r=r>�is_lxdr��	s��
�7�7�>�>�/�*�*r=rk�errorsc�>�tjjdt|�d�}	t	|�}i}d\}}|j||�}|j|�D]"}|s�|j|d�\}	}
|	s�|
||	<�$|S#t
tf$ricYSwxYw)z�
    Return the environment in a dict that a given process id was started with.

    @param encoding: decoding will be done with .decode(encoding, errors) and
    text will be returned.
    @param errors: passed through .decode(encoding, errors).
    z/procr�)r��=r�)	r8r�r\rmr�rUr�rnr;)�pidrkr�rr�env�null�equalr�rIrcs           r>r�r��	s���
�����g�s�3�x��	3�B��#�B�'��
�C��K�D�%����x��0�H��~�~�d�#������i�i��q�)���s���C��I���J��
�W����	��s�B�B�Bc��i}|j�D]}	|jdd�\}}|||<�|S#t$r|}d}Y�wxYw)Nr�r�T)r;r)�kvstringr�r�rArcs     r>�keyval_str_to_dictr��	sc��
�C��~�~����	����3��*�J�S�#���C��
��J��	�	��C��C�	�s�5�
A�Ac�r�|jd�r|dd}tjjd|z�S)Nr��z/sys/class/block/%s/partition)r�r8r�r)rKs r>�is_partitionr��	s4��
����!������
�7�7�>�>�9�F�B�C�Cr=c��t|t�s|g}g}|D]�}t|t�r|j|��%t|ttf�rmt|�dkst|�dkDrt
d��t|�dk(r#|dr|j|t	|�z���|j|d���t
d��|S)Nr�r4z Invalid package & version tuple.rzInvalid package type.)rlr�rmrr5rr�)�version_fmt�pkgs�pkglist�pkgs    r>�expand_package_listr��	s����d�D�!��v���G��8���c�3���N�N�3����c�E�4�=�)��3�x�!�|�s�3�x�!�|�"�#E�F�F��3�x�1�}��Q�����{�U�3�Z�7�8���N�N�3�q�6�"��6�7�7�!8�$�Nr=c�<�|jd�D�cgc]}|s�|��	}}d}d}d}d}	t|�D]�\}
}|j�}t|�dkr"|jd|
dzt|�|�y|d}
|
jd�D�cgc]}|s�|��	}}t|�t|�kDr��t	t|�t|��}|d||d|k7r��|	�t|	�t|�kDr��	|jd�}
	||
dz}||
d
z}|
}|}	|d}��|r|r|r
|rr||||fSy|r	|r|r|||fSycc}wcc}w#t$r|jd	|
dz|�YywxYw#t$r|jd|
dz|�YywxYw)
zRReturn the mount information for PATH given the lines from
    /proc/$$/mountinfo.r�N�
z$Line %d has two few columns (%d): %sr�r\r�-z,Did not find column named '-' in line %d: %sr4z/Too few columns after '-' column in line %d: %sr�)r;r�rr��minrQr�
IndexError)r��mountinfo_lines�log�get_mnt_optsr��
path_elements�devpth�fs_type�match_mount_point�match_mount_point_elementsr�rar��mount_point�mount_point_elements�x�
mount_optionss                 r>�parse_mount_infor�	s��!%�
�
�3��5�1�1�Q�5�M�5�
�F��G���6:���_�-�9!���4��
�
����u�:��?��I�I�6��A��s�5�z�4�
���A�h��+6�+<�+<�S�+A�G�a�Q��G��G��#�$�s�=�'9�9��
��(�)�3�}�+=�>����!�$�
�a��(:�:��&�1�c�&�7
��$�%�7&�
�
	����C� �A�	��A��E�l�G��1�q�5�\�F�(��%9�"��a��
�s9!�v��g�"3�
��G�%6�
�F�F�
��g�"3��G�%6�7�7���O6��* H��.�	��I�I�>��A��t�
��		���	��I�I�A�1�q�5�$�
��		�s:�E�E�E
�E
�>E�E8�E5�4E5�8F�Fc��td�j�D]%}|j�dd\}}}||k(s� |||fcSy)z<On older kernels there's no /proc/$$/mountinfo, so use mtab.�	/etc/mtabNrT)r�rWr;)r�rarrr	s     r>�
parse_mtabr 
sR���{�+�6�6�8�0��'+�z�z�|�B�Q�'7�$���W��$���7�K�/�/�0�r=c��|jd�}t|�dk(r|dSt|�dk(r|dS|ddvrx|dd}tjgd��\}}|jd	�D]:}|j�}t|�dkDs�"|d|k(s�+|d}t|�St|�Stjd
|�y)Nr�r�rrTr4)r��gpt�gptidrD�ufsidr�)�glabel�statusz-sr7z)Unexpected input in find_freebsd_part: %s)r;rr rmrZr[)�fs�splitted�target_labelr�r��labelsr�s       r>�find_freebsd_partr)
s����x�x��}�H�
�8�}�����{��	�X��!�	���{��	�!��A�	A��!�"�v���y�y�!;�<���t��j�j��&�	�F��L�L�N�E��5�z�A�~�%��(�l�":��Q�x����4�y��	�
�4�y�����?��Dr=c���d}|jd�D]K}|j�}t|�dkDs�"tjj	|d|z�s�H|}|S|S)Nr7r4r�)r;rr8r�r�)r��mnt_list�
path_foundrar�s     r>�get_path_dev_freebsdr"<
sb���J����t�$����
�
����u�:��>�b�g�g�n�n�U�1�X��_�=��J�����
�r=c���tjdd|gddg��\}}t|�r+tjddg�\}}t||�}|�y|}|j�}t	|d�}d|zS)Nr/z-prr�r�r�)r rr"r;r)r�rnrfr r!r��
label_parts       r>�get_freebsd_devpthr%F
s|���I�I�w��d�3�!�Q��@�M�V�S�
�3�x��)�)�W�d�O�4���3�)�$��9�
������
�,�,�.�C�"�3�q�6�*�J��Z��r=c��tjdg�\}}d}|jd�D�cgc]}|s�|��	}}d}d}d}	d}
|j�D�]�}tj||�}|s�|jd�}|jd�}|jd�D�cgc]}|s�|��	}
}t
|
�t
|�kDr�xtt
|
�t
|��}|
d||d|k7r��|
�t
|
�t
|
�kDr��|}	|
}
|jd�}|jd	�}|�Ld
j|jd	�jd
�j�jd��}tjd||||�tjd
|�}|st�r|dvrt|�}|}|	|k(s���n|	r|	|vry|rrr|	r	r|||	|fSyyyyrr|	r|||	fSyyycc}wcc}w)z�Return the mount information for PATH given the lines ``mount(1)``
    This function is compatible with ``util.parse_mount_info()``r/ze^(?P<devpth>[\S]+?) on (?P<mountpoint>[\S]+?) (\(|type )(?P<type>[^,\(\) ]+)( \()?(?P<options>.*?)\)$r�Nrr2rrxr�rQrzNfound line in mount -> devpth: %s, mount_point: %s, fs_type: %s, options: '%s'z^(/dev/.+)[sp]([0-9])$)�zfs�nfs)r r;rWrNr5rTrrr\rErZr�r3r%)r�r�mountoutputr��regexr�rrrr
rrar@r
rr	r�devm�match_devpths                   r>�parse_mountr-T
s^���)�)�W�I�.��[�$�	C�
�
!%�
�
�3��5�1�1�Q�5�M�5�
�F��K���6:���&�&�(�8���I�I�e�T�"��������"���g�g�l�+��+6�+<�+<�S�+A�G�a�Q��G��G��#�$�s�=�'9�9��
��(�)�3�}�+=�>����!�$�
�a��(:�:��&�1�c�&�7
��$�%�7&�
�'��%9�"��'�'�&�/�����	�*�
��$��H�H����	�"�(�(��-�3�3�5�;�;�D�A��M�	�	�	�
�����
	
��y�y�1�6�:���
����)F�(��/�F�����$��q8�t� 1�� =����G�(9�m� �'�+<�m�L�L�?L�(9�G�<��G�(9� �'�+<�=�=�):�G�<��M6�� Hs�H�H�'H	�/H	c�(�dtj�z}tjj|�r't	|�j�}t
||||�Stjjd�rt|�St||�S)Nz/proc/%s/mountinfor)	r8�getpidr�r�r�rWrrr-)r�rr�mountinfo_pathr�s     r>�get_mount_infor1�
sp��:*�B�I�I�K�7�N�	�w�w�~�~�n�%��~�.�9�9�;����e�S�,�?�?�	������	$��$����4��.�.r=�optc�H�t|d���^}}||jd�vS)NT�rrQ�r1r;)r�r2r)�mnt_optss    r>�
has_mount_optr7�
s&��!�$�T�:�L�Q���(�.�.��%�%�%r=c�N�|jdd�}t|�dkDr|S|dfS)Nr3r�)�rsplitr)�dottedrXs  r>�expand_dotted_devnamer;�
s,���=�=��a� �D�
�4�y�1�}�����~�r=c��|�g}|�g}g}i}||zD]}	t||z|zd��||<�t|�r*t	djdj
|�����|S#t$r||vr|j|�Y�swxYw)NF�rzMissing required files: {files}rQ)�files)r�r�rrrr�r\)r��required�optional�delimrer�r's       r>�pathprefix2dictrB�
s������������G�
�C�
��
 �"��	"�%�d�U�l�Q�&6�e�D�C��F�"��7�|��-�4�4�3�8�8�G�;L�4�M�
�	
��J��!�	"��H�}����q�!��	"�s�A%�%B�Bc�8�ddddd�}dddd	�}i}t|�j�D]J}	|j�\}}}|rt	|�||z||<�/||vs�4t	|�||z|||<�L|S#t$r|j�\}}d
}Y�WwxYw)N��r��@)�kB�mB�B�gB�total�free�	available)z	MemTotal:zMemFree:z
MemAvailable:rI)r�rWr;rr7)	�meminfo�raw�mpliers�kmapr�rarAr��units	         r>�read_meminforS�
s����%�a�u�=�G���$��D�

�C��w�'�2�2�4�	8��	�#�z�z�|��C�����5�z�G�D�M�1�C��H�
�D�[� ��Z�'�$�-�7�C��S�	�N�	8��J���	�����J�C���D�	�s�A8�8B�Bc�l�|}|jd�r|dd}n|jd�r|dd}dddd	d
d�}|}d}|D]%}|j|�s�|}|dt|�}�'	t|�}|dkrtd|z��t	|||z�S#t$r}td
|z�|�d}~wwxYw)a}Convert human string or integer to size in bytes

    In the original implementation, SI prefixes parse to IEC values
    (1KB=1024B). Later, support for parsing IEC prefixes was added,
    also parsing to IEC values (1KiB=1024B). To maintain backwards
    compatibility for the long-used implementation, no fix is provided for SI
    prefixes (to make 1KB=1000B may now violate user expectations).

    Future prospective callers of this function should consider implementing a
    new function with more standard expectations (1KB=1000B and 1KiB=1024B)

    Examples:
    10M => 10485760
    10MB => 10485760
    10MiB => 10485760
    �iBN���rIrr�rDrErFl)rI�K�M�G�Trz'%s' is not valid input.z'%s': cannot be negative)r#r�floatrr7)r��size_inrP�num�mplierr@r�s       r>�human2bytesr_s���"�G��}�}�T���C�R�y��	
���s�	��C�R�y���E��E��F�G�
�C�
�F�
�$���=�=����F��q�C��F�7�#�C�$�
F��C�j���Q�w��3�g�=�>�>��s�W�V�_�$�%�%��
�F��3�g�=�>�A�E��F�s�'B�	B3�B.�.B3c�j�|�tj�d}|dk(xs|ddk(xr|dddk(}|S)z$Return True if platform is x86-basedNr\�x86_64rr�r4�86)r8r9)�
uname_arch�x86_arch_matchs  r>�is_x86re:sM�����X�X�Z��]�
��8�+���1�
���7��A�B��4�!7���r=c�,�tj|�Sr�)�email�message_from_string)r�s r>rhrhDs���$�$�V�,�,r=c�F�tjddgd��}t�}|jj�D]Q}	|j	dd�\}}}|j
d�s�,|jtjdd|���S|S#t
$rY�awxYw)	Nz
dpkg-queryz--listTrBr4)�hi�iiz:.*r�)
r r^rDrWr;rr�rcrN�sub)rF�	pkgs_instra�stater�r)s      r>�get_installed_packagesroHs���
�)�)�\�8�,�d�
;�C���I��
�
�%�%�'�2��	�"�j�j��q�1�O�U�C�����L�)��M�M�"�&�&���C�0�1�
2�����	��	�s�B�	B �B c�x�d}	tt|d���}|jdd�j�dk(ry	t�}d|vrytd	d��}d|j�vrytjjd
�ryy#t$r!}t
j
d||�Yd}~�ud}~wwxYw)NrWTr=rKr�zubuntu-corez!Unexpected error loading '%s': %sz
snap_core=z/etc/system-image/channel.iniz/etc/system-image/config.d/F)r`r�rar�rrZr[r8r8r�r�)�orpath�orinfor�r2r�s     r>�system_is_snappyrsWs����F�D�#�N�6��$F�G���:�:�d�B��%�%�'�=�8��9�
�m�G��w����<�D�I�G���
�
��'��	�w�w�}�}�2�3�����D����7���C�C��D�s�9B�	B9�B4�4B9c��d}|j�D]}|jd�s�|dd}n|�y|jd�r|S|jd�rd|td�dzS|jd�rd|td�dj�zS|jd�rTd	|td�dj�z}tj
j
|�r|St|�}|r|d
S|Sd|zS)Nzroot=r�r�r�z/dev/disk/by-label/zUUID=z/dev/disk/by-uuid/z	PARTUUID=z/dev/disk/by-partuuid/r)r;r�rr�r8r�r�r�)r2rir��
disks_path�resultss     r>�rootdev_from_cmdlinerwos���E��}�}�����>�>�'�"����G�E���
�}������ �������!�$�u�S��]�_�'=�=�=����� �#�e�C��L�N�&;�&A�&A�&C�C�C�����$�$�u�S��-=�-?�'@�'F�'F�'H�H�	��7�7�>�>�*�%��� ��'����1�:�����U�?�r=c�p�d�}i}||�D]%}|jdd�\}}|s|}|s|s�!|||<�'|S)z�Given shell like syntax (key=value\nkey2=value2\n) in content
    return the data in dictionary form.  If 'add_empty' is True
    then add entries in to the returned dictionary for 'VAR='
    variables.  Set their value to empty_val.c�0�tj|d��S)NT)�comments)�shlexr;)rgs r>�_shlex_splitz(load_shell_content.<locals>._shlex_split�s���{�{�4�$�/�/r=r�r�)r;)r��	add_empty�	empty_valr|r`rarAr�s        r>r`r`�sS��0��D��W�%����Z�Z��Q�'�
��U���E����D��I���Kr=c	��t|�}d}	|t|D�cgc]$}tjj|�s�#|��&c}�z}|stjd|||�gS|dk(rtjd|||�||z|kDrnt
j|�||z
}��tjd|||�|Scc}w)Nrz)%sAll files appeared after %s seconds: %sz6%sWaiting up to %s seconds for the following files: %sz*%sStill missing files after %s seconds: %s)r^r8r�r�rZr�rm�sleep)�flist�maxwait�naplen�log_pre�need�waitedr's       r>�wait_for_filesr��s����u�:�D�
�F�
����:�1������q�(9�Q�:�;�;����I�I�;����	
��I��Q�;��I�I�H����	
��F�?�W�$���
�
�6���&���)�,�I�I�4�g�w����K��1;s
�$C
�C
c�<�d�}|jd|gt��y)z-Helper to wait on completion of snap seeding.c��tjd�stjd�ytjgd��y)N�snapz+Skipping snap wait, no snap command present)r��waitr(zseed.loaded)r r�rZr�r<r=r>rLz&wait_for_snap_seeded.<locals>.callback�s+���z�z�&�!��I�I�C�D���	�	�;�<r=zsnap-seeded)�freqN)�runr')rPrLs  r>�wait_for_snap_seededr��s��=�
�I�I�m�X�r��I�9r=c�T�t|d��}|djd�}|ddk(S)z1Check whether the given mount point is mounted rwTr4rrQr�rwr5)rrn�
mount_optss   r>�mount_is_read_writer��s1��
�K�d�
;�F����!�!�#�&�J��a�=�D� � r=c��tjd�syddg}|r5tjj	|�ry|jd|zg�|r|jd|zg�tj|�S)zAInvoke udevadm settle with optional exists and timeout parameters�udevadmN�settlez--exit-if-exists=%sz--timeout=%s)r r�r8r�r�r�)r�r��
settle_cmds   r>�udevadm_settler��sr���:�:�i� �	��X�&�J�
�
�7�7�>�>�&�!�����0�6�9�:�;�����>�G�3�4�5��9�9�Z� � r=r�r(c�l�dgi}	tjt|jd�d���}d|vrg|d<|S#t$r)t
j
d|jd��Y|Stj$r0}t
jdtj|�Yd}~|Sd}~wwxYw)N�scopeszhotplug.enabledFr=zFile not found: %sz>Ignoring contents of %s because it is not decodable. Error: %s)rrr�r�r�rZr��JSONDecodeErrorr[r�HOTPLUG_ENABLED_FILE)r�r�r�s   r>�read_hotplug_enabled_filer��s����r�N�G�#��*�*��5�?�?�+<�=�U�K�
���7�"� "�G�H���N���L��	�	�&����8I�(J�K��N����
����L��)�)�
�	
�	
��N��
�s�/A�.B3�1B3�%B.�.B3c#�K�d��y�w)ztContext manager that does nothing.

    Note: In python-3.7+, this can be substituted by contextlib.nullcontext
    Nr<r<r=r>�nullcontextr��s����
�s�)r}r�)� N)TTr�)rr)r�r�r�)r�r�r�r)z
/etc/hosts)NrKNFNr�)rDN)i�)NNN)NNNT)�)r�r�F)rS�created)T)r}r�)z
/proc/meminfoF)FN)g�?r�)�ry�
contextlibrjrXrgrr�r	r�rr�loggingr8�os.pathr'r�r�rNr{r�r_r�r�r�r�rm�base64r�collectionsrrrr�r�	functoolsr�pathlibr	�typesr
�typingrrr
rrrrrrrrrrr�urllibrr�	cloudinitrrrrrrr r!r"r#r$�cloudinit.log.log_utilr%�cloudinit.settingsr&r'�cloudinit.helpersr(r]�	getLoggerr�rZ�sepr�r�r�rr�r�r?rGrOrmrrrort�timedr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr^r#r)r-r3r7r:r=rBrDrFrUrkr�r2r�r�r�r�r�r�r�r�r�r�r�r�r�r)r/r4r3rFrHrQrYr�rurOrzr~r�r�r�r�r�r�r�r��PathLiker7r�r�r�r8r�r�r�r�r�r�rrr	rrrrrr-rArVrZr]rerhrqr�r�r�r�r�r#r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr"r%r-r1r7r;r�rBrSr_rerhrorsrwr`r�r�r�r�r�r�r<r=r>�<module>r�sz�������
���	���	���
�
�	��
�
��
��
����/��������� ������*�4��'����g����!���F�F�C����v�}�}�
$�v�';�';�
;�
�)��+�
�>����
�����
��:M��c�5�j�)�M��M�
O�e�C��J�'�O�e�O�
����$�%�
�%�
�E�
�&�
� �&,�,�^	�y�	�	��	�
�*�� �D��,0�..�D�..�h&�$�
�
4� 
� 	�3�	�4�	���(�
�(����
����1�
�1���3�
�3���0�
�0���1�
�1�%��?�%�P��:1�
�:1�z7�t��
�
�
��6�0�&Q5�h5�8�G�,�5��5�p��������������
�&�B!�4�'�%�P)�X.2��d��@9=�,��,�^<�
 �F*��z��(8�V%�P����?�#�0�$�0�$�0�f�
��
�(EI��*EI��6EI�*�$EI�*�(EI�=�@�>�04��	���b�k�k�!�"���h��u�d�{�+�
,���	�
��004��	P���b�k�k�!�"�P��h��u�d�{�+�
,�P��	P�
	�P����
��$�	�d�	���
�_�	
�c�3�h��_�'��}�_�	�(�3�-��_�D+*�T�#�s�(�^�+*�\�S��������
����>�"� $�w��#��4�"�6���"��"�'�Z
�
���
[�|*�
 �
	�
��
���'J�
�'J�T�&5�
��6;����/3��	���&��3��3��/�#�/�#�/�+�C�+�C�+�+�C�+�C�+�
�c�
�d�3�i�
� ����>�"�
�
��:�#�	
�
�:�
�:��:�#�:�z$��"�J��N�1����*�
�*�Z+�1:����*-��	�#�s�(�^��>	�D��614�%�K�\�E�&� �T>�n!�u�$/�N&�S�&�T�&�
�$(�$�b�g�g�k�k��0�0(&�V�-���0�>�(�>	:�!�!�$�W����(�
�Y�t�S�$��/�
��
r=
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!