403Webshell
Server IP : 178.105.222.151  /  Your IP : 216.73.216.38
Web Server : nginx/1.28.3
System : Linux MNK 7.0.0-15-generic #15-Ubuntu SMP PREEMPT_DYNAMIC Wed Apr 22 16:06:43 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.5.4
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /proc/self/root/lib/python3/dist-packages/cloudinit/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/self/root/lib/python3/dist-packages/cloudinit/__pycache__/util.cpython-314.pyc
+
��i�l��2
�^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RI	t	^RI
t
^RIt^RIt^RI
t^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIt^RIHt^RIHt^RIHtHt^RI H!t!^RI"H#t#^RI$H%t%^RI&H't'^R	I(H)t)H*t*H+t+H,t,H-t-H.t.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6^R
I7H8t8^RI9t9^RI:H;t;H<t<H=t=H>t>H?t?H@t@HAtAHBtBHCtCHDtDHEtE^RIFHGtG^R
IHHItIHJtJ]*'d^RIKHLtLRsM]P�!]O4tP]P�R/tRR]P�,]P�,tUR�tVR�tWRtX]#!4R4tY]#!4R4tZR�RRllt[R�RRllt\]?P�!R4RRl4t^Rt_!RR4t`!RR]a4tb!R R!]a4tcR"tdR�R#lteR�R$ltfR�R%ltgR�R&lthR�R'ltiR(R/R)R*lltjR+tkR,tlR-tmR�R/ltnR0toR1R2ltp]#!4R34tq]#!4R44tr]#!4R54ts]#!4R64tt]#!4R74tu]#!4R84tvR�R:ltwR�R;ltxR�R<ltyR�R=ltz]#!4R>4t{R?t|]#!4R@4t}R�RAlt~R�RBltRCt�R�RDlt�R�RERFllt�]P<RG4t�]P<RH4t�RIt�RJt�R�RKlt�R�RLlt�R]�33RMlt�R�RNlt�R(R/RORPllt�R(R/RQRRllt�R�RSlt�R�RTlt�RUt�!RVRW]24t�R�RXlt�R�RYlt�]?P�!RZ4R[R\l4t�R]t�R^t�R_t�R`t�R�Ralt�R�Rblt�R�Rclt�R�Rdlt�R�Relt�R�Rflt�Rgt�RhRRiR9/RjRkllt�RhRRiR9/RlRmllt�]#!4Rn4t�Rot�RpRqlt�R�Rrlt�R�Rslt�R�Rtlt�RuRvlt�RwRxlt�R�RyRzllt�R{t�R|t�R}t�R�R~lt�]?P�!R4]�33R�l4t�R�t�R�R�lt�]P<R�4t�R�t�R�R�lt�R�t�R�t�R�R�lt�R�t�R�tR�t�]#!4R�4t�R�t�R�t�R�R�R9/R�R�lllt�R�t�R�t�R�R�lt�R�R�lt�R�R�lt�R�R�lt�R�R�lt�]?P�!R�4R�R�R.R�RR�R/R�R�lll4t�R�t�R�R�lt�R�R�lt�R�R�lt�R�t�R�t�R�t�R�t�]#!4R�4t�R�t�R�R�R�llt�R�t�R�t�R�t�]PR93R�lt�R�t�R�t�R�t�R�t�R�R�lt�]PR93R�lt�R�R�lt�R�t�RR]EP�P�3R�lt�R�R�lt�R�t�R�R�lt�R�t�R�t�R�t�R�t�R�R�lt�R�R�lt�R�t�R�t�R�R�lt�R�R�lt�]R�R�l4t�R#)��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_-.()c��\\\\P!4P
P
R4R,44#)�.�N�N)�tuple�map�int�os�uname�release�split���0/usr/lib/python3/dist-packages/cloudinit/util.py�kernel_versionr8`s0����S�"�(�(�*�,�,�2�2�3�7��;�<�=�=r6c�j�\P!RR.RR7pVPP4#)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 r7�get_dpkg_architecturer@ds-���)�)�V�3�4�d�
C�C��:�:����r6c�d�RRRRRRRR/p/p\P!RR	.R
R7pVPP4F8pVPR4wrEpW@9gKVP	4WV,&K:	VP4Uu.uF
qwV9gKVNK	ppV'd&\PR
RPV44V#uupi \PdBp	\PRT	4\RTP444pRp	?	T#Rp	?	ii;i)�Codename�codename�Description�descriptionzDistributor ID�id�Releaser3�lsb_releasez--allTr;�:z.Missing fields in lsb_release --all output: %s�,z#Unable to get lsb_release --all: %sc3�("�TFqR3x�K
	R#5i)�UNAVAILABLENr5)�.0�vs& r7�	<genexpr>�lsb_release.<locals>.<genexpr>�s���>�
�1�
�&�
�s�N)r r=�
splitlines�	partitionr>�values�LOG�warning�join�ProcessExecutionError�dict)
�fmap�datar?�line�fnamer)�val�k�missing�errs
          r7rHrHos��	�J��}��$��9�	�D��D�?��i�i���0�$�?���J�J�)�)�+�D� �N�N�3�/�M�E�c��}�$'�I�I�K��%�[�!�,�#�k�k�m�=�m���}�1�1�m��=���K�K�@�����!�
��K��>���%�%�?����9�3�?��>����
�>�>���K��	?�s6�AC�!/C�C�C�#/C�C�D/�.6D*�*D/c�R�V^8�dQhR\\\3,R\/#)r-�blob�return�r�str�bytes)�formats"r7�__annotate__rh�s'��M�M��c�5�j�)�M��Mr6c�V�\V\4'dV#VPVR7#�)�encoding)�
isinstancere�decode)rbrks&&r7�
decode_binaryrn�s$���d�C�(�(�4�L�d�k�k�8�k�.L�Lr6c�R�V^8�dQhR\\\3,R\/#)r-�textrcrd)rgs"r7rhrh�s'��O�O�e�C��J�'�O�e�Or6c�V�\V\4'dV#VPVR7#rj)rlrf�encode)rprks&&r7�encode_textrs�s$���d�E�*�*�4�N����X��0N�Nr6zBase64 decodingc�0�V^8�dQhR\R\/#)r-rZrc)rf)rgs"r7rhrh�s��
�
�%�
�E�
r6c��\V\4'g\R\V4,4h\	VRR7# \
PdTu#i;i)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)rlrf�	TypeError�typer�binascii�Error)rZs&r7�maybe_b64decoder{�sP���d�E�"�"��6��d��C�D�D�����-�-���>�>�����s�A�A�Ac��VPRR7pVP4R8Xdb\V\4'dLVP	4pV'd VP
'dVP
pMRpVP
VR4#V#)T)rmrp�utf-8�surrogateescape)�get_payload�get_content_maintyperlrf�get_charset�input_codecrm)�part�cte_payload�charsetrks&   r7�fully_decoded_payloadr��s����"�"�$�"�/�K�� � �"�f�,���U�2�2��"�"�$���w�*�*�*��*�*�H��H��!�!�(�,=�>�>��r6c�6a�]tRt^�toRRltRtRtRtVtR#)�SeLinuxGuardc��V\P!R4VnWnW nR# \dRTnL"i;i)�selinuxN)r�
import_moduler��ImportError�path�	recursive)�selfr�r�s&&&r7�__init__�SeLinuxGuard.__init__�sB��	
�	 �#�1�1�)�<�D�L��	�"����	 ��D�L�	 �s�-�A�Ac�n�VP'd#VPP4'dR#R#�TF)r��is_selinux_enabled)r�s&r7�	__enter__�SeLinuxGuard.__enter__�s#���<�<�<�D�L�L�;�;�=�=��r6c���VP'd!VPP4'gR#\PP	VP4'gR#\PPVP4p\P!V4pVPPWE\P,4\PRTTP4TPPY@PR7R# \dR#i;i \d.p\PRTTPT4Rp?R#Rp?ii;i)Nz,Restoring selinux mode for %s (recursive=%s)�r�z,restorecon failed on %s,%s maybe badness? %s)r�r�r1r��lexists�realpath�lstat�matchpathcon�stat�ST_MODE�OSErrorrT�debugr��
restoreconrU)r��	excp_type�
excp_value�excp_tracebackr��stats�es&&&&   r7�__exit__�SeLinuxGuard.__exit__�s����|�|�|�4�<�<�#B�#B�#D�#D���w�w���t�y�y�)�)���w�w����	�	�*��	��H�H�T�N�E��L�L�%�%�d�$�,�,�,?�@�	�	�	�:���N�N�	
�
	��L�L�#�#�D�N�N�#�C���	��	���	��K�K�>������	
�
��	�s+�AD �8&D2� D/�.D/�2E*�="E%�%E*)r�r�r�N�F)	�__name__�
__module__�__qualname__�__firstlineno__r�r�r��__static_attributes__�__classdictcell__��
__classdict__s@r7r�r��s����	#���r6r�c��]tRt^�tRtR#)�MountFailedErrorr5N�r�r�r�r�r�r5r6r7r�r�����r6r�c��]tRt^�tRtR#)�DecompressionErrorr5Nr�r5r6r7r�r��r�r6r�c�p�\P!4pV^8Xd"V!V/VB\P!^4R#\
PRV\P!V44R# \d@\	\
R\P!T44\P!^4R#i;i)rz&Failed forking and calling callback %sz(Forked child %s who will run callback %sN)	r1�fork�_exit�	Exceptionr%rTr"�obj_namer�)�child_cb�args�kwargs�fids&*, r7�fork_cbr��s���
�'�'�)�C�
�a�x�		��d�%�f�%��H�H�Q�K�	�	�	�6������)�	
���	���8��#�#�H�-�
�

�H�H�Q�K�
	�s�A+�+AB5�4B5c���\V\4'dVRJ#\pV'd\V4V,p\	V4P4P
4V9dR#R#r�)rl�bool�TRUE_STRINGS�listre�lowerr>�r]�addons�	check_sets&& r7�is_truer�sQ���#�����d�{���I�
���O�f�,�	�
�3�x�~�~�����9�,��r6c���\V\4'dVRJ#\pV'd\V4V,p\	V4P4P
4V9dR#R#)FT)rlr��
FALSE_STRINGSr�rer�r>r�s&& r7�is_falser�sQ���#�����e�|���I�
���O�f�,�	�
�3�x�~�~�����9�,��r6c�\�V'gR#\V\4'dV#\W4#r�)rlr�r�)r]r�s&&r7�translate_boolr�s'�����#�����
��3��r6c��\P!4pV'g&\P\P,pRP\
V4Uu.uFq2PV4NK	up4#uupi��)�random�SystemRandom�string�
ascii_letters�digitsrV�range�choice)�strlen�select_from�r�_xs&&  r7�rand_strr�(sS������A���*�*�V�]�]�:��
�7�7�E�&�M�B�M�b�H�H�[�)�M�B�C�C��Bs�A;c�b�V'gRp\^R7R,V,pW 9gK#V#)r�)r�r))r�)�
dictionary�postfix�newkeys&& r7�
rand_dict_keyr�/s/�����
���#�c�)�G�3���#���Mr6�instance_data_filec�$�V^8�dQhR\/#�r-rc)r)rgs"r7rhrh9s��..�..�D�..r6c	���^RIHpHpHpHp\V4pT'dH\PPT4'd#T!TTT4p\PRTT4\T/R7# \d/u#i;i Td"p\PRTT4Rp?LCRp?iTdLOTd,p\PRTT\T44Rp?L{Rp?ii;i)z>Read a yaml config with optional template, and convert to dict)�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�FileNotFoundErrorr1r��existsrTr�rU�repr�	load_yaml)r\r�r�r�r�r��config_filer�s&$      r7�	read_confr�9s������$�U�+���b�g�g�n�n�-?�@�@�	�8���"��K�

�I�I�1�"��	
�0�[�"�-�-��E���	��� +�	��K�K�F���
�
��
�	�
��	��K�K� �"���Q��
�
��	�sG�A5�!B�5
B�B�C(�B+�+C(�4C(�7C(�<C(�=!C#�#C(c�&�\\V!4#�N)�sorted�
uniq_merge)�listss*r7�uniq_merge_sortedr�ms���*�e�$�%�%r6c��.pVFcp\V\4'd:VP4PR4pVUu.uFq3'gKVNK	ppVP	V4Ke	\V4#uupi)rJ)rlrer>r4�extend�	uniq_list)r��
combined_list�a_list�as*   r7r�r�ysl���M����f�c�"�"��\�\�^�)�)�#�.�F�!'�-��A�1�a�a��F�-����V�$���]�#�#��.s�	A7�A7c�
�\P4FwrVPW4pK	.pVF!pV\9gKVP	V4K#	VFpVPVR4pK	VP4pV#r�)�FN_REPLACEMENTS�items�replace�
FN_ALLOWED�appendr>)�fnr^rN�removalss&   r7�clean_filenamer
�st���%�%�'���
�Z�Z��
��(��H�
���J���O�O�A�����
�Z�Z��2�
���	����B�
�Ir6Tc	��\P!\V44;_uu_4p\P!RR^V4;_uu_4pV'd.\VP
44uuRRR4uuRRR4#VP
4uuRRR4uuRRR4# +'giM;iRRR4R# +'giR#;i \d*pT'dTuRp?#\\T44ThRp?ii;i)N�rb)
�io�BytesIOrs�gzip�GzipFilern�readr�r�re)rZ�quietrm�buf�ghr�s&&&   r7�decomp_gzipr�s���4�
�Z�Z��D�)�
*�
*�c�4�=�=��$��3�4
�4
�
��$�R�W�W�Y�/�	4
�4
�
*�
*��w�w�y�
4
�4
�
*�
*�4
�4
��
*�
*�
*�
*���4���K�$�S��V�,�!�3��	4�sp�'C�"C�!B%	�,
C�6
C�B%	�
C�
C�%B5
�0C�8C�C	�
C�C�D
�!	D�*D
�0D�D
c�Z�V'gR#VPR^4pV^,P4p\V4^8XdV^,P4pMRpV'dVR8XgVP4R8XdRpV'dVR8XgVP4R8XdRpW#3#)NrIz-1�none�NN)r4r>�lenr�)�ug_pair�	ug_parted�u�gs&   r7�extract_usergroupr�s�������
�
�c�1�%�I��!�����A�
�9�~����a�L��� ������T�	�Q�W�W�Y�&�0�����T�	�Q�W�W�Y�&�0���
�6�Mr6c�0�V^8�dQhR\R\/#)r-�root_dirrc)rerX)rgs"r7rhrh�s��	�	�3�	�4�	r6c��\4p\P!\PP	VR44F�p\PPV4'gK*\PP
V4^RpVP4pV'gKfVPR4R8XgK~W1V&K�	V#)z*.pyr+������)	rX�globr1r�rV�isfile�basenamer>�find)r �entriesr\�modnames&   r7�get_modules_from_dirr*�s����f�G����2�7�7�<�<��&�9�:���w�w�~�~�e�$�$���'�'�"�"�5�)�!�B�/���-�-�/���7�w�|�|�C�(�B�.�$�E�N�
;��Nr6c�2�R\P!49#)z�deprecated: 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�systemr5r6r7�is_Linuxr0�s���h�o�o�'�'�'r6c�v�R\P!49dR#\P!4R8XdR#R#)�BSDT�	DragonFlyFr-r5r6r7�is_BSDr4�s)������!�!������K�'��r6c�*�\4R,R8H#)�variant�freebsd��system_infor5r6r7�
is_FreeBSDr:�����=��#�y�0�0r6c�*�\4R,R8H#)r6�	dragonflyr8r5r6r7�is_DragonFlyBSDr>�s���=��#�{�2�2r6c�*�\4R,R8H#)r6�netbsdr8r5r6r7�	is_NetBSDrA�s���=��#�x�/�/r6c�*�\4R,R8H#)r6�openbsdr8r5r6r7�
is_OpenBSDrD�r;r6Fc�4�W9dV#\W,4#r�)r���yobj�keyr�s&&&r7�get_cfg_option_boolrI�s��
�����$�)�$�$r6c�h�W9dV#W,p\V\4'g\V4pV#r�)rlre)rGrHr�r]s&&& r7�get_cfg_option_strrK�s.��
����
�)�C��c�3����#�h���Jr6c�.�\\WVR74#)r�)r0rKrFs&&&r7�get_cfg_option_intrM�s���!�$�W�=�>�>r6c���V'gRp\PPV4'g/#\V4pRpRV9dRp\P
!W!4pV'd�VP
4pRVR,9d
VR,VR&VR,P4PR4^,VR&VR,R8XdR	VR&R
VR,RVR,R
VR,/#/#)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\.]+)�namerCz linuxzred hat enterprise�redhat�ID�
VERSION_IDr$�VERSION_CODENAME)	r1r�r�r��re�match�	groupdictr�rR)�release_file�redhat_release�redhat_regexrV�groups&    r7�_parse_redhat_releaser\�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�
�	
�
�Ir6c���RpRpRp/pRp\PPR4'd?\\	R44p\PPR4'dRVR&V'g
Rp\4pV'd�VP
RR4pVP
RR4pRV9gR	V9d\P!4pM�VR
8XgVR8XdVP
RR4pM�VR
8XdV'gVP
RR4pM`VP
RR4pV'gG\P!RVP
RR44pV'dVP4R,pVR8XdRpM`\4'd:\P!4P4p\P!4pM\ P#R4R#WV3#)r�F�/etc/os-releasez/etc/rpi-issue�raspberry-pi-osrRTrS�sles�suse�alpine�photon�PRETTY_NAME�	virtuozzorTz[^ ]+ \((?P<codename>[^)]+)\)�VERSIONrC�rhelrQzPUnable to determine distribution, template expansion may have unexpected results)r�r�r�)r1r�r��load_shell_contentr�r\�getr.�machinerUrVrWr4r/r�r3rTrU)�distro_name�distro_version�flavor�
os_release�os_release_rhelrVs      r7�get_linux_distrorp s����K��N�
�F��J��O�	�w�w�~�~�'�(�(�'��7H�(I�J�
�
�7�7�>�>�*�+�+�0�J�t�����*�,�
�� �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�'�-�-�/��!�)�)�+�����
4�	
�����0�0r6c��VR,P4pRpVR8XdPVR,^,P4pVR9dTpV#VR	9dRpV#VR8XdRpV#VR
9dRpV#RpV#VR9dTpV#)r/�unknown�linux�distrgra�ubunturQ)�	almalinuxrb�aosc�arch�
azurelinux�centos�
cloudlinux�debian�	eurolinux�fedora�mariner�miraclelinux�	openeuler�opencloudos�openmandrivarcr_rg�rockyra�	tencentosre)ru�	linuxmint�mint)�opensusez
opensuse-leapzopensuse-microoszopensuse-tumbleweed�sle_hpcz	sle-micror`)�windows�darwinr7r@rCr=)r�)�infor/r6�
linux_dists&   r7�_get_variantr�Ts���
�(�^�
!�
!�
#�F��G�
����&�\�!�_�*�*�,�
��
�
�0!�G�6�N�5�:�
:��G�2�N�1�8�
#��G�.�N�-�
�
��G��N��G��N�
��
����Nr6c
��R\P!4R\P!4R\P!4R\P!4R\	\P
!44R\
4/p\V4VR&V#)r.r/r3�pythonr2rtr6)r.r/r3�python_versionr�r2rpr�)r�s r7r9r9�sp��	�H�%�%�'��(�/�/�#��8�#�#�%��(�)�)�+���h�n�n�&�'�� �"�
�D�#�4�(�D��O��Kr6c���W9dV#W,f.#W,p\V\4'dVUu.uFqDNK	ppV#\V\4'g\V4pV.#uupi)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�re)rGrHr�r]rN�cvals&&&   r7�get_cfg_option_listr��sj�������y���	�
�)�C��#������3�a��3������c�3����#�h���5�L��	 s�
A)c��\V\4'dVPR4pTpVFpWC9dVu#W4,pK	V#)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.�/)rlrer4)rG�keypr��cur�toks&&&  r7�get_cfg_by_pathr��sE���$�����z�z�#���
�C����>��N��h����Jr6c�8�\W4wr#\W#4W#3#r�)�get_output_cfg�redirect_output)�cfg�mode�outfmt�errfmts&&  r7�fixup_outputr��s ��%�c�0��V��F�#���r6c��\\PPR44'd\PR4R#V'g\PpV'g\PpRpV'EdC\PRW 4VPR^4wrVVR8XgVR8XdRpVR8XdR	p\Wg4pMgVR
8XdO\P!VR\PVR7p	\\\ ,V	P"4pM\%R
V,4hV'd4\P&!VP)4VP)44W8XdL\PRW04\P&!VP)4VP)44R#V'd�\PRW14VPR^4wrVVR8XgVR8XdRpVR8XdR	p\Wg4pMgVR
8XdO\P!VR\PVR7p	\\\ ,V	P"4pM\%RV,4hV'd6\P&!VP)4VP)44R#R#R#)�_CLOUD_INIT_SAVE_STDOUTz5Not redirecting output due to _CLOUD_INIT_SAVE_STDOUTNc���\P!^4\P!R4Pp\P
!V4R# \dR#i;i)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)r1�umask�grp�getgrnam�gr_gid�setgid�KeyError)�group_ids r7�set_subprocess_umask_and_gid�5redirect_output.<locals>.set_subprocess_umask_and_gid�sJ��	�����	 ��|�|�E�*�1�1�H�

�I�I�h���	�	��	�s� A�A�AzRedirecting %s to %s� �>�>>�ab�wb�|T)�shell�stdin�
preexec_fnz"Invalid type for output format: %sz!Invalid type for error format: %s)r�r1�environrirTr��sysr=�stderrr4�open�
subprocess�Popen�PIPErrr
r�rw�dup2�fileno)
r�r��o_out�o_errr�r��arg�owith�new_fp�procs
&&&&      r7r�r��s����r�z�z�~�~�7�8�9�9��	�	�I�J����
�
����
�
�� �&�v��	�	�(�%�8��l�l�3��*����3�;�$�$�,��E��s�{����#�%�F�
�S�[��#�#��� �o�o�7�	�D��"�S�'�4�:�:�.�F��@�6�I�J�J���G�G�F�M�M�O�U�\�\�^�4����I�I�,�e�<��G�G�F�M�M�O�U�\�\�^�4��
��	�	�(�%�8��l�l�3��*����3�;�$�$�,��E��s�{����#�%�F�
�S�[��#�#��� �o�o�7�	�D��"�S�'�4�:�:�.�F��?�&�H�I�I���G�G�F�M�M�O�U�\�\�^�4��+r6c�F�V^8�dQhR\\,R\/#)r-�sourcesrc)rrrX)rgs"r7rhrh7s��5�5�8�G�,�5��5r6c��V'd\\V44p/pVFgpV'gK
\P!V4pV'g\P!4p\P
!V4pVP
W#4pKi	V#)a�Merge 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&&    r7�
mergemanydictr�7su��T��x��(�)���J����3�&�;�;�C�@��#�#*�#:�#:�#<� ��&�&�'7�8�F����j�6�J���r6c#��"�\P!4p\P!V4Vx�\P!V4R# \P!T4i;i5ir�)r1�getcwd�chdir)�ndir�currs& r7r�r�os;���
�9�9�;�D��
������
�
�����������s�A&�A�A&�A#�#A&c#�"�\P!V4pVx�\P!V4R# \P!T4i;i5ir�)r1r�)�n_msk�olds& r7r�r�ys2���
�(�(�5�/�C���	�
����
������
�s�A�6�A�A�Ac�*�RPWRVR7#)z{0:{fill}{align}{size}}�^)�fill�align�size)rg)rpr��max_lens&&&r7�centerr��s!��$�+�+��s��,��r6c��\PRV4\P!V4R# \dR#i;i)z�
Deletes a directory and all its contents by calling shutil.rmtree
Will ignore FileNotFoundError

@param path: The path of the directory.
"""
zRecursively deleting %sN)rTr��shutil�rmtreer��r�s&r7�del_dirr��s6���I�I�'��.�
��
�
�d����
��
���0�?�?c���\WVR7wrErgWPR&W`R&W@R&WpR&R# \Pd,pTP\P8XdRp?R#hRp?ii;i)	z�
returns boolean indicating success or failure (presence of files)
if files are present, populates 'fill' dictionary with 'user-data' and
'meta-data' entries
)�base�ext�timeout�	user-data�vendor-data�	meta-data�network-configTNF)�read_seededr#�UrlError�code�	NOT_FOUND)	r�r�r�r��md�ud�vd�networkr�s	&&&&     r7�read_optional_seedr��sj��
�)�t�g�N�����[�� �]���[��!(�
���������6�6�Z�)�)�)��
���s� $�A$�A�A�A$c��/pV'gRR.pM^\PPVPR4R4\PPVP	R4R4.p\V4pVUu.uF5q3'gK\PP
V4'gK3VNK7	ppRpVFhp\PP\PPVR44'gKH\PPVR4pM	RpVFhp\PP\PPVR44'gKH\PPVR4pM	V'dV'dWAR&WQR&V#V'dWAR&V#uupi)	z/var/lib/cloud/data/sslz /var/lib/cloud/instance/data/sslrZ�sslNzcert.pemzkey.pem�	cert_file�key_file)r1r�rV�
get_ipath_cur�	get_cpathr��isdirr%)�paths�ssl_details�ssl_cert_paths�dr�r�s&     r7�fetch_ssl_detailsr�sW���K��%�.�
��
�G�G�L�L��,�,�V�4�e�<��G�G�L�L�����0�%�8�
�� ��/�N�!/�J��A�1�a������q�9I�a�a��N�J��I�
��
�7�7�>�>�"�'�'�,�,�q�*�5�6�6������Q�
�3�I����H�
��
�7�7�>�>�"�'�'�,�,�q�)�4�5�5��w�w�|�|�A�y�1�H����X�#,�K� �"*�J����
�#,�K� ����!Ks�=	G�"G�2Gc�J�Tp\V4p\PR\V4V4\P
!V4pVf\PR4TpM9\
WB4'g)\RV:R\P!V4:R24hTpV# \P\\3d�pRpRp\TR4'd \TR4'd\TR4pM0\TR4'd\TR4'd
\TR4pT'd?TR	PTP^,TP ^,TR
7,
pMTRPTR7,
p\P#T4Rp?T#Rp?ii;i)
zKAttempting to load yaml from string of length %s with allowed root types %sNz-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[�colr`z. {err})r`)rnrTr�r�yaml�	safe_loadrlrwr"r��	YAMLError�
ValueError�hasattr�getattrrgr[�columnrU)rbr��allowed�loaded�	convertedr��msg�marks&&&     r7r�r��sk��
�F����D�!��	�	�
6���I��		
��N�N�4�(�	����I�I�E�F��I��I�/�/���J�/�/�	�:�<��
���"�M��!
�N�N�I�z�2��(�����1�n�%�%�'�!�^�*D�*D��1�n�-�D�
�Q��
'�
'�G�A�~�,F�,F��1�n�-�D���G�N�N����Q��D�K�K�!�O��O��
�C�
�9�#�#��#�*�*�C����C����M��!�s �B
B� F"�>A,F�+A,F�F"c��VPR4^8�dfVPRRV,4pVPRRV,4pVPRRV,4pVPRRV,4pM~\P'd=VR
,R8wd/\P
!V4PR8Xd
VR,
pV:R:V:2pV:R:V:2pV:R:V:2pV:R:V:2pRp\P!WrVR7p	V	P4'd\V	P4p\P!YbTR7pRpTP4'd\TP/R
7p\P!YBTR7p
RpT
P4'd
T
PpRp\P!YRTR7pTP4'dTPpM\PR4Y�Y�3# \Pd"p
\PR	T
4Rp
?
ELRp
?
ii;i \Pd!p
\PRT
4Rp
?
LmRp
?
ii;i)z%sr�r�r�r�r�r�N)r��retrieszNo network config provided: %sr�zError in vendor-data responsez!Error in vendor-data response: %sr#)r'rr�%NOCLOUD_SEED_URL_APPEND_FORWARD_SLASHr�urlparse�queryr#�read_file_or_url�okr��contentsr�rTr�)r�r�r�r�ud_url�vd_url�md_url�network_urlr��network_respr��md_respr��ud_respr�r��vd_resps&&&&             r7r�r��s���y�y���!�����d�K�#�$5�6�����d�M�C�$7�8�����d�K�#�$5�6���l�l�4�)9�C�)?�@���9�9�9��B�x�3��5�>�>�$�#7�#=�#=��#C�����!�;��4��!�=�#�6��!�;��4��"&�(8�#�>���G�7�!�2�2��'�
���?�?����� 5� 5�6�G��)�)����G�
�B��z�z�|�|�
�w�'�'��
4���)�)����G�
�B��z�z�|�|�
�
�
��	
�B�
7��-�-��W�
���:�:�<�<��!�!�B��I�I�5�6�
�2����A���7��	�	�2�A�6�6��7��0���:��	�	�5�q�9�9��:�s0�=H�I�I�0I�I�J	�)J�J	c�$�V^8�dQhR\/#r��rX)rgs"r7rhrh*s����d�r6c	��\\P!V4RR7pVUu.uFq3PR4'gKVNK	ppVUu.uFIp\PP\PP
W44'gKGVNKK	pp.pVF?p\PP
W4pVP\VVR74KA	\V4#uupiuupi \d\PRT4K|\d"p\PRYg4Rp?K�Rp?ii;i)zRead configuration directory.T�r�z.cfg�r��1REDACTED config part %s, insufficient permissions�Error accessing file %s: [%s]N)r�r1�listdir�endswithr�r%rVrr��PermissionErrorrTrUr�r�)�confdr��confs�f�cfgsrr�r�s&$      r7�read_conf_dr6*s
��
�2�:�:�e�$�d�3�E��4��1���F�!3�Q�Q��E�4��H��1�����������U�0F�!G�Q�Q��E�H��D����w�w�|�|�E�&��	B��K�K���'9��
�� �����/
5��
I���	��K�K�C�T�
��	B��K�K�7��A�A��	B�s<�C2�C2�AC7�C7�C<�<!E� E�)E�*E�Ec�$�V^8�dQhR\/#r�r))rgs"r7rhrhJs��,�,��,r6c���\4p/p\WR7pVPV4RpRV9diVR,pV'dW\V\4'g(\RV:R\P!V4:24h\V4P4pM-\PPVR	24'dVR	2pV'dC\PPV4'd\!WQR7pVP#V4\%V4# \d\PRT4EL\d"p\PRY4Rp?EL=Rp?ii;i)
a�Read 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�rr1rTrUr�rlrerwr"r�r>r1r�rr6�
appendleftr�)�cfgfiler�r5r�r�r2�	confd_cfgs&$     r7�read_conf_with_confdr=Js$����D��C�	���G��	
���C���E��3���H�
����e�S�)�)���
� 3� 3�E� :�<���
�E�
�(�(�*���	�����'��"�~�	&�	&��)�2���������u�%�%���M�	����	�"������9�
����?��	
��A����3�W�@�@��A�s#�D�!E-�E-�E-�E(�(E-c�,�\\VR74#)��cmdline)r��read_cc_from_cmdliner?s&r7�read_conf_from_cmdlinerBys���)�'�:�;�;r6c���Vf\4pRV2pRpRp\V4p\V4p\V4p.pVPV4pV^8�d�VPW'V,4pV^8dTpVP\P
!WV,VP
44PRR44VPWV,4pK�RPV4#)Nr�z cc:�end_ccz\n�
)	�get_cmdlinerr'rr�unquote�lstriprrV)	r@�	tag_begin�tag_end�begin_l�end_l�clen�tokens�begin�ends	&        r7rArA~s������-���'��m�G��I��G��)�n�G���L�E��w�<�D�
�F��L�L��#�E�
�1�*��l�l�7�G�O�4����7��C��
�
��M�M�'�'�/�C�8�?�?�A�B�J�J��t�
�	
�
���Y�e��4���9�9�V��r6c��VPR4pV^8:gW^,
,R8wdV#VPRR4#)rE�
z
)r'r)r�poss& r7�dos2unixrT�s=��
�-�-��
�C�
�a�x�8�!�G�$��,������F�D�)�)r6c�,a�]tRtRtoV3RltRtVtR#)�HostnameFqdnInfoi�c�><�V^8�dQh/S[;R&S[;R&S[;R&#)r-�hostname�fqdn�
is_default�rer�)rgr�s"�r7rh�HostnameFqdnInfo.__annotate__�s&�����M��

�I����r6r5N)r�r�r�r��__annotate_func__r�r�r�s@r7rVrV�s����r6rVc��RpRV9d7\VR,4p\VRVPR4^,4pM�RV9dCVR,PR4^8�d&VR,pVR,RVPR4pMBVP	RVR7P
pRV9dVR,pMVP	VR7wrS\
WTV4#)	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.
FrYrXr+NT)rY�
metadata_only)r_)rerKr4r'�get_hostnamerXrV)r��cloudr_rZrYrXs&&&   r7�get_hostname_fqdnrb�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�J�7�7r6c�V�Rp\V4P4FupVPR4pV^8�dV^VpVP4pV'gK:VP	4p\V4^8dK\WR,9gKkV^,pV#	V# \dT#i;i)ax
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-NN)r�rQr'r>r4r�IOError)rX�filenamerYr[�hashpos�tokss&&    r7�get_fqdn_from_hostsrj�s����D�
�"�8�,�7�7�9�D��i�i��n�G��!�|��A�g����:�:�<�D���
�:�:�<�D��4�y�1�}����8�#��A�w����K�):�(�K���
���K�
�s$�AB�.B�
B�B�B(�'B(z
Resolving URLc�$�V^8�dQhR\/#r��r�)rgs"r7rhrhs��2�2�$�2r6c	���\P!V4pVPp\\4;_uu_4\
P!VPPR44'dRRR4R#RRR4\f�\4pRp/pVF�p\P!VR^^\P\P4p.WV&VFDwr�r�pWV,PV:RV^,:24VP!V^,4KF	K�	Vs	V'd\&P)RV4\P!VR4pV^,^,^,p
V
\9# +'giEL;i \P"\P$3dEK"i;i \P"\P$3dR#i;i)a�determine if a url's network address is resolvable, return a boolean
This also attempts to be resilient 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.
z[]NTz: zdetected dns redirection: %sF)zdoes-not-exist.example.com.zexample.invalid.�!__cloud_init_expected_not_found__)rrrXrrr�
is_ip_address�netlocr>�_DNS_REDIRECT_IP�set�socket�getaddrinfo�SOCK_STREAM�AI_CANONNAMEr�add�gaierror�errorrTr�)�url�
parsed_urlrP�badips�badnames�
badresults�iname�result�_fam�_stype�_proto�cname�sockaddr�addrs&             r7�
is_resolvabler�s�������$�J����D�
�*�	�	����Z�.�.�4�4�T�:�;�;��
�	�;�
������
��
�
��E�	
��+�+��4��A�v�'9�'9�6�;N�;N���%'�
�!�=C�9�D�&���%�,�,�����-L�M��J�J�x��{�+�>D�
�"����I�I�4�j�A���#�#�D�$�/���a�y��|�A����+�+�+�?
�	�	��*�O�O�V�\�\�2�
��
��
�O�O�V�\�\�*����s0�7F� BF�
6G�F	�%F?�>F?�%G+�*G+c�0�\P!4pV#r�)rs�gethostname)rXs r7r`r`8s���!�!�#�H��Or6c�v�\P!V4^,# \PdR#i;i)rN)rs�
gethostbyaddr�herror)�ips&r7r�r�=s3����#�#�B�'��*�*���=�=����s��8�8c��\V4#)z5determine if this url is resolvable (existing or ip).)r�)rzs&r7�is_resolvable_urlr�Ds
�����r6c���VfR#\PRV4VF/p\V4'd\PRV4Vu#K1	R# \dKCi;i)zW
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')rTr�r�r�)�
candidates�cands& r7�search_for_mirrorr�Ish��
����I�I�5�z�B���	� ��&�&��	�	�6��=���'�����	��	�s�(A�A#�"A#c���.pV'g2\P!R4\P!R4,#VPR4'd\VPR4pRV,RV,3Uu.uF,p\PPV4'gK*VNK.	ppV#VR8Xd\P!R4pV#VR8Xd\P!R4pV#uupi)z/dev/msdosfs/*z/dev/iso9660/*�LABEL=z
/dev/msdosfs/z
/dev/iso9660/�	TYPE=vfat�TYPE=iso9660)r$�
startswithrHr1r�r�)�criteria�oformat�tag�no_cacher��devlist�label�ps&&&&&   r7�find_devs_with_freebsdr�\s����G���y�y�)�*�T�Y�Y�7G�-H�H�H����8�$�$�����)��&��-���/F�G�
�G���w�w�~�~�a� �
�A�G�	�
��N�	
�[�	 ��)�)�,�-���N�
�^�	#��)�)�,�-���N��
s�8'C,�$C,c�:�.pRpRpRpV'dQVPR4'dVPR4pVPR4'dVPR4p\P!.RO^.R7p	V	PP	4F�p
V'g	V'd\P!RV
.^^.R7wr�V'dRV,V9dKIVR8Xd
RV9dKYVR	8Xd
RV9dKiVPR
V
,4K�	V#)Nr�r�zTYPE=��rcs�	mscdlabelz
label "%s"�iso9660zISO filesystem�vfat�/dev/��sysctl�-nzhw.disknames)r�rHr r=r4r)r�r�r�r�r�r�r��_type�
mscdlabel_outr?�devr)s&&&&&       r7�find_devs_with_netbsdr�ps����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��l�U�*�=�@���I��"2�-�"G���F�?�/�=�@�����w��}�%�"��Nr6c��\P!.R
O^.R7p.pVPP4PR4FtpVP	R4'gKVR8XdK%VPVRRR,4VP
R4'dKYVPVRRR,4Kv	VUu.uFpR	V,NK	up#uupi)r�r�rJrIzfd0:Nr�cd�ir�r�r#)r r=�rstripr4r0rr�)	r�r�r�r�r�r?r��entryr�s	&&&&&    r7�find_devs_with_openbsdr��s����)�)�4�1�#�
>�C��G����"�"�$�*�*�3�/���~�~�c�"�"���F�?�����u�S�b�z�C�'�(�����%�%��N�N�5��"�:��+�,�0�")�)��A�G�a�K�K��)�)��)s�Cc�^�\P!.R	O^.R7p\VPP4RR7Uu.uF7pVP	R4'dKVP	R4'dK5VNK9	ppVR8Xd+VUu.uFqfP	R
4'gKVNK	ppMOVR9d+VUu.uFqfP	R
4'dKVNK	ppMV'd\
P
RV4VUu.uFpRV,NK	up#uupiuupiuupiuupi)r�r�Tr+r��vnr�zUnexpected criteria: %sr�)r�r�z
kern.disks)r��acd)zLABEL=CONFIG-2r�)r r�r=r4r�rTr�)r�r�r�r�r�r?r�r�s&&&&&   r7�find_devs_with_dragonflybsdr��s���)�)�2���
<�C���
�
�(�(�*�D�9��9�A��|�|�D�!�	
�*+�,�,�t�*<�	
��9����>�!�%�E�g����m�)D�1�1�g��E��	�4�	4�%�K�g��l�l�=�.I�1�1�g��K��	��	�	�+�X�6�!(�)��A�G�a�K�K��)�)����F��K��*s0�D�!D�:D�
D �*D �>D%�D%�D*c�f�\4'd\WW#V4#\4'd\WW#V4#\	4'd\WW#V4#\
4'd\WW#V4#R.p.pV'dVPRV,4V'dVPRV,4V'dVPRR.4V'dVPRV,4V'dVPV4WV,p\P!V^^.R7wr�.pTP4F.pTP4pT'gKTPT4K0	T# \Pd#p
T
P\8XdRpR	p
?
LwhR	p
?
ii;i)
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%sr�r�N)r:r�rAr�rDr�r>r�rr�r rW�errnorrQr>)
r�r�r�r�r��
blk_id_cmd�options�cmdr?�_errr�r(r[s
&&&&&        r7�find_devs_withr��s_���|�|�%�h���M�M�	���$�X��t�L�L�	���%�h���M�M�	�	�	�*��s�d�
�	
���J��G��	���v��*�+�
����v��~�&��	����k�*�+��	���v��)�*�����t��
�
�C���i�i��!�Q��0����G���� ���z�z�|���4��N�N�4� �!��N���%�%���7�7�f���C����s�E9�9F0�F+�*F+�+F0c�Z�Vf.pM\V4p.ROpV'dVPRR.4VPV4\P!VRRR7p/pVPP	4F/pVPR4wrgp\
V4WF&WdV,R&K1	V#)	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�r�Tr)r<rmrI�DEVNAME)r��-o�full)r�r�r r=rQrRrh)	�devs�
disable_cacher�r?�retr[r�r)rZs	&&       r7r�r��s����|����D�z��
!�C���
�
�D�+�&�'��J�J�t��
�)�)�C��i�
8�C�
�C��
�
�%�%�'���~�~�c�*����%�d�+���!�C����(�
�Jr6c�N�.pVFpW!9dKVPV4K	V#r�)r)�in_list�out_listr�s&  r7r�r�
s,���H�
���=���O�O�A��	�
�Or6�read_cbrc��V^8�dQhR\\\P3,R\\
\.R3,,R\R\/#�r-r\r�Nrrc)	rrer1�PathLikerrr0r�rf)rgs"r7rhrhsP������b�k�k�!�"���h��u�d�{�+�
,���	�
�r6c�D�\P!RRR7p\PRW4T;_uu_4\P
!4;_uu_4p\
VR4;_uu_4p\WTVR7RRR4TP4pRRR4RRR4\PR\X4YP4T# +'giL\;i \d
T'ghLui;i +'giLq;i +'giL|;i)r��skip)�log_modezReading from %s (quiet=%s)r)�chunk_cbNzReading %s bytes from %s%s)r�TimedrTr�r
rr��pipe_in_outr��getvaluer�output)r\r�r�timer�ofh�ifhrs&$$    r7�load_binary_filer�s���
���b�6�2�E��I�I�*�E�9�	��
�Z�Z�\�\�S�
��%��&�&�#���7�;�'�
�|�|�~�H��
��I�I�*�C��M�5�,�,�O��O�'�&��$�
����
��	�\��
��sq�D�C<	�C"�-C
�;C"�C<	�D�C�C"�C<	�C"�"C9�5C9�6C<	�8C9�9C<	�<D
�D�D	c��V^8�dQhR\\\P3,R\\
\.R3,,R\R\/#r�)rrer1r�rrr0r�)rgs"r7rhrh,sV��P�P���b�k�k�!�"�P��h��u�d�{�+�
,�P��	P�
	�Pr6c�.�\\WVR74#))r�r)rnr�)r\r�rs&$$r7r�r�,s���)�%��N�O�Or6c�*�\4'd$\R4pVPRR4RRpV#\R4P
4pV# \d$p\PRT4RpRp?T#Rp?ii;i \dRpT#i;i)z/proc/1/cmdline�r�Nz"failed reading /proc/1/cmdline: %sr�z
/proc/cmdliner#)�is_containerr�rr�rTrUr>)rr@r�s   r7�_get_cmdliner�5s����~�~�	�%�&7�8�H��&�&�v�s�3�C�R�8�G��N�	�$�_�5�;�;�=�G��N���	��K�K�<�a�@��G��N��	���	��G��N�	�s(� A�B�A>�A9�9A>�
B�Bc�n�R\P9d\PR,#\4#)�DEBUG_PROC_CMDLINE)r1r�r�r5r6r7rFrFHs&���r�z�z�)��z�z�.�/�/��>�r6c�$�V^8�dQhR\/#r�rl)rgs"r7rhrhOs��	�	�d�	r6c�t�Rp\V4P4pVR8H# \\3dR#i;i)z/proc/sys/crypto/fips_enabled�1F)r�r>rfr�)�	fips_procrs  r7�fips_enabledr�OsB��/�I��!�)�,�2�2�4���3�����W����	�s�"�7�7c���^pVPV4p\V4^8XdM7VPV4V\V4,
pV'gKPV!V4KZVP4V#�r)rr�write�flush)�in_fh�out_fh�
chunk_sizer��bytes_pipedrZs&&&&  r7r�r�[s\���K�
��z�z�*�%���t�9��>�����T���s�4�y� ���8��[�!�
�L�L�N��r6c��VR9d
VR9dR#\PRWV4\P!WV4R#)Nz%Changing the ownership of %s to %s:%s)Nr#)rTr�r1�chown)r\�uid�gids&&&r7�	chownbyidr�js3��
�j��S�J�.���I�I�5�u�3�G��H�H�U��r6c��RpRpV'd!\P!V4PpV'd!\P!V4P
p\YT4R# \dp\RT,4ThRp?ii;i)�zUnknown user or group: %sNr#)	�pwd�getpwnam�pw_uidr�r�r�r�r�r�)r\�userr[r�r�r�s&&&   r7�chownbynamer�rss��
�C�
�C�@���,�,�t�$�+�+�C���,�,�u�%�,�,�C��e�#����@��1�Q�7�8�a�?��@�s�/A$� A$�$B�/B�Bc��V^8�dQhR\\\3,R\\,R\\\,,/#)r-r�r�rc)rrer
rr)rgs"r7rhrhs>��_�_�	
�c�3�h��_�'��}�_�	�(�3�-��_r6c�:�RR.pV'dRV9dV#VR,pW9d
W1,pMRV9dV#VR,p\V\4'dWD.p\V\4'd9\V4^8�d
V^,V^&\V4^8�d
V^,V^&\V\4'd'RV9d
VR,V^&RV9d
VR,V^&V^,R8Xd
V^,V^&.R
Op\V4F�wrgV'gKVP
4pRp	VFAp
VPV
4'gKV
:RV\V
4RP4:2pR	p	M	V	'gR:RVP4:2pW�V&K�	V#)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��allryz&1r�Fr�T)r�r�r�)	rlrer�rrX�	enumeraterHr�r>)r�r�r��outcfg�modecfg�swlistr�r�r]�found�ss&&         r7r�r�s���N!%�d�|�C��(�#�%��
�
��]�F��~��,������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��#�������h�h�j�����A��~�~�a� � �!"�C��A���M�$7�$7�$9�:�����	�
�!�3�9�9�;�/�C��A����Jr6c�F�V^8�dQhR\\\3,/#)r-r�)rrer
)rgs"r7rhrh�s��+*�+*�T�#�s�(�^�+*r6c��.p.pV'd\V\4'gV#VPR4pV'dVPV4\	VR4F�pV'gK
\
P!RV4pV'gK.VPR4pVP4p\V4^8XdVPV4KrRR.VR,8XgK�VPV^,4K�	VFcp\P!VR24FCp	\PPV	4'gK*W�8wgK2VPV	4KE	Ke	\\W,44#)	aReturn 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>.*)�target�teez-ar,�*)rlrXrirr�rUrVr[r4rr$r1r�r%r�rr)
r��logs�rotated_logs�default_log�fmtrVr
�parts�logfile�rotated_logfiles
&         r7�get_config_logfilesr�s���D��L��j��d�+�+����'�'�.�)�K�����K� ��c�4�(�������<�c�B�������X�&��������u�:��?��K�K����T�]�e�B�i�
'��K�K��a��!�)���#�y�y�G�9�A��7�O��w�w�~�~�o�.�.�?�3M��#�#�O�4�	 8����D�'�(�)�)r6c�0�V^8�dQhR\R\/#)r-�routinerc�re)rgs"r7rhrhs����S���r6c��\P!V4pVP\V44VP	4pVeV^V#V#r�)�hashlib�new�updaters�	hexdigest)rbr�mlen�hasher�digests&&&  r7�	hash_blobr sF��
�[�[��
!�F�
�M�M�+�d�#�$�
�
�
�
�F����a��~���
r6c�h�\P!V4'dR#R# \dR#i;i�TFN)r�r�r��rPs&r7�is_userr$�0����<�<�������������"�1�1c�h�\P!V4'dR#R# \dR#i;ir")r�r�r�r#s&r7�is_groupr("r%r&c�^�\PRW4\P!W4R#)zRenaming %s to %sN)rTr�r1�rename��src�dests&&r7r*r**s���I�I�!�3�-��I�I�c�r6c�.�VFp\W!4K	R#r�)�
ensure_dir)�dirlistr�rs&& r7�ensure_dirsr10s��
���1��r6zLoading jsonc��\P!\V44p\V\	V44'gHRPVUu.uFp\
V4NK	up4p\RV:R\V4:R24hV#uupi)�, �(z) root types expected, got r)	�json�loadsrnrlr.rVrerwrx)rp�
root_types�decoded�t�expected_typess&&   r7�	load_jsonr;5sp���j�j��t�,�-�G��g�u�Z�0�1�1����J�#?�J�q�C��F�J�#?�@����t�G�}�
.�
�	
��N��$@s�
Bc���\PPV4pV\PPV48XdV#\PPV4'dV#\	V4#)z�Get the last directory in a path that does not exist.

Example: when path=/usr/a/b and /usr/a does not exist but /usr does,
return /usr/a
)r1r��dirnamer�get_non_exist_parent_dir)r��p_paths& r7r>r>AsS���W�W�_�_�T�
"�F�
�������(�(���
�7�7�=�=�� � ��K�+�F�3�3r6c�x�\PPV4'g�\V4p\PP	V4pRpVR8XdRp\WVR7;_uu_4\P!V4RRR4\W4V'g	V'dr\WBV4\VPV4^,R,4p\V4pVPF p	VPV	4p\W�V4K"	R#R#\W4R# +'giL�;i)Tr�Fr�N:r�NN)
r1r�rr>r=r��makedirs�chmodr�r	r4r�joinpath)
r�r�r�r[�non_existed_parent_dir�dir_name�selinux_recursive�sub_relative_dir�sub_pathr�s
&&&&      r7r/r/Rs���
�7�7�=�=����!9�$�!?���7�7�?�?�4�(�� ���s�?� %��
�(�
@�
@��K�K���A�
�d���5��.�e�<� $�D�J�J�/E�$F�q�$I�"�$M�N���2�3�H�(�.�.��#�,�,�T�2���H�E�2�/�
�	�d��A�
@�s�/D)�)D9	c#�"�Vx�V'dRV.p\P!V4R#R# T'dRT.p\P!T4ii;i5i)�umountN)r )rJ�
umount_cmds& r7�	unmounterrLmsK���"����"�F�+�J��I�I�j�!���6�"�F�+�J��I�I�j�!��s�A�.�&A�%A�Ac�6�/p\PPR4'd\R4P	4pRpM2\
P
!R4pVPP	4pRp\P!R4pVF�pVR8Xd*VP4p\V4^8wdK,Vwrxr�r�MyVPV4p
V
e\V
P44^8dKhV
P^4pV
P^4pV
P^4p	V
P^4p
VPRR4pRV	RVRV
/W&K�	\P!R	W4V# \"\$3d\'\R
4T#i;i)z/proc/mountsr��mountz*^(/dev/[\S]+) on (/.*) \((.+), .+, (.+)\)$z\040r��fstype�
mountpoint�optszFetched %s mounts from %szFailed fetching mount points)r1r�r�r�rQr r=rU�compiler4r�search�groupsr[rrTr�rfr�r%)�mounted�
mount_locs�methodr?�mountre�mpline�wordsr��mprOrQ�_freq�_passno�ms              r7�mountsr_wsi���G�$4�
�7�7�>�>�.�)�)�'��7�B�B�D�J��F��)�)�G�$�C����.�.�0�J��F��*�*�J�K�� �F����������u�:��?��:?�7��&��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��&��b����G�L�'!�0	�	�	�-�w�?��N��
�W��4��s�2�3��N�4�s�$E3�EE3�3!F�Fc�t�\V\4'dV.pMS\V\\34'd
\V4pM+VfRpM$\	RP\
V4R74h\4'd	VfR.pML\4'd6Vf.ROp\V4FwrsVR8XdRWg&VR9gKRWg&K	MVfR.p\4p\P!4;_uu_4p	R	p
\PPV4V9d/V\PPV4,R
,pM�RpVFbpRp.ROp
V'dV
P!RV.4V
P#V4V
P#V	4\$P$!W�R7T	p
T	pM	X'g\1RV:RV	:RV:24hVP3R4'g
VR,
p\5V
4;_uu_4Vf
V!V4pMV!W�4pVuuRRR4uuRRR4# \&\(3d?pT'd)\*P-R
TTRP/X
4T4TpRp?EK.Rp?ii;i +'giM;iRRR4R# +'giR#;i)a
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�cd9660�msdosr�r�FrPz-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�)�ufsrbrc)r��msdosfs)rNr��ro)rlrer�r.rwrgrxr0r4rr_r!�tempdirr1r�r�r�rr rfr�rTr�rVr�r0rL)�device�callbackrZ�mtype�update_env_for_mount�	log_error�mtypes�indexrU�tmpdrJrP�failure_reason�mountcmd�excr�s&&&&&&          r7�mount_cbrt�sU��"�%�������	�E�D�%�=�	)�	)��e���	�����D�K�K��5�k�
L�
�
�	
��z�z��>��X�F��	����>�/�F�%�f�-�L�E��	�!� (��
��+�+� '��
�	.��>��T�F��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�H�!�F�!%�J�� �0�&��t�^�5����"�"�3�'�'��#��J�
�v�
�
��|��z�*���z�0����
�O
�	��$ ��)�)� ��	�	�9�#�!��H�H�X�.���&)�N��)��*�
��
�O
�	�	�	�s\�9AJ&�AH6�4J&�-J&�.J&�
J	�!
J&�6J	�2J	�9J&�J	�J&�J
�J&�&J7	c�6�\P!\4#r�)�obj_copy�deepcopyr&r5r6r7�get_builtin_cfgrxs�����[�)�)r6c�l�\PRV4\PP	V4#)zTesting if a link exists for %s)rTr�r1r��islinkr�s&r7�is_linkr{s$���I�I�/��6�
�7�7�>�>�$��r6c��\PRW4V'd�\PP	V4'd|\PP\PP
V4R\^4,4p\P!W4\P!W14R#\P!W4R#)z$Creating symbolic link from %r => %r�tmpN)
rTr�r1r�r�rVr=r��symlinkr)�source�link�force�tmp_links&&& r7�sym_linkr�
sy���I�I�4�d�C��������&�&��7�7�<�<������� 5�u�x��{�7J�K��
�
�
�6�$�
�
�
�8�"���J�J�v�r6c��\PRV4\P!V4R# \dR#i;i)zAttempting to remove %sN)rTr�r1�unlinkr�r�s&r7�del_filer�s3���I�I�'��.�
�
�	�	�$����
��
�r�c�^�\PRW4\P!W4R#)zCopying %s to %sN)rTr�r��copyr+s&&r7r�r�s���I�I� �#�,�
�K�K��r6c��\P!R\P!44pV# \dRpT#i;i)z%a, %d %b %Y %H:%M:%S %z�??)�time�strftime�gmtimer�)�tss r7�time_rfc2822r�#s@���
�]�]�5�t�{�{�}�
E���I����
��
�I��s�*.�
?�?c�La�^RIo^RIo!V3RlRSP4pSPSPPR44pSP
4pSPV4Vn^\4'g^M^S.pSP^,!V!pV!4pVPVSP\V44SPV4SPV4R^4R8wd%VPVPR,,#\!R4h)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
Nc�T<�]tRtRtRZP3RZP3.tRtR#)�boottime.<locals>.timevali;�tv_sec�tv_usecr5N)r�r�r�r��c_int64�_fields_r�)�ctypess�r7�timevalr�;s����v�~�~�.��F�N�N�0K�L�r6r��cg��.Az/Unable to retrieve kern.boottime on this systemr#)r��ctypes.util�	Structure�CDLL�util�find_library�c_size_t�sizeof�valuerA�c_intr�r�byrefr�r��RuntimeError)r��libcr��
mib_values�mibrr�s      @r7�boottimer�+s������M�&�"�"�M��;�;�v�{�{�/�/��4�5�D��?�?��D����w�'�D�J�	��+�+��2��J��<�<�!��j�
)�C�
�)�C������L�L��Z��)��L�L����L�L����
�
	
��	��z�z�C�K�K�)�3�3�3�
�H�
I�Ir6c�h�RpRp\PPR4'd/Rp\R4pV'dVP	4^,pV#Rp\\P!4\4,
4pV# \d\\RT,4T#i;i)r�rrz/proc/uptimer�z&Unable to read uptime using method: %s)r1r�r�r�r4rer�r�r�r%rT)�
uptime_strrWrs   r7�uptimer�Vs����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�$B�,B�/B�"B1�0B1c�"�\WRRR7R#)r�N)�omoder���
write_file)r��contents&&r7�append_filer�is���t�D�t�4r6�
preserve_modec�4�V^8�dQhR\R\RR/#)r-r�r�rcN)r0r�)rgs"r7rhrhms$������/3��	�r6c�$�\VRRWR7R#)r�r�)r�r�r�r�Nr�)r�r�r�s&&$r7�ensure_filer�ms����b��4�r6c�J�\V4# \\3dR#i;ir�)r0rrw)�possible_ints&r7�safe_intr�us)����<� � ���	�"����s�

�"�"c���\V4pV'd?V'd5\V4;_uu_4\P!W4RRR4R#R#R# +'giR#;ir�)r�r�r1rB)r�r��	real_modes&& r7rBrB|s@�����I��	�
�$�
�
��H�H�T�%� �
��t�
�
�
�s�A�A%	c�0�V^8�dQhR\R\/#)r-�grp_namerc�rer0)rgs"r7rhrh�s����3��3�r6c��Rp\P!V4PpV# \d\PRT4T#i;i)zh
Returns the group id of a group name, or -1 if no group exists

@param grp_name: the name of the group
z"Group %s is not a valid group namer#)r�r�r�r�rTr�)r�r�s& r7�get_group_idr��sQ��
�C�B��l�l�8�$�+�+���J���B��	�	�6��A��J�B�s� &�!A�
Ac�0�V^8�dQhR\R\/#�r-r�rcr�)rgs"r7rhrh�s��/�/�#�/�#�/r6c�j�\P!\P!V4P4#)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_IMODEr1�st_moder�s&r7�get_permissionsr��s!���<�<�����
�-�-�.�.r6c�0�V^8�dQhR\R\/#r�r)rgs"r7rhrh����+�+�C�+�C�+r6c��\P!V4p\P!VP4P
#)zk
Returns the owner of the file/folder pointed by the path.

@param path: The full path of the file/folder.
)r1r�r��getpwuid�st_uid�pw_name�r��sts& r7�	get_ownerr���*��
�����B��<�<��	�	�"�*�*�*r6c�0�V^8�dQhR\R\/#r�r)rgs"r7rhrh�r�r6c��\P!V4p\P!VP4P
#)zk
Returns the group of the file/folder pointed by the path.

@param path: The full path of the file/folder.
)r1r�r��getgrgid�st_gid�gr_namer�s& r7�	get_groupr��r�r6c�F�V^8�dQhR\R\\,/#)r-�usernamerc)rer)rgs"r7rhrh�s��
�
�c�
�d�3�i�
r6c�:�.p\P!4F0pWP9gKVPVP4K2	\
P!V4PpVP\P!V4P4V#)zd
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�rTr[r�s&   r7�get_user_groupsr��si���F�������|�|�#��M�M�%�-�-�(� ��,�,�x�
 �
'�
'�C�
�M�M�#�,�,�s�#�+�+�,��Mr6zWriting file�ensure_dir_existsr�r[c�0�V^8�dQhR\R\/#)r-r�r�rl)rgs"r7rhrh�s ��:�:�
�:��:r6c	��V'd
\V4pV'd+\\PPV4WgR7RVP
49d\V4pRpM
\V4pRpRV,p	\PRVVV	\V4V4\VR7;_uu_4\W4;_uu_4p
V
PV4V
P!4R	R	R	4R	R	R	4\#W4R	# \dELi;i \d
RT,p	L�i;i +'giLQ;i +'giL\;i)
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�r[�brf�
charactersz%oz%rzWriting to %s - %s: [%s] %s %sr�N)r�r�r/r1r�r=r�rsrnrwrTr�rr�r�r�r�rB)rgr�r�r�r�r�r�r[�
write_type�mode_r�fhs&&&&&$$$   r7r�r��s��:�	�"�8�,�D���2�7�7�?�?�8�,�4�E�
�e�k�k�m���g�&���
���(��!�
�������I�I�(��
���G���
�
�8�	$�	$�
�(�
"�
"�b��H�H�W���H�H�J�#�
%�
�(���7�	��	����������#�
"��
%�	$�sG�D�8	D�8E
�"D7	�.E
�D�D�D4�3D4�7E
�E
�
E	c��\P!V4F_p\PPW4p\PP	V4'd\V4KT\
V4Ka	R#)z�
Deletes all contents of a directory without deleting the directory itself.

@param dirname: The directory whose contents should be deleted.
N)r1r/r�rVrr�r�)r=�node�
node_fullpaths&  r7�delete_dir_contentsr��sL���
�
�7�#�������W�3�
�
�7�7�=�=��'�'��M�"��]�#�$r6c��\P!4p\V4pVRVP4:RV:2,
pVR\	4,,
pV#)r�z by cloud-init v. z on %s)r$�version_stringre�titler�)�comment_charr��ci_ver�headers&&  r7�make_headerr�	sE��
�
#�
#�
%�F�
��
�F�
�4�:�:�<��@�@�F�
�h���'�'�F��Mr6c	��\V\\34'g'\R\P
!V4,4hRpV'd
VR,
pR:R:R:R:2p^pVF�p\V\\34'd`.pVF4pVP
R\V4PRV4,4K6	V:RPV4:R2pV^,
pK~\V\4'dV:V:R2pV^,
pK�VfK�\R\P
!V4:R	V:24h	\PR
V4V#)z8Input to shellify was type '%s'. Expected list or tuple.r�z
#!/bin/sh
�'�\z'%s'r�rEzUnable to shellify type 'z&'. Expected list, string, tuple. Got: zShellified %s commands.)rlr.r�rwr"r�rrerrVrTr�)�cmdlist�
add_headerr��escaped�	cmds_mader��fixedr4s&&      r7�shellifyr�	s$���g��t�}�-�-��F��"�"�7�+�
-�
�	
�
�G���=� ����s�C�0�G��I����d�T�5�M�*�*��E������V�s�1�v�~�~�c�7�'C�D�E��")�3�8�8�E�?�;�G���N�I�
��c�
"�
"�")�4�0�G���N�I�
�\���'�0�0��6��>��
�!�*�I�I�'��3��Nr6c��V'd&VPV4'dV\V4RpV'd'VPV4'dVR\V4)pV#r�)r�rr0)r[�prefix�suffixs&&&r7�strip_prefix_suffixr�=	sK��
�$�/�/�&�)�)��C��K�M�"��
�$�-�-��'�'��N�s�6�{�l�#���Kr6c��\P!V^,4fR#\P!V4R# \PdR#i;i)rFT)r �whichrW)r�s&r7�_cmd_exits_zeror�E	sG���z�z�#�a�&��!����	�	�#�����%�%����s�;�A�Ac��\.RO4#)�systemd-detect-virt)rz--quietz--container�r�r5r6r7�_is_container_systemdrO	s���L�M�Mr6c��\R.4#)zlxc-is-containerrr5r6r7�_is_container_old_lxcrS	s���.�/�0�0r6c���\4'gR#.ROp\P!V^,4fR#\P!V4wrVP4R8H#)Fr�)r�z-qnzsecurity.jail.jailed)r:r r�r>)r�r?r)s   r7�_is_container_freebsdrW	sG���<�<��
3�C��z�z�#�a�&��!��
�Y�Y�s�^�F�C��9�9�;�#��r6c�^�\\\3pVFpV!4'gKR#	\^4pRV9dR#RV9dR#\PPR4'd(\PPR4'gR#\R4P4pVFHpVPR4'gKVP4PR^4wrVVR	8wgKGR#	R
# \\
3dL�i;i \\
3dR
#i;i)z@
Checks to see if this code running in a container of some sort
T�	container�LIBVIRT_LXC_UUIDz/proc/vzz/proc/bcz/proc/self/statuszVxID:rI�0F)rrr�get_proc_envrfr�r1r�rr�rQr�r>r4)�checks�helper�pid1env�linesr[�_keyr]s       r7r�r�a	s��	����F����8�8���	
��q�/���'�!����(��)�
�w�w�}�}�Z� � ������z�)B�)B��	
��2�3�>�>�@���D����w�'�'�"�j�j�l�0�0��a�8����#�:��	���%
�W��
��
��
�W��
���
�s;�D�D�2D�&D�9D�<D�D�D�D,�+D,c�@�\PPR4#)z2Check to see if we are running in a lxd container.z
/dev/lxd/sock)r1r�r�r5r6r7�is_lxdr�	s��
�7�7�>�>�/�*�*r6c�^�V^8�dQhR\R\R\\\3,/#)r-rk�errorsrc)rer)rgs"r7rhrh�	s,������*-��	�#�s�(�^�r6c�X�\PPR\V4R4p\	V4p/pRRrvTPY4pTPT4F/pT'gK
TPT^4wr�T	'gK+Y�T	&K1	T# \
\3d/u#i;i)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��=)	r1r�rVrer�rfr�rmr4)�pidrkrrr�env�null�equalr�rPr]s&&&        r7rr�	s���
�����g�s�3�x��	3�B��#�B�'��
�C��3�%����x�0�H��~�~�d�#�����i�i��q�)����4���I�$��J��
�W����	��s�B�B)�(B)c��/pVP4FpVPR^4wr4WAV&K	V# \dTpRpLi;i)rT)r4r)�kvstringr�r�rHr]s&    r7�keyval_str_to_dictr�	sZ��
�C��~�~���	����3��*�J�S��C��
 ��J��	�	��C��C�	�s�5�A�Ac��VPR4'd
VR,p\PPRV,4#)r���NNz/sys/class/block/%s/partition)r�r1r�r%)ris&r7�is_partitionr"�	s5��
����!�!�����
�7�7�>�>�9�F�B�C�Cr6c��\V\4'gV.p.pVF�p\V\4'dVPV4K,\V\\34'd�\V4^8g\V4^8�d\
R4h\V4^8Xd3V^,'d$VPV\	V4,4K�VPV^,4K�\
R4h	V#)r�z Invalid package & version tuple.zInvalid package type.)rlr�rerr.rr�)�version_fmt�pkgs�pkglist�pkgs&&  r7�expand_package_listr(�	s����d�D�!�!��v���G����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�!�$�Nr6c�.�VPR4Uu.uFqD'gKVNK	ppRpRpRpRp	\V4EF$wr�VP4p\V4^
8d(VPRV
^,\V4V4R#V^,p
V
PR4Uu.uFqD'gKVNK	pp\V4\V48�dK�\	\V4\V44pV^VV^V8wdK�V	e\V	4\V48�dK�VPR4p
Y�^,,pY�^,,pT
pTp	T^,pEK'	V'd(V'dV'dV'dX'dWgVV3#R#V'dV'd
V'dWgV3#R#uupiuupi \d TPRT
^,T4R#i;i \d TPRT
^,T4R#i;i)zNReturn the mount information for PATH given the lines from
/proc/$$/mountinfo.r�Nz$Line %d has two few columns (%d): %s�-z,Did not find column named '-' in line %d: %sz/Too few columns after '-' column in line %d: %s)r4rrr��minror�
IndexError)r��mountinfo_lines�log�get_mnt_optsr��
path_elements�devpth�fs_type�match_mount_point�match_mount_point_elementsr�r[r�mount_point�mount_point_elements�x�
mount_optionss&&&&             r7�parse_mount_infor9�	s
��!%�
�
�3��5��1�1�Q�Q��M�5�
�F��G���6:���_�-����
�
����u�:��?��I�I�6��A��s�5�z�4�
���A�h��+6�+<�+<�S�+A�G�+A�a�Q���+A��G��#�$�s�=�'9�9��
��(�)�3�}�+=�>����!�$�
�a��(:�:��&�1�c�&�7
��$�%�7&�
�
	����C� �A�	���E�l�G��q�5�\�F�(��%9�"��a��
�s.�v��g�"3�
��%6�
�F�F�
��g�"3��%6�7�7���O6��* H��.�	��I�I�>��A��t�
��		���	��I�I�A�1�q�5�$�
��		�s:�	F3�F3�&	F8�4F8�$F=�6G*�=%G'�&G'�*%H�Hc��\R4P4F)pVP4R,wr#pW08XgK%W$V3u#	R#)z<On older kernels there's no /proc/$$/mountinfo, so use mtab.�	/etc/mtab:N�NN)r�rQr4)r�r[r1r5r2s&    r7�
parse_mtabr=/
sE���{�+�6�6�8��'+�z�z�|�B�'7�$��W����K�/�/�9�r6c���VPR4p\V4^8Xd
V^,#\V4^8Xd
V^,#V^,R9d�VR,p\P!.RO4wr4VPR4F>pVP4p\V4^8�gK%V^,V8XgK5V^,pM	\V4#\PRV4R#)r�r rEz)Unexpected input in find_freebsd_part: %sN)r��gpt�gptidre�ufsid)�glabel�statusz-s)r4rr rerTrU)�fs�splitted�target_labelr�r��labelsrs&      r7�find_freebsd_partrH8
s����x�x��}�H�
�8�}�����{��	�X��!�	���{��	�!��A�	A��"�v���y�y�!;�<����j�j��&�F��L�L�N�E��5�z�A�~�%��(�l�":��Q�x���	'�
�4�y�����?��Dr6c���RpVPR4F]pVP4p\V4^8�gK%\PP	V^,V,4'gKZTpV#	V#)NrE)r4rr1r�r�)r��mnt_list�
path_foundr[rs&&   r7�get_path_dev_freebsdrLK
s`���J����t�$���
�
����u�:��>�b�g�g�n�n�U�1�X��_�=�=��J����%�
�r6c��\P!RRV.^^.R7wr\V4'd.\P!RR.4wr2\W4pVfR#TpVP4p\	V^,4pRV,#)rNz-pr�Nr�)r rrLr4rH)r�r�r`rJrKr��
label_parts&      r7�get_freebsd_devpthrOU
sx���I�I�w��d�3�!�Q��@�M�V�
�3�x�x��)�)�W�d�O�4���)�$�9�
������
�,�,�.�C�"�3�q�6�*�J��Z��r6c��\P!R.4wr#RpVPR4Uu.uFqU'gKVNK	ppRpRpRp	Rp
VP4EF�p\P!WK4pV'gK$VPR4pVPR4pVPR4Uu.uFqU'gKVNK	p
p\
V
4\
V48�dK�\\
V
4\
V44pV
^VV^V8wdK�V
e\
V
4\
V
48�dK�Tp	T
p
VPR4pVPR4pVeMR	PVPR4PR	4P4PR
44p\PRVVVV4\P!RV4pV'g#\4'dVR
9d\V4pTpW�8XgEK�M	V	'dW�9dR#V'd.X'd$X'dV	'dX'dVW�V3#R#R#R#R#X'dX'dV	'dVW�3#R#R#R#uupiuupi)zReturn the mount information for PATH given the lines ``mount(1)``
This function is compatible with ``util.parse_mount_info()``rNze^(?P<devpth>[\S]+?) on (?P<mountpoint>[\S]+?) (\(|type )(?P<type>[^,\(\) ]+)( \()?(?P<options>.*?)\)$r�Nr1rPrxr�rJr3zNfound line in mount -> devpth: %s, mount_point: %s, fs_type: %s, options: '%s'z^(/dev/.+)[sp]([0-9])$)�zfs�nfs)r r4rQrUrSr[rr+rVr>rTr�r:rO)r�r/�mountoutputr��regexr�r0r1r5r3r4r[r^r6r7r2r8�devm�match_devpths&&                 r7�parse_mountrWc
sU���)�)�W�I�.��[�	C�
�
!%�
�
�3��5��1�1�Q�Q��M�5�
�F��K���6:���&�&�(���I�I�e�"��������"���g�g�l�+��+6�+<�+<�S�+A�G�+A�a�Q���+A��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����$��q)�t� 1� =����G�(9�m� �'�m�L�L�?L�(9�G�<��G�(9� �'�=�=�):�G�<��M6�� Hs�	I9�I9�6	I>�I>c�D�R\P!4,p\PPV4'd&\	V4P4p\
WW4#\PPR4'd\V4#\W4#)z/proc/%s/mountinfor;)	r1�getpidr�r�r�rQr9r=rW)r�r.r/�mountinfo_pathrs&&&  r7�get_mount_infor[�
sp��:*�B�I�I�K�7�N�	�w�w�~�~�n�%�%��~�.�9�9�;����S�?�?�	������	$�	$��$����4�.�.r6c�0�V^8�dQhR\R\/#)r-�optrcr[)rgs"r7rhrh�
s��&�&�S�&�T�&r6c�F�\VRR7Evr#WPR49#)T�r/rJ�r[r4)r�r]r)�mnt_optss&&  r7�
has_mount_optrb�
s"��!�$�T�:�L�Q��.�.��%�%�%r6c�R�VPR^4p\V4^8�dV#VR3#)r+N)�rsplitr)�dottedris& r7�expand_dotted_devnamerf�
s,���=�=��a� �D�
�4�y�1�}�����~�r6c�L�Vf.pVf.p.p/pW,F p\W,V,RR7WV&K"	\V4'd+\	RPRP
V4R74hV# \dYa9dTPT4K�K�i;i)NF�rzMissing required files: {files}rJ)�files)r�r�rrrrgrV)r��required�optional�delimr_r�r4s&&&&   r7�pathprefix2dictrm�
s������������G�
�C�
�
 �
 ��	"�%�d�l�Q�&6�e�D�C�F�!��7�|�|��-�4�4�3�8�8�G�;L�4�M�
�	
��J��!�	"��}����q�!��	"�s�A:�:"B#�"B#c�z�RR
RRR^RR/pRRRRRR	/p/p\V4P4FdpVP4wrgpV'd\	V4W(,,WF&K;Wc9gKC\	V4W(,,WCV,&Kf	V# \dTP4wrgRpLti;i)
�kB�mB�B�gBz	MemTotal:�totalzMemFree:�freez
MemAvailable:�	available���@)r�rQr4rr0)	�meminfo�raw�mpliers�kmapr�r[rHr��units	&&       r7�read_meminfor~s����U�D�%��a��u�=�G��W��F����D�

�C��w�'�2�2�4��	�#�z�z�|��C����5�z�G�M�1�C�H�
�[� ��Z�'�-�7�C�S�	�N�5��J���	�����J�C��D�	�s�B�B:�9B:c
���TpVPR4'dVRR
pMVPR4'dVRRpR^RRRR
RRRR/pTpRpVF-pVPV4'gKTpV^\V4)pK/	\V4pT^8d\R	T,4h\	Y2T,,4# \dp\RT,4ThRp?ii;i)aMConvert 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
�iBNrq�K�M�G�Tz'%s' is not valid input.z'%s': cannot be negative���r#rvrwrxl)r0r�floatrr0)r��size_inr{�num�mplierr^r�s&      r7�human2bytesr�s���"�G��}�}�T����C�R�y��	
���s�	�	��C�R�y���A�s�E�3��s�E�3��F�G�
�C�
�F�
���=�=�����F��q�C��F�7�#�C��
F��C�j���Q�w��3�g�=�>�>��s�V�_�$�%�%��
�F��3�g�=�>�A�E��F�s�B<�<C�C�Cc��Vf\P!4^,pVR8H;'g!V^,R8H;'d
VR,R8HpV#)z$Return True if platform is x86-based�x86_64r�re�86)r1r2)�
uname_arch�x86_arch_matchs& r7�is_x86r�IsS�����X�X�Z��]�
��8�+����1�
���7�7��B��4�!7���r6c�.�\P!V4#r�)�email�message_from_string)r�s&r7r�r�Ss���$�$�V�,�,r6c�`�\P!RR.RR7p\4pVPP4FYpVP	R^4wr4pTP
R4'gK2TP\P!RRT44K[	V# \
dKmi;i)z
dpkg-queryz--listTr;Nz:.*r�)�hi�ii)
r rrr=rQr4rr�rwrU�sub)r?�	pkgs_instr[�stater'r)s      r7�get_installed_packagesr�Ws���
�)�)�\�8�,�d�
;�C���I��
�
�%�%�'��	�"�j�j��q�1�O�U�����L�)�)��M�M�"�&�&���C�0�1�
(�����	��	�s�B�B-�,B-c��Rp\\VRR74pVPRR4P4R8XdR#\4pRV9dR#\R	RR7pRVP49dR#\PPR
4'dR#R# \d!p\
P
RY4Rp?L�Rp?ii;i)r^TrhrRr�zubuntu-corez!Unexpected error loading '%s': %sNz
snap_core=z/etc/system-image/channel.iniz/etc/system-image/config.d/F)rhr�rir�rrTrUrFr1r�r)�orpath�orinfor�r@r�s     r7�system_is_snappyr�fs����F�D�#�N�6��$F�G���:�:�d�B��%�%�'�=�8��9�
�m�G��w����<�D�I�G���
�
��'��	�w�w�}�}�2�3�3�����D����7��C�C��D�s�;B"�"C
�-C�C
c��RpVP4F%pVPR4'gKVR,pM	VfR#VPR4'dV#VPR4'dRV\R4R,#VPR4'd$RV\R4RP4,#VPR4'diR	V\R4RP4,p\P
P
V4'dV#\V4pV'd
V^,#V#RV,#)
Nzroot=r r�r�z/dev/disk/by-label/zUUID=z/dev/disk/by-uuid/z	PARTUUID=z/dev/disk/by-partuuid/)r4r�rr�r1r�r�r�)r@rr��
disks_path�resultss&    r7�rootdev_from_cmdliner�~s!���E��}�}����>�>�'�"�"���G�E���
�}������ � �������!�!�$�u�S��]�_�'=�=�=����� � �#�e�C��L�N�&;�&A�&A�&C�C�C�����$�$�$�u�S��-=�-?�'@�'F�'F�'H�H�	��7�7�>�>�*�%�%��� ��'����1�:�����U�?�r6c��Rp/pV!V4F7pVPR^4wrgV'gTpV'gV'gK3WtV&K9	V#)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�2�\P!VRR7#)T)�comments)�shlexr4)rbs&r7�_shlex_split�(load_shell_content.<locals>._shlex_split�s���{�{�4�$�/�/r6r)r4)r��	add_empty�	empty_valr�rZr[rHr�s&&&     r7rhrh�sL��0��D��W�%���Z�Z��Q�'�
����E������I�&��Kr6c	���\V4p^pT\VUu.uF,p\PPV4'gK*VNK.	up4,pV'g\PRVVV4.#V^8Xd\PRVVV4WR,V8�dM \P!V4WR,
pK�\PRW1V4V#uupi)rz)%sAll files appeared after %s seconds: %sz6%sWaiting up to %s seconds for the following files: %sz*%sStill missing files after %s seconds: %s)rrr1r�r�rTr�r��sleep)�flist�maxwait�naplen�log_pre�need�waitedr4s&&&&   r7�wait_for_filesr��s����u�:�D�
�F�
����:��1������q�(9�Q�Q��:�;�;����I�I�;����	
��I��Q�;��I�I�H����	
��?�W�$���
�
�6������I�I�4�g����K��1;s�'C 
�C 
c�>�RpVPRV.\R7R#)z-Helper to wait on completion of snap seeding.c��\P!R4'g\PR4R#\P!.RO4R#)�snapz+Skipping snap wait, no snap command presentN)r��waitr/zseed.loaded)r r�rTr�r5r6r7rj�&wait_for_snap_seeded.<locals>.callback�s.���z�z�&�!�!��I�I�C�D���	�	�;�<r6zsnap-seeded)�freqN)�runr')rarjs& r7�wait_for_snap_seededr��s��=�
�I�I�m�X�r��I�9r6c�d�\VRR7pVR,PR4pV^,R8H#)z1Check whether the given mount point is mounted rwTr_rJ�rwr#r`)r5r��
mount_optss&  r7�mount_is_read_writer��s1��
�K�d�
;�F����!�!�#�&�J��a�=�D� � r6c�D�\P!R4'gR#RR.pV'dA\PP	V4'dR#VPRV,.4V'dVPRV,.4\P!V4#)zAInvoke udevadm settle with optional exists and timeout parameters�udevadmN�settlez--exit-if-exists=%sz--timeout=%s)r r�r1r�r�r�)r�r��
settle_cmds&& r7�udevadm_settler��sx���:�:�i� � �	��X�&�J�
�
�7�7�>�>�&�!�!�����0�6�9�:�;�����>�G�3�4�5��9�9�Z� � r6c�(�V^8�dQhRRR\/#)r-rr(rcr))rgs"r7rhrh�s����W���r6c�|�R./p\P!\VPR4RR74pRV9d.VR&V# \d*\
P
RTPR44T#\Pd1p\
PR\PT4Rp?T#Rp?ii;i)�scopeszhotplug.enabledFrhzFile not found: %sz>Ignoring contents of %s because it is not decodable. Error: %sN)r5r6r�rr�rTr��JSONDecodeErrorrUr�HOTPLUG_ENABLED_FILE)rr�r�s&  r7�read_hotplug_enabled_filer��s����r�N�G�#��*�*��5�?�?�+<�=�U�K�
���7�"� "�G�H���N���L��	�	�&����8I�(J�K��N����
����L��)�)�
�	
�	
��N��
�s#�0A�0B;�7B;�
B;�%B6�6B;c�@�V^8�dQhR\R\R3,/#)r-rcN)rr
)rgs"r7rhrh
s��
�
�Y�t�S�$��/�
r6c#�"�Rx�R#5i)zlContext manager that does nothing.

Note: In python-3.7+, this can be substituted by contextlib.nullcontext
Nr5r5r6r7�nullcontextr�	s
���
�s�	)�truer��on�yes)�offr�no�false)r}r�)� N)TTr�r�r)r�r�r!)r�r�r!�
)z
/etc/hosts)NriNFN)NF)rvN)i�)NNN)NNNT)�)r�r�F)rd�created)T)r}r)z
/proc/meminfoF)FN)g�?r�)�ry�
contextlibr�rvr�r$r�rrr
r5�loggingr1�os.pathr.r�r�rUr�r�rsr�r�r�r�r��base64r�collectionsrrrr�r�	functoolsr�pathlibr	�typesr
�typingrrr
rrrrrrrrrrr�urllibrr�	cloudinitrrrrrrr r!r"r#r$�cloudinit.log.log_utilr%�cloudinit.settingsr&r'�cloudinit.helpersr(rq�	getLoggerr�rT�seprr�r�rr�r�r8r@rHrnrs�timedr{r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
rrr*r0r4r:r>rArDrIrKrMr\rpr�r9r�r�r�r�r�r�r�r�r�r�rrXr�r�r6r=rBrArTrVrbrjr�r`r�r�r�r�r�r�r�r�r�r�r�r�r�rFr�r�r�r�r�rr r$r(r*r1r;r>r/rLr_rtrxr{r�r�r�r�r�r�r�r�rBr�r�r�r�r�r�r�r�r�r�r�rrrr�rrrr"r(r9r=rHrLrOrWr[rbrfr�rmr~r�r�r�r�r�r�rhr�r�r�r�r�r�r5r6r7�<module>r�s<�������
���	���	���
�
�	��
�
��
��
����/��������� ������*�4��'���
����!���F�F�C����v�}�}�
$�v�';�';�
;�
�)��+�
�>����
�����
��:M�
O�

���$�%�
�&�
� �&,�,�^	�y�	�	��	�
�*�� �D��..�4�..�h&�$�
�
4� 
� 	���(�
�(����
����1�
�1���3�
�3���0�
�0���1�
�1�%��?�%�P��01�
�01�f8�v��
�
�
��6�0�&Q5�h5�p�������������
��&�B!�4�'�%�P4�n�T��@,��,�^<�
 �F*��z��(8�V%�P
���?�#�2�$�2�j�
��
�&�(�4*�"*�&=�@�>��04���	�*P�04�P��	P����
��$�	���
�_�D+*�\�����

���>�"� $�w��#��4�"�6���"��"�'�T\�~*�
 �
	�
��
���'J�
�'J�T�&5��6;����&��/�+�+�
� 
���>�"�:�#�:�
�:��:�#�:�z$��"�J��N�1����*�
�*�Z+�
�>	�D��614�%�K�\�E�&� �T>�n!�u�$/�N&�
�$(�$�b�g�g�k�k��0�0(&�V�-���0�>�(�>	:�!�!�$�(�
��
r6

Youez - 2016 - github.com/yon3zu
LinuXploit