__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
�

x[h�l�	��SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSK
rSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJr SSKJr SSKJrJr SSK J!r! SSK"J#r# SSK$J%r% SSK&J'r' SS	K(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6 SS
K7J8r8 SSK9r9SSK:J;r;J<r<J=r=J>r>J?r?J@r@JArAJBrBJCrCJDrDJErE SSKFJGrG SS
KHJIrIJJrJ \*(aSSKKJLrL SqM\R�"\O5rP\R�S0rRS\R�-\R�-rUSrVSrWSrX\#"5S5rY\#"5S5rZS�S\5\[\\4S\[4Sjjr]S�S\5\[\\4S\\4Sjjr^\?R�"S5S\\S\\4Sj5r`Sra"SS 5rb"S!S"\c5rd"S#S$\c5reS%rfS�S&jrgS�S'jrhS�S(jriS�S)jrjS�S*jrkSS+.S\.4S,jjrlS-rmS.rnS/roS�S1jrpS2rqS3\[S\r4S4jrs\#"5S55rt\#"5S65ru\#"5S75rv\#"5S85rw\#"5S95rx\#"5S:5ryS�S<jrzS�S=jr{S�S>jr|S�S?jr}\#"5S@5r~SAr\#"5SB5r�S�SCjr�S�SDjr�SEr�S�SFjr�S�SG\4\1S\r4SHjjr�\R<SI5r�\R<SJ5r�SKr�SLr�S�SMjr�S�SNjr�S\r44SOjr�S�SPjr�SS+.S\r4SQjjr�SS+.S\r4SRjjr�S�SSjr�S�STjr�SUr�"SVSW\25r�S�SXjr�S�SYjr�\?R�"SZ5S\�4S[j5r�S\r�S]r�S^r�S_r�S�S`jr�S�Sajr�S�Sbjr�S�Scjr�S�Sdjr�S�Sejr�Sfr�SS;Sg.Sh\5\[\GRF4Si\3\,\�/S4Sj\�S\\4Skjjr�SS;Sg.Sh\5\[\GRF4Si\3\,\�/S4Sj\�S\[4Sljjr�\#"5Sm5r�Snr�S\�4Sojr�S�Spjr�S�Sqjr�S�Srjr�Ss\.\[\+4St\3\[S\0\3\[4Sujr�Ss\.\[\+44Svjr�S�Sw\[S\[4Sxjjr�Syr�Szr�S{r�S�S|jr�\?R�"S}5\r44S~j5r�Sr�S�S�jr�\R<S�5r�S�r�S�S�jr�S�r�S�r�S�S�jr�S�r�S�rS�r�\#"5S�5r�S�r�S�r�S�S;S�.St\�S�\�SS4S�jjjr�S�r�S�r�S�\[S\�4S�jr�S�\[S\�4S�jr�S�\[S\[4S�jr�S�\[S\[4S�jr�S�\[S\0\[4S�jr�\?R�"S�5S�S0SSS�.S�\�S�\�4S�jjj5r�S�r�S�S�jr�S�S�jr�S�S�jr�S�r�S�r�S�r�S�r�\#"5S�5r�S�r�S�S�\[S�\[S\.\[\[44S�jjr�S�r�S�r�S�r�\PS;4S�jr�S�r�S�r�S�r�S�r�S�S�jr�\PS;4S�jr�S�\[S\�4S�jr�S�r�SS\GR�R�4S�jr�S�S�jr�S�r�S�S�jr�S�r�S�r�S�r�S�r�S�S�jr�S�S�jr�S�r�S�r�S�S�jr�S�S�S\r4S�jr�\S\/S\+S44S�j5r�g)��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��[[[[R"5R
R
S5SS55$)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�d�[R"SS/SS9nURR5$)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�J�SSSSS.n0n[R"SS/SS	9nURR5H3nURS
5upEnX@;dMUR	5XU'M5 UR5Vs/sHowU;dM
UPM nnU(a%[RSSRU55 U$s snf![RaAn	[RS
U	5 [SUR555nSn	A	U$Sn	A	ff=f)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�(# �UHoS4v� M
 g7f)�UNAVAILABLENr<)�.0�vs  r>�	<genexpr>�lsb_release.<locals>.<genexpr>�s���>�
�1�
�&�
�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�)�)�+�D� �N�N�3�/�M�E�c��}�$'�I�I�K��%�[�!�,�#�k�k�m�=�m���}�1�m��=���K�K�@�����!�
��K��>���%�%�?����9�3�?��>����
�>�>���K��	?�s6�AC
�+C
�	C�C�.C
�C
�
D"�!6D�D"�blob�returnc�N�[U[5(aU$URUS9$�N)�encoding)�
isinstance�str�decode)rhrls  r>�
decode_binaryrp�s$���d�C�(�(�4�L�d�k�k�8�k�.L�Lr=�textc�N�[U[5(aU$URUS9$rk)rm�bytes�encode)rqrls  r>�encode_textru�s$���d�E�*�*�4�N����X��0N�Nr=zBase64 decodingrac��[U[5(d[S[U5-5e[	USS9$![
Ra Us$f=f)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)rmrs�	TypeError�typer�binascii�Error)ras r>�maybe_b64decoder|�sP���d�E�"�"��6��d��C�D�D�����-�-���>�>�����s�	8�A�Ac��URSS9nUR5S:Xa^[U[5(aIUR	5nU(aUR
(a
UR
nOSnUR
US5$U$)NT)rorq�utf-8�surrogateescape)�get_payload�get_content_maintypermrs�get_charset�input_codecro)�part�cte_payload�charsetrls    r>�fully_decoded_payloadr��s~���"�"�$�"�/�K�� � �"�f�,���U�2�2��"�"�$���w�*�*��*�*�H��H��!�!�(�,=�>�>��r=c�*�\rSrSrSSjrSrSrSrg)�SeLinuxGuard�c��U [R"S5UlXlX lg![a
 SUlN f=f)N�selinux)r�
import_moduler��ImportError�path�	recursive)�selfr�r�s   r>�__init__�SeLinuxGuard.__init__�sB��	
�	 �#�1�1�)�<�D�L��	�"����	 ��D�L�	 �s�,�A�Ac�f�UR(a URR5(agg�NTF)r��is_selinux_enabled)r�s r>�	__enter__�SeLinuxGuard.__enter__�s!���<�<�D�L�L�;�;�=�=��r=c��UR(aURR5(dg[RR	UR5(dg[RRUR5n[R"U5nURRXE[R5 [RSUUR5 URRX@RS9 g![a gf=f![a,n[RSUURU5 SnAgSnAff=f)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�OSErrorr[�debugr��
restoreconr\)r��	excp_type�
excp_value�excp_tracebackr��stats�es       r>�__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�/#D#�
D �D �#
E�-"E�E)r�r�r�N�F)�__name__�
__module__�__qualname__�__firstlineno__r�r�r��__static_attributes__r<r=r>r�r��s��	#��r=r�c��\rSrSrSrg)�MountFailedError��r<N�r�r�r�r�r�r<r=r>r�r�����r=r�c��\rSrSrSrg)�DecompressionError��r<Nr�r<r=r>r�r��r�r=r�c�f�[R"5nUS:Xa U"U0UD6 [R"S5 g[
RSU[R"U55 g![a> [	[
S[R"U55 [R"S5 gf=f)Nrz&Failed forking and calling callback %s�z(Forked child %s who will run callback %s)	r8�fork�_exit�	Exceptionr%r[r"�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(�(AB0�/B0c���[U[5(aUSL$[nU(a[U5U-n[	U5R5R
5U;aggr�)rm�bool�TRUE_STRINGS�listrn�lowerrE�rd�addons�	check_sets   r>�is_truer�sQ���#�����d�{���I�
���O�f�,�	�
�3�x�~�~�����9�,��r=c���[U[5(aUSL$[nU(a[U5U-n[	U5R5R
5U;agg)NFT)rmr��
FALSE_STRINGSr�rnr�rEr�s   r>�is_falser�sQ���#�����e�|���I�
���O�f�,�	�
�3�x�~�~�����9�,��r=c�V�U(dg[U[5(aU$[X5$�NF)rmr�r�)rdr�s  r>�translate_boolr�s'�����#�����
��3��r=c��[R"5nU(d![R[R-nSR[
U5Vs/sHo2RU5PM sn5$s snf�N�)�random�SystemRandom�string�
ascii_letters�digitsr]�range�choice)�strlen�select_from�r�_xs    r>�rand_strr�(sS������A���*�*�V�]�]�:��
�7�7�E�&�M�B�M�b�H�H�[�)�M�B�C�C��Bs�A7c�H�U(dSn[SS9S-U-nX ;aU$M)Nr��)r�r))r�)�
dictionary�postfix�newkeys   r>�
rand_dict_keyr�/s4�����
���#�c�)�G�3���#���M�	r=��instance_data_filec	���SSKJnJnJnJn [U5nU(aF[RRU5(a"U"UUU5n[RSUU5 [U0S9$![a 0s$f=f!Ua!n[RSUU5 SnAN>SnAfUa NIUa+n[RSUU[U55 SnANtSnAff=f)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��existsr[r�r\�repr�	load_yaml)rcr�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;�A0�!B�0A?�>A?�C�B$�$	C�/C�4!C�Cc�$�[[U65$�N)�sorted�
uniq_merge)�listss r>�uniq_merge_sortedr�ms���*�e�$�%�%r=c��/nUHbn[U[5(a9UR5RS5nUVs/sH
o3(dMUPM nnUR	U5 Md [U5$s snf)NrQ)rmrnrEr;�extend�	uniq_list)r��
combined_list�a_list�as    r>r�r�ysj���M����f�c�"�"��\�\�^�)�)�#�.�F�!'�-��A�1�a��F�-����V�$���]�#�#��.s�
A6�A6c��[R5HupURX5nM /nUH nU[;dMUR	U5 M" UHnURUS5nM UR5nU$r�)�FN_REPLACEMENTS�items�replace�
FN_ALLOWED�appendrE)�fnrerU�removalss    r>�clean_filenamer
�st���%�%�'���
�Z�Z��
��(��H�
���J���O�O�A�����
�Z�Z��2�
���	����B�
�Ir=Tc���[R"[U55n[R"SSSU5nU(a+[UR
55sSSS5 sSSS5 $UR
5sSSS5 sSSS5 $!,(df   O=fSSS5 g!,(df   g=f![a(nU(aUsSnA$[[U55UeSnAff=f)N�rbr�)
�io�BytesIOru�gzip�GzipFilerp�readr�r�rn)ra�quietro�buf�ghr�s      r>�decomp_gzipr�s���4�
�Z�Z��D�)�
*�c�4�=�=��$��3�4
�
��$�R�W�W�Y�/�	4
�4
�
*�
*��w�w�y�
4
�4
�
*�
*�4
�4
��
*�
*�
*���4���K�$�S��V�,�!�3��	4�so�B;�B*� B�	B*�$	B;�.B�=	B*�	B;�
B	�B*�!B;�*
B8�4B;�8B;�;
C-�C(�
C-�C(�(C-c�8�U(dgURSS5nUSR5n[U5S:XaUSR5nOSnU(aUS:XdUR5S:XaSnU(aUS:XdUR5S:XaSnX#4$)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���
�6�Mr=�root_dirc��[5n[R"[RR	US55Hn[RRU5(dM)[RR
U5SSnUR5nU(dMdURS5S:XdM{X1U'M� U$)Nz*.pyr���r3���)	r_�globr8r�r]�isfile�basenamerE�find)r"�entriesrc�modnames    r>�get_modules_from_dirr,�s����f�G����2�7�7�<�<��&�9�:���w�w�~�~�e�$�$���'�'�"�"�5�)�!�B�/���-�-�/���7�w�|�|�C�(�B�.�$�E�N�
;��Nr=c�2�S[R"5;$)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�systemr<r=r>�is_Linuxr2�s���h�o�o�'�'�'r=c�l�S[R"5;ag[R"5S:Xagg)N�BSDT�	DragonFlyFr/r<r=r>�is_BSDr6�s)������!�!������K�'��r=c�"�[5SS:H$)N�variant�freebsd��system_infor<r=r>�
is_FreeBSDr<�����=��#�y�0�0r=c�"�[5SS:H$)Nr8�	dragonflyr:r<r=r>�is_DragonFlyBSDr@�s���=��#�{�2�2r=c�"�[5SS:H$)Nr8�netbsdr:r<r=r>�	is_NetBSDrC�s���=��#�x�/�/r=c�"�[5SS:H$)Nr8�openbsdr:r<r=r>�
is_OpenBSDrF�r=r=Fc�*�X;aU$[X5$r�)r���yobj�keyr�s   r>�get_cfg_option_boolrK�s��
�����$�)�$�$r=c�\�X;aU$Xn[U[5(d[U5nU$r�)rmrn)rIrJr�rds    r>�get_cfg_option_strrM�s.��
����
�)�C��c�3����#�h���Jr=c�(�[[XUS95$)Nr�)r7rMrHs   r>�get_cfg_option_intrO�s���!�$�W�=�>�>r=c��U(dSn[RRU5(d0$[U5nSnSU;aSn[R
"X!5nU(afUR
5nSUS;aUSUS'USR5RS5SUS'USS	:XaS
US'USUSUSS.$0$)
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�rY)�release_file�redhat_release�redhat_regexrX�groups     r>�_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�
�	
�
�Ir=c�J�SnSnSn0nSn[RRS5(a[[	S55nU(dSn[5nU(a�UR
SS5nUR
SS5nSU;dSU;a[R"5nO�US	:XdUS
:XaUR
SS5nOzUS:XaU(dUR
SS5nOZUR
S
S5nU(dA[R"SUR
SS55nU(aUR5SnUS:XaSnO�[5(a9[R"5R5n[R"5nOLSn[R "5nSnUHnU(dMSnM U(d[$R'S5 U$XU4$!["a NDf=f!SnUHnU(dMSnM U(d[$R'S5 ff=f)Nr�F�/etc/os-releaseTrTrU�sles�suse�alpine�photon�PRETTY_NAME�	virtuozzorVz[^ ]+ \((?P<codename>[^)]+)\)�VERSIONrI�rhelrS)r�r�r�r�zPUnable to determine distribution, template expansion may have unexpected results)r8r�r��load_shell_contentr�r^�getr0�machinerWrXrYr6r1r�r:�distr�r[r\)	�distro_name�distro_version�flavor�
os_release�os_release_rhelrXrl�found�entrys	         r>�get_linux_distrort 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����5��E������<������0�0���	��	���E����5��E������<���s*�G�
G*�'G-�)G*�*G-�-
H"�>$H"c���USR5nSnUS:XaCUSSR5nUS;aUnU$US;aSnU$US	:XaS
nU$US;aSnU$SnU$US
;aUnU$)Nr1�unknown�linuxrlr)�	almalinuxrc�aosc�arch�
azurelinux�centos�
cloudlinux�debian�	eurolinux�fedora�mariner�miraclelinux�	openeuler�opencloudos�openmandrivardrh�rockyrb�	tencentosrf)�ubuntu�	linuxmint�mintr�rSrh)�opensusez
opensuse-leapzopensuse-microoszopensuse-tumbleweed�sle_hpcz	sle-microrarb)�windows�darwinr9rBrEr?)r�)�infor1r8�
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��[R"5[R"5[R"5[R"5[	[R
"55[
5S.n[U5US'U$)N)r0r1r:�pythonr9rlr8)r0r1r:�python_versionr�r9rtr�)r�s r>r;r;�sc���%�%�'��/�/�#��#�#�%��)�)�+��h�n�n�&�'� �"�
�D�#�4�(�D��O��Kr=c���X;aU$Xc/$Xn[U[5(aUVs/sHoDPM nnU$[U[5(d[U5nU/$s snf)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.
)rmr�rn)rIrJr�rdrU�cvals      r>�get_cfg_option_listr��sj�������y���	�
�)�C��#������3�a��3������c�3����#�h���5�L��	 s�Ac��[U[5(aURS5nUnUHnXC;aUs $X4nM U$)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.�/)rmrnr;)rI�keypr��cur�toks     r>�get_cfg_by_pathr��sE���$�����z�z�#���
�C����>��N��h����Jr=c�8�[X5up#[X#5 X#4$r�)�get_output_cfg�redirect_output)�cfg�mode�outfmt�errfmts    r>�fixup_outputr��s ��%�c�0��V��F�#���r=c�0�[[RRS55(a[RS5 gU(d[RnU(d[RnSnU(Ga0[RSX 5 URSS5upVUS:XdUS:XaS	nUS:XaS
n[Xg5nO[US:XaG[R"US[RUS
9n	[[[ U	R"5nO[%SU-5eU(a3[R&"UR)5UR)55 X:XaJ[RSX05 [R&"UR)5UR)55 gU(a�[RSX15 URSS5upVUS:XdUS:XaS	nUS:XaS
n[Xg5nO[US:XaG[R"US[RUS
9n	[[[ U	R"5nO[%SU-5eU(a4[R&"UR)5UR)55 ggg)N�_CLOUD_INIT_SAVE_STDOUTz5Not redirecting output due to _CLOUD_INIT_SAVE_STDOUTc��[R"S5 [R"S5Rn[R
"U5 g![a gf=f)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_gid�5redirect_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�environrjr[r��sysrD�stderrr;�open�
subprocess�Popen�PIPErrr
r�rx�dup2�fileno)
r�r��o_out�o_errr�r��arg�owith�new_fp�procs
          r>r�r��s����r�z�z�~�~�7�8�9�9��	�	�I�J����
�
����
�
�� �&��	�	�(�%�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��+r=�sourcesc��U(a[[U55n0nUHenU(dM[R"U5nU(d[R"5n[R
"U5nUR
X#5nMg U$)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      r>�
mergemanydictr�@su��T��x��(�)���J����3�&�;�;�C�@��#�#*�#:�#:�#<� ��&�&�'7�8�F����j�6�J���r=c#��# �[R"5n[R"U5 Uv� [R"U5 g![R"U5 f=f7fr�)r8�getcwd�chdir)�ndir�currs  r>r�r�xs;���
�9�9�;�D��
������
�
�����������s�A%�A
�A%�
A"�"A%c#�# �[R"U5nUv� [R"U5 g![R"U5 f=f7fr�)r8r�)�n_msk�olds  r>r�r��s2���
�(�(�5�/�C���	�
����
������
�s�A�5�A�A
�
Ac�$�SRXSUS9$)Nz{0:{fill}{align}{size}}�^)�fill�align�size)�format)rqr��max_lens   r>�centerr��s!��$�+�+��s��,��r=c�\�[RSU5 [R"U5 g)NzRecursively deleting %s)r[r��shutil�rmtree�r�s r>�del_dirr��s���I�I�'��.�
�M�M�$�r=c��[XUS9upEpgXPS'X`S'X@S'XpS'g![Ra)nUR[R:XaSnAgeSnAff=f)	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-data�network-configTNF)�read_seededr#�UrlError�code�	NOT_FOUND)	r�r�r�r��md�ud�vd�networkr�s	         r>�read_optional_seedr��sj��
�)�t�g�N�����[�� �]���[��!(�
���������6�6�Z�)�)�)��
���s� �A�A�A�Ac��0nU(dSS/nO^[RRURS5S5[RRUR	S5S5/n[U5nUVs/sH3o3(dM[RR
U5(dM1UPM5 nnSnUHgn[RR[RRUS55(dMG[RRUS5n O SnUHgn[RR[RRUS55(dMG[RRUS5n O U(aU(a
XAS'XQS'U$U(aXAS'U$s snf)	Nz/var/lib/cloud/data/sslz /var/lib/cloud/instance/data/sslra�sslzcert.pemzkey.pem�	cert_file�key_file)r8r�r]�
get_ipath_cur�	get_cpathr��isdirr')�paths�ssl_details�ssl_cert_paths�drrs      r>�fetch_ssl_detailsr	�sU���K��%�.�
��
�G�G�L�L��,�,�V�4�e�<��G�G�L�L�����0�%�8�
�� ��/�N�!/�J��A�1�a������q�9I�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�<
F;�
"F;�0F;c��Un[U5n[RS[U5U5 [R
"U5nUc[RS5 UnO8[
XB5(d([SU<S[R"U5<S35eUnU$![R[[4a�nSnSn[US5(a[US5(a
[US5nO.[US5(a[US5(a[US5nU(a/US	RURS
-UR S
-US9-
nOUSRUS
9-
n[R#U5 SnAU$SnAff=f)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�)rb�colrgz. {err})rg)rpr[r�r�yaml�	safe_loadrmrxr"r��	YAMLError�
ValueError�hasattr�getattrr�rb�columnr\)rhr��allowed�loaded�	convertedr��msg�marks        r>r�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�BB�F�;B>E?�?Fc��URS5S:�aUURSSU-5nURSSU-5nURSSU-5nURSSU-5nOs[R(a2USS:wa)[R
"U5RS	:XaUS-
nU<S<U<3nU<S<U<3nU<S<U<3nU<S<U<3nSn[R"XrUS
9n	U	R5(a[U	R5n[R"XbUS
9nSnUR5(a[UR0S9n[R"XBUS
9n
SnU
R5(aU
RnSn[R"XRUS
9nUR5(a
URnO[RS
5 X�X�4$![Ra n
[RSU
5 Sn
A
N�Sn
A
ff=f![Ra n
[RSU
5 Sn
A
NjSn
A
ff=f)Nz%srr�r�r�r�r%r�r�)r��retrieszNo network config provided: %sr�zError in vendor-data responsez!Error in vendor-data response: %s)r)rr�%NOCLOUD_SEED_URL_APPEND_FORWARD_SLASHr�urlparse�queryr#�read_file_or_url�okr��contentsr�r[r�)r�r�r�r�ud_url�vd_url�md_url�network_urlr��network_respr��md_respr��ud_respr�r��vd_resps                 r>r�r��s���y�y���!�����d�K�#�$5�6�����d�M�C�$7�8�����d�K�#�$5�6���l�l�4�)9�C�)?�@���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�!G,�H#�,H �H�H �#I�7I�Ic	��[[R"U5SS9nUVs/sHo3RS5(dMUPM nnUVs/sHHn[RR[RR
X55(dMFUPMJ nn/nUH<n[RR
X5nUR[UUS95 M> [U5$s snfs snf![a [RSU5 Mx[a!n[RSXg5 SnAM�SnAff=f)zRead configuration directory.T�r�z.cfgr��1REDACTED config part %s, insufficient permissions�Error accessing file %s: [%s]N)r�r8�listdir�endswithr�r'r]r
r��PermissionErrorr[r\r�r�)�confdr��confs�f�cfgsrr�r�s        r>�read_conf_dr6)s��
�2�:�:�e�$�d�3�E��4��1���F�!3�Q��E�4��H��1�����������U�0F�!G�Q��E�H��D����w�w�|�|�E�&��	B��K�K���'9��
�� �����/
5��
I���	��K�K�C�T�
��	B��K�K�7��A�A��	B�s6�C,�C,�AC1�C1�C6�6 E�	E�"D>�>Ec��[5n0n[XS9nURU5 SnSU;abUSnU(aU[U[5(d'[SU<S[R"U5<35e[U5R5nO,[RRUS	35(aUS	3nU(a>[RRU5(a[!XQS9nUR#U5 [%U5$![a [RSU5 GN	[a!n[RSX5 SnAGN.SnAff=f)
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�r
r1r[r\r�rmrnrxr"r�rEr8r�rr6�
appendleftr�)�cfgfiler�r5r�r�r2�	confd_cfgs       r>�read_conf_with_confdr<Is$����D��C�	���G��	
���C���E��3���H�
����e�S�)�)���
� 3� 3�E� :�<���
�E�
�(�(�*���	�����'��"�~�	&�	&��)�2���������u�%�%���M�	����	�"������9�
����?��	
��A����3�W�@�@��A�s�	D� E�1	E�:E�Ec�&�[[US95$)N��cmdline)r��read_cc_from_cmdliner>s r>�read_conf_from_cmdlinerAxs���)�'�:�;�;r=c���Uc
[5nSU3nSnSn[U5n[U5n[U5n/nURU5nUS:�a�URX'U-5nUS:aUnUR[R
"XU-UR
55RSS55 URXU-5nUS:�aM�SRU5$)Nr�z cc:�end_ccrz\n�
)	�get_cmdlinerr)r
r�unquote�lstriprr])	r?�	tag_begin�tag_end�begin_l�end_l�clen�tokens�begin�ends	         r>r@r@}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���1�*��9�9�V��r=c�n�URS5nUS::dXS-
S:waU$URSS5$)NrDrr��
z
)r)r)r"�poss  r>�dos2unixrS�s=��
�-�-��
�C�
�a�x�8�!�G�$��,������F�D�)�)r=c�4�\rSrSr%\\S'\\S'\\S'Srg)�HostnameFqdnInfoi��hostname�fqdn�
is_defaultr<N)r�r�r�r�rn�__annotations__r�r�r<r=r>rUrU�s���M�

�I��r=rUc�j�SnSU;a.[US5n[USURS5S5nOrSU;a5USRS5S:�aUSnUSSURS5nO7UR	SUS9R
nSU;aUSnOUR	US	9upS[
XTU5$)
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.
FrWrVr3rNT)rW�
metadata_only)r[)rnrMr;r)�get_hostnamerVrU)r��cloudr[rXrWrVs      r>�get_hostname_fqdnr^�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�7r=c�<�Sn[U5R5HinURS5nUS:�aUSUnUR5nU(dM8UR	5n[U5S:aMYXSS;dMcUSn U$ U$![a U$f=f)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�r4r�)r�rXr)rEr;r�IOError)rV�filenamerWrb�hashpos�tokss      r>�get_fqdn_from_hostsrf�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�A8B
�B
�B
�
B�Bz
Resolving URLc	��[R"U5nURn[c�[	5nSn0nUH}n[
R"USSS[
R[
R5n/XV'UH8up�p�nXVRU<SUS<35 URUS5 M: M UqU(a[RSU5 [[ 5 ["R$"UR&R)S55(a
SSS5 gSSS5 [
R"US5nUSSSn
U
[;$![
R[
R4a GMKf=f!,(df   Ne=f![
R[
R4a g	f=f)
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)rrrV�_DNS_REDIRECT_IP�set�socket�getaddrinfo�SOCK_STREAM�AI_CANONNAMEr
�add�gaierror�errorr[r�rrr�
is_ip_address�netlocrE)�url�
parsed_urlrR�badips�badnames�
badresults�iname�result�_fam�_stype�_proto�cname�sockaddr�addrs              r>�
is_resolvabler�s�������$�J����D������
��
�
��E�	
��+�+��4��A�v�'9�'9�6�;N�;N���%'�
�!�=C�9�D�&���%�,�,�����-L�M��J�J�x��{�+�>D�
�"����I�I�4�j�A�
�
�j�
!�� � ��!2�!2�!8�!8��!>�?�?��"�
!�?�"��#�#�D�$�/���a�y��|�A����+�+�+���O�O�V�\�\�2�
��
��"�
!��
�O�O�V�\�\�*����sB�A9E�F�*6F	� F�*2F�$F�F�	
F�F�$G�Gc�0�[R"5nU$r�)rl�gethostname)rVs r>r\r\5s���!�!�#�H��Or=c�j�[R"U5S$![Ra gf=f�Nr)rl�
gethostbyaddr�herror)�ips r>r�r�:s3����#�#�B�'��*�*���=�=����s��2�2c��[U5$)z5determine if this url is resolvable (existing or ip).)r�)rus r>�is_resolvable_urlr�As
�����r=c���Ucg[RSU5 UH.n[U5(a[RSU5 Us $M0 g![a M@f=f)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')r[r�r�r�)�
candidates�cands  r>�search_for_mirrorr�Fsh��
����I�I�5�z�B���	� ��&�&��	�	�6��=���'�����	��	�s�'A�
A�Ac���/nU(d-[R"S5[R"S5-$URS5(aSURS5nSU-SU-4Vs/sH+n[RRU5(dM)UPM- nnU$US:Xa[R"S5nU$US:Xa[R"S5nU$s snf)Nz/dev/msdosfs/*z/dev/iso9660/*�LABEL=z
/dev/msdosfs/z
/dev/iso9660/�	TYPE=vfat�TYPE=iso9660)r&�
startswithrGr8r�r�)�criteria�oformat�tag�no_cacher��devlist�label�ps        r>�find_devs_with_freebsdr�Ys����G���y�y�)�*�T�Y�Y�7G�-H�H�H����8�$�$�����)��&��-���/F�G�
�G���w�w�~�~�a� �
�G�	�
��N�	
�[�	 ��)�)�,�-���N�
�^�	#��)�)�,�-���N��
s�*(C�Cc��/nSnSnSnU(aNURS5(aURS5nURS5(aURS5n[R"/SQS/S9n	U	RR	5Hnn
U(dU(a[R"SU
/SS/S9up�U(aS	U-U;aM>US
:XaSU;aMLUS:XaSU;aMZURS
U
-5 Mp U$)Nr�r�zTYPE=��sysctl�-nzhw.disknamesr��rcs�	mscdlabelr�z
label "%s"�iso9660zISO filesystem�vfat�/dev/)r�rGr rDr;r
)r�r�r�r�r�r�r��_type�
mscdlabel_outrF�devr)s            r>�find_devs_with_netbsdr�ms����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��}�%�"��Nr=c��[R"/SQS/S9n/nURR5RS5HinUR	S5(dMUS:XaM#URUSSS-5 UR
S	5(aMRURUSSS
-5 Mk UVs/sHnSU-PM
 sn$s snf)Nr�rr�rQrPzfd0:r%r�cd�ir�)r rD�rstripr;r0r
r�)	r�r�r�r�r�rFr�rsr�s	         r>�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��)�)��)s�5Cc�D�[R"/SQS/S9n[URR5SS9Vs/sH5nUR	S5(aMUR	S5(aM3UPM7 nnUS:Xa*UVs/sHofR	S	5(dMUPM nnOMUS
;a*UVs/sHofR	S	5(aMUPM nnOU(a[
R
SU5 UVs/sHnSU-PM
 sn$s snfs snfs snfs snf)
N)r�r�z
kern.disksrr�Tr,r��vnr�)r��acd)zLABEL=CONFIG-2r�zUnexpected criteria: %sr�)r r�rDr;r�r[r�)r�r�r�r�r�rFr�r�s        r>�find_devs_with_dragonflybsdr��s����)�)�2���
<�C���
�
�(�(�*�D�9��9�A��|�|�D�!�	
�*+�,�,�t�*<�	
�9����>�!�%�E�g����m�)D�1�g��E��	�4�	4�%�K�g��l�l�=�.I�1�g��K��	��	�	�+�X�6�!(�)��A�G�a�K��)�)����F��K��*s/�D�D�3D�D�"D�5D�D�<Dc�(�[5(a
[XX#U5$[5(a
[XX#U5$[	5(a
[XX#U5$[
5(a
[XX#U5$S/n/nU(aURSU-5 U(aURSU-5 U(aURSS/5 U(aURSU-5 U(aURU5 XV-n[R"USS/S	9up�/nUR5H-nUR5nU(dMURU5 M/ U$![Ra!n
U
R[:XaS
nSn
A
NteSn
A
ff=f)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)r<r�rCr�rFr�r@r�r
rr r^�errnorrXrE)
r�r�r�r�r��
blk_id_cmd�options�cmdrF�_errr�r*rbs
             r>�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�>E�F�0F�F�Fc�H�Uc/nO[U5n/SQnU(aURSS/5 URU5 [R"USSS9n0nURR	5H+nURS5upgn[
U5XF'XdUS'M- U$)	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)rCrorP�DEVNAME)r�rr rDrXrYri)	�devs�
disable_cacher�rF�retrbr�r)ras	         r>r�r��s����|����D�z��
!�C���
�
�D�+�&�'��J�J�t��
�)�)�C��i�
8�C�
�C��
�
�%�%�'���~�~�c�*����%�d�+���!�C����(�
�Jr=c�L�/nUHnX!;aM
URU5 M U$r�)r
)�in_list�out_listr�s   r>rr
s,���H�
���=���O�O�A��	�
�Or=��read_cbrrcr�rc	��[R"SSS9n[RSX5 U [R
"5n[
US5n[XTUS9 SSS5 UR5nSSS5 SSS5 [RS[W5XR5 U$!,(df   NZ=f![a U(deNqf=f!,(df   Nk=f!,(df   Nt=f)Nr��skip)�log_modezReading from %s (quiet=%s)r)�chunk_cbzReading %s bytes from %s%s)r�Timedr[r�rrr��pipe_in_outr��getvaluer�output)rcr�r�timer�ofh�ifhr"s       r>�load_binary_filer�s���
���b�6�2�E��I�I�*�E�9�	�
�Z�Z�\�S�
��%��&�#���7�;�'�
�|�|�~�H��
��I�I�*�C��M�5�,�,�O��O�'�&��$�
����
��	�\��
��sk�C+�C�C�B1�C�%C�5C+�1
B?�;C�>C�?C�C�C�C�C�
C(	�$C+�+
C9c�(�[[XUS95$)Nr�)rpr�)rcr�rs   r>r�r�)s���)�%��N�O�Or=c�$�[5(a#[S5nURSS5SSnU$[S5R
5nU$![a#n[RSU5 SnSnAU$SnAff=f![a SnU$f=f)Nz/proc/1/cmdline�r�r%z"failed reading /proc/1/cmdline: %sr�z
/proc/cmdline)�is_containerr�rr�r[r\rE)r"r?r�s   r>�_get_cmdliner�2s����~�~�	�%�&7�8�H��&�&�v�s�3�C�R�8�G��N�	�$�_�5�;�;�=�G��N���	��K�K�<�a�@��G��N��	���	��G��N�	�s(� A�A?�
A<�A7�7A<�?B�Bc�d�S[R;a[RS$[5$)N�DEBUG_PROC_CMDLINE)r8r�r�r<r=r>rErEEs&���r�z�z�)��z�z�.�/�/��>�r=c�p�Sn[U5R5nUS:H$![[4a gf=f)Nz/proc/sys/crypto/fips_enabledr+F)r�rErbr�)�	fips_procr"s  r>�fips_enabledr�LsB��/�I��!�)�,�2�2�4���3�����W����	�s�"�5�5c���SnURU5n[U5S:XaO0URU5 U[U5-
nU(aU"U5 MQUR5 U$r�)rr�write�flush)�in_fh�out_fh�
chunk_sizer��bytes_pipedras      r>r�r�Xsa���K�
��z�z�*�%���t�9��>�����T���s�4�y� ����[�!���L�L�N��r=c�z�US;aUS;ag[RSXU5 [R"XU5 g)N)Nr%z%Changing the ownership of %s to %s:%s)r[r�r8�chown)rc�uid�gids   r>�	chownbyidr�gs3��
�j��S�J�.���I�I�5�u�3�G��H�H�U��r=c��SnSnU(a [R"U5RnU(a [R"U5R
n[XU5 g![an[SU-5UeSnAff=f)Nr%zUnknown user or group: %s)	�pwd�getpwnam�pw_uidr�r�r�r�r�r�)rc�userr]r�r�r�s      r>�chownbynamer�oss��
�C�
�C�@���,�,�t�$�+�+�C���,�,�u�%�,�,�C��e�#����@��1�Q�7�8�a�?��@�s�AA!�!
A?�+A:�:A?r�r�c���SS/nU(aSU;aU$USnX;aX1nO
SU;aU$USn[U[5(aXD/n[U[5(a.[U5S:�aUSUS'[U5S:�aUSUS'[U[5(aSU;aUSUS'SU;aUSUS'USS:XaUSUS'/SQn[U5H�upgU(dMUR
5nS	n	UH@n
URU
5(dMU
<S
U[U
5SR5<3nSn	 O U	(dS<S
UR5<3nX�U'M� U$)
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�rrz&1)r�r�r�Fr�Tr�)	rmrnr�rr_�	enumeraterGr�rE)r�r�r��outcfg�modecfg�swlistr�r�rdrr�ss           r>r�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����Jr=c���/n/nU(a[U[5(dU$URS5nU(aURU5 [	US5H�nU(dM[
R"SU5nU(dM,URS5nUR5n[U5S:XaURU5 MoSS/USS:XdM|URUS5 M� UHan[R"US	35HAn	[RRU	5(dM)X�:wdM0URU	5 MC Mc [[X-55$)
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>.*)�targetr��teez-ar4�*)rmr_rjr
r�rWrXr]r;rr&r8r�r'r�rk)
r��logs�rotated_logs�default_log�fmtrXr��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��!�)���#�y�y�G�9�A��7�O��w�w�~�~�o�.�.�?�3M��#�#�O�4�	 8����D�'�(�)�)r=�routinec��[R"U5nUR[U55 UR	5nUbUSU$U$r�)�hashlib�new�updateru�	hexdigest)rhr�mlen�hasher�digests     r>�	hash_blobrsF��
�[�[��
!�F�
�M�M�+�d�#�$�
�
�
�
�F����a��~���
r=c�^�[R"U5(agg![a gf=fr�)r�r�r��rRs r>�is_userr�0����<�<��������������
,�,c�^�[R"U5(agg![a gf=fr�)r�r�r�rs r>�is_grouprrrc�\�[RSX5 [R"X5 g)NzRenaming %s to %s)r[r�r8�rename��src�dests  r>rr's���I�I�!�3�-��I�I�c�r=c�,�UHn[X!5 M gr�)�
ensure_dir)�dirlistr�rs   r>�ensure_dirsr-s��
���1��r=zLoading jsonc��[R"[U55n[U[	U55(dHSRUVs/sHn[
U5PM sn5n[SU<S[U5<S35eU$s snf)N�, �(z) root types expected, got r)	�json�loadsrprmr5r]rnrxry)rq�
root_types�decoded�t�expected_typess     r>�	load_jsonr)2sp���j�j��t�,�-�G��g�u�Z�0�1�1����J�#?�J�q�C��F�J�#?�@����t�G�}�
.�
�	
��N��$@s�	Bc���[RRU5nU[RRU5:XaU$[RRU5(aU$[	U5$)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>r,r,>sS���W�W�_�_�T�
"�F�
�������(�(���
�7�7�=�=�� � ��K�+�F�3�3r=c�@�[RRU5(d�[U5n[RR	U5nSnUS:XaSn[XVS9 [R"U5 SSS5 [X5 U(dU(ah[XBU5 [URU5SSS5n[U5nURH n	URU	5n[X�U5 M" gg[X5 g!,(df   N�=f)NTr�Fr�r�)
r8r�rr,r+r��makedirs�chmodr�r	r;r�joinpath)
r�r�r�r]�non_existed_parent_dir�dir_name�selinux_recursive�sub_relative_dir�sub_pathr�s
          r>rrOs���
�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�
Dc#�# �Uv� U(aSU/n[R"U5 gg!U(aSU/n[R"U5 ff=f7f)N�umount)r )r8�
umount_cmds  r>�	unmounterr:jsK���"����"�F�+�J��I�I�j�!���6�"�F�+�J��I�I�j�!��s�A�+�#A�$A�Ac�&�0n[RRS5(a[S5R	5nSnO2[
R
"S5nURR	5nSn[R"S5nUH�nUS:Xa(UR5n[U5S:waM*Uupxp�p�OwURU5n
U
b[U
R55S:aMdU
RS5nU
RS5nU
RS	5n	U
RS5n
URS
S5nU	UU
S.X'M� [R!S
X5 U$!["[$4a ['[S5 U$f=f)Nz/proc/mountsr��mountz*^(/dev/[\S]+) on (/.*) \((.+), .+, (.+)\)$�rir�r4raz\040r�)�fstype�
mountpoint�optszFetched %s mounts from %szFailed fetching mount points)r8r�r�r�rXr rDrW�compiler;r�search�groupsr]rr[r�rbr�r%)�mounted�
mount_locs�methodrF�mountre�mpline�wordsr��mpr>r@�_freq�_passno�ms              r>�mountsrNtsc���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� � ���G�L�'!�0	�	�	�-�w�?��N��
�W��4��s�2�3��N�4�s�E&E,�, F�Fc��[U[5(aU/nON[U[[45(a[U5nO'UcSnO![	SR[
U5S95e[5(aUcS/nOD[5(a2Uc/SQn[U5HupsUS:XaSXg'US;dMS	Xg'M OS
/n[5n[R"5n	Sn
[RRU5U;a&U[RRU5SnO�SnUH^nSn/S
Qn
U(aU
R!SU/5 U
R#U5 U
R#U	5 [$R$"X�S9 U	n
U	n O W(d[1SU<SU	<SU<35eUR3S5(dUS-
n[5U
5 Uc	U"U5nOU"X�5nUsSSS5 sSSS5 $![&[(4a=nU(a([*R-SUUSR/W
5U5 UnSnAGMSnAff=f!,(df   O=fSSS5 g!,(df   g=f)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)�ufs�cd9660�msdosr�rR)r��msdosfsrSr�Fr?)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�)rmrnr�r5rxr�ryr2r6r�rNr!�tempdirr8r�r�rr
r rbr�r[r�r]r�r0r:)�device�callbackra�mtype�update_env_for_mount�	log_error�mtypes�indexrD�tmpdr8r?�failure_reason�mountcmd�excr�s                r>�mount_cbrc�sG��"�%�������	�E�D�%�=�	)�	)��e���	�����D�K�K��5�k�
L�
�
�	
��z�z��>��X�F��	����>�/�F�%�f�-�L�E��	�!� (��
��+�+� '��
�	.�����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
�	�	�sQ�!AI+�7AH�AI+�I�-	I+�I
�1I�I+�I
�
I+�
I	�I+�+
I9c�6�[R"[5$r�)�obj_copy�deepcopyr&r<r=r>�get_builtin_cfgrg�s�����[�)�)r=c�l�[RSU5 [RR	U5$)NzTesting if a link exists for %s)r[r�r8r��islinkr�s r>�is_linkrjs$���I�I�/��6�
�7�7�>�>�$��r=c��[RSX5 U(a�[RR	U5(av[RR[RR
U5S[S5-5n[R"X5 [R"X15 g[R"X5 g)Nz$Creating symbolic link from %r => %r�tmpr�)
r[r�r8r�r�r]r+r��symlinkr)�source�link�force�tmp_links    r>�sym_linkrrsy���I�I�4�d�C��������&�&��7�7�<�<������� 5�u�x��{�7J�K��
�
�
�6�$�
�
�
�8�"���J�J�v�r=c�~�[RSU5 [R"U5 g![a gf=f)NzAttempting to remove %s)r[r�r8�unlinkr�r�s r>�del_filerus3���I�I�'��.�
�
�	�	�$����
��
�s�/�
<�<c�\�[RSX5 [R"X5 g)NzCopying %s to %s)r[r�r��copyrs  r>rwrws���I�I� �#�,�
�K�K��r=c��[R"S[R"55nU$![a SnU$f=f)Nz%a, %d %b %Y %H:%M:%S %z�??)�time�strftime�gmtimer�)�tss r>�time_rfc2822r~s@���
�]�]�5�t�{�{�}�
E���I����
��
�I��s�*.�>�>c�.^�SSKmSSKm"U4SjSTR5nTRTRRS55nTR
5nTRU5UlS[5(dSOS/nTRS	-"U6nU"5nURUTR[U55TRU5TRU5SS5S
:waURURS--$[!S5e)
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�R>�\rSrSrSYR4SYR4/rSrg)�boottime.<locals>.timevali7�tv_sec�tv_usecr<N)r�r�r�r��c_int64�_fields_r�)�ctypess�r>�timevalr�7s����v�~�~�.��F�N�N�0K�L�r=r��cr���Sr4r%g��.Az/Unable to retrieve kern.boottime on this system)r��ctypes.util�	Structure�CDLL�util�find_library�c_size_t�sizeof�valuerC�c_intr�r�byrefr�r��RuntimeError)r��libcr��
mib_values�mibrr�s      @r>�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�Ir=c�J�SnSn[RRS5(a)Sn[S5nU(aUR	5SnU$Sn[[R"5[5-
5nU$![a [[SU-5 U$f=f)Nryrvz/proc/uptimerr�z&Unable to read uptime using method: %s)r8r�r�r�r;rnrzr�r�r%r[)�
uptime_strrFr"s   r>�uptimer�Rs����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�AB�+B�B"�!B"c��[XSSS9 g)Nr�)�omoder���
write_file)r��contents  r>�append_filer�es���t�D�t�4r=)�
preserve_moder�c��[USSXS9 g)Nr�r�)r�r�r�r�r�)r�r�r�s   r>�ensure_filer�is����b��4�r=c�F�[U5$![[4a gf=fr�)r7rrx)�possible_ints r>�safe_intr�qs)����<� � ���	�"����s�

� � c��[U5nU(a3U(a+[U5 [R"X5 SSS5 ggg!,(df   g=fr�)r�r�r8r0)r�r��	real_modes   r>r0r0xs:�����I��	�
�$�
��H�H�T�%� �
��t�
�
�s�A�
A�grp_namec��Sn[R"U5RnU$![a [RSU5 U$f=f)zh
Returns the group id of a group name, or -1 if no group exists

@param grp_name: the name of the group
r%z"Group %s is not a valid group name)r�r�r�r�r[r�)r�r�s  r>�get_group_idr�sQ��
�C�B��l�l�8�$�+�+���J���B��	�	�6��A��J�B�s� &� A
�	A
r�c�j�[R"[R"U5R5$)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��[R"U5n[R"UR5R
$)zk
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��[R"U5n[R"UR5R
$)zk
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�8�/n[R"5H/nXR;dMURUR5 M1 [
R"U5RnUR[R"U5R5 U$)zd
Returns a list of all groups to which the user belongs

@param username: the user we want to check
)	r��getgrall�gr_memr
r�r�r��pw_gidr�)r�rCr]r�s    r>�get_user_groupsr��si���F�������|�|�#��M�M�%�-�-�(� ��,�,�x�
 �
'�
'�C�
�M�M�#�,�,�s�#�+�+�,��Mr=zWriting file)�ensure_dir_existsr�r]r�c	�h�U(a[U5nU(a'[[RRU5XgS9 SUR
5;a[U5nSnO
[U5nSnSU-n	[RSUUU	[U5U5 [US9 [X5n
U
RU5 U
R!5 S	S	S	5 S	S	S	5 [#X5 g	![a N�f=f![a SU-n	N�f=f!,(df   NG=f!,(df   NP=f)
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]�brs�
charactersz%oz%rzWriting to %s - %s: [%s] %s %sr�N)r�r�rr8r�r+r�rurprxr[r�rr�r�r�r�r0)rcr�r�r�r�r�r�r]�
write_type�mode_r�fhs           r>r�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�C-�2C=�#D#�/"D�D#�-
C:�9C:�=D�D�
D 	�D#�#
D1c���[R"U5H^n[RRX5n[RR	U5(a
[U5 MS[
U5 M` g)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]rr�ru)r+�node�
node_fullpaths   r>�delete_dir_contentsr��sL���
�
�7�#�������W�3�
�
�7�7�=�=��'�'��M�"��]�#�$r=c��[R"5n[U5nUSUR5<SU<3-
nUS[	5--
nU$)Nr�z by cloud-init v. z on %s)r$�version_stringrn�titler~)�comment_charr��ci_ver�headers    r>�make_headerr�	sE��
�
#�
#�
%�F�
��
�F�
�4�:�:�<��@�@�F�
�h���'�'�F��Mr=c	�j�[U[[45(d"[S[R
"U5-5eSnU(aUS-
nSS-nSnUH�n[U[[45(aW/nUH0nUR
S[U5RSU5-5 M2 U<S	RU5<S
3nUS-
nMu[U[5(aU<U<S
3nUS-
nM�UcM�[S[R
"U5<S
U<35e [RSU5 U$)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�rDr�zUnable to shellify type 'z&'. Expected list, string, tuple. Got: zShellified %s commands.)rmr5r�rxr"r�r
rnrr]r[r�)�cmdlist�
add_headerr��escaped�	cmds_mader��fixedr4s        r>�shellifyr�	s!���g��t�}�-�-��F��"�"�7�+�
-�
�	
�
�G���=� ���0�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��Nr=c��U(a$URU5(aU[U5SnU(a%URU5(aUS[U5*nU$r�)r�rr0)rb�prefix�suffixs   r>�strip_prefix_suffixr�9	sK��
�$�/�/�&�)�)��C��K�M�"��
�$�-�-��'�'��N�s�6�{�l�#���Kr=c��[R"US5cg[R"U5 g![Ra gf=f)NrFT)r �whichr^)r�s r>�_cmd_exits_zeror�A	sG���z�z�#�a�&��!����	�	�#�����%�%����s�4�A�
Ac��[/SQ5$)N)zsystemd-detect-virtz--quietz--container�r�r<r=r>�_is_container_systemdr�K	s���L�M�Mr=c��[S/5$)Nzlxc-is-containerr�r<r=r>�_is_container_old_lxcr�O	s���.�/�0�0r=c��[5(dg/SQn[R"US5cg[R"U5upUR5S:H$)NF)r�z-qnzsecurity.jail.jailedrr+)r<r r�rE)r�rFr)s   r>�_is_container_freebsdr�S	sG���<�<��
3�C��z�z�#�a�&��!��
�Y�Y�s�^�F�C��9�9�;�#��r=c�>�[[[4nUHnU"5(dM g [S5nSU;agSU;ag[RRS5(a%[RRS5(dg[S5R5nUHEnURS5(dMUR5RS	S5upVUS
:wdME g g![[
4a N�f=f![[
4a gf=f)z@
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_envrbr�r8r�rr�rXr�rEr;)�checks�helper�pid1env�linesrb�_keyrds       r>r�r�]	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:�C3�C3�2D	�&D	�.D	�0D	�3D�D�	D�Dc�@�[RRS5$)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=rl�errorsc�T�[RRS[U5S5n[	U5n0nSupgURX5nURU5H-nU(dMURUS5up�U	(dM)X�U	'M/ U$![
[4a 0s$f=f)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]rnr�rbr�ror;)�pidrlr�rr"�env�null�equalr�rRrds           r>r�r��	s���
�����g�s�3�x��	3�B��#�B�'��
�C��K�D����x�0�H��~�~�d�#�����i�i��q�)����4���I�$��J��
�W����	��s�B�B'�&B'c��0nUR5HnURSS5up4XAU'M U$![a UnSnNf=f)Nr�r�T)r;r)�kvstringr�r�rJrds     r>�keyval_str_to_dictr�	sZ��
�C��~�~���	����3��*�J�S��C��
 ��J��	�	��C��C�	�s�5�A�Ac�|�URS5(aUSSn[RRSU-5$)Nr��z/sys/class/block/%s/partition)r�r8r�r')rXs r>�is_partitionr�	s7��
����!�!������
�7�7�>�>�9�F�B�C�Cr=c���[U[5(dU/n/nUH�n[U[5(aURU5 M+[U[[45(aw[U5S:d[U5S:�a[
S5e[U5S:Xa)US(aURU[	U5-5 M�URUS5 M�[
S5e U$)Nr�r4z Invalid package & version tuple.rzInvalid package type.)rmr�rnr
r5rr�)�version_fmt�pkgs�pkglist�pkgs    r>�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�!�$�Nr=c��URS5Vs/sH
oD(dMUPM nnSnSnSnSn	[U5GHup�UR5n[U5S:a"URSU
S-[U5U5  gUSn
U
RS5Vs/sH
oD(dMUPM nn[U5[U5:�aM�[	[U5[U55nUSUUSU:waM�U	b[U	5[U5:�aM�URS5n
X�S-nX�S
-nU
nUn	USnGM U(a"U(aU(aU(aW(aXgUU4$gU(aU(aU(aXgU4$gs snfs snf![a URS	U
S-U5  gf=f![a URSU
S-U5  gf=f)
zNReturn the mount information for PATH given the lines from
/proc/$$/mountinfo.r�N�
z$Line %d has two few columns (%d): %sr�rir�-z,Did not find column named '-' in line %d: %sr4z/Too few columns after '-' column in line %d: %sr)r;r�rr��minr^r�
IndexError)r��mountinfo_lines�log�get_mnt_optsr��
path_elements�devpth�fs_type�match_mount_point�match_mount_point_elementsr�rbr�mount_point�mount_point_elements�x�
mount_optionss                 r>�parse_mount_infor�	s��!%�
�
�3��5��1�1�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:�
F�F�
F�*F�F�(F8� F5�4F5�8 G�Gc��[S5R5H$nUR5SSup#nX0:XdM X$U4s $ g)z<On older kernels there's no /proc/$$/mountinfo, so use mtab.�	/etc/mtabNra)r�rXr;)r�rbrrrs     r>�
parse_mtabr +
sG���{�+�6�6�8��'+�z�z�|�B�Q�'7�$��W����K�/�/�9�r=c��URS5n[U5S:XaUS$[U5S:XaUS$USS;asUSSn[R"/SQ5up4URS	5H4nUR5n[U5S:�dM$USU:XdM/USn O [U5$[RS
U5 g)Nr�r�rrar4)r��gpt�gptidrQ�ufsidr)�glabel�statusz-srDz)Unexpected input in find_freebsd_part: %s)r;rr rnr[r\)�fs�splitted�target_labelr�r��labelsrs       r>�find_freebsd_partr+4
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�����?��Dr=c���SnURS5HSnUR5n[U5S:�dM$[RR	USU-5(dMPUn U$ U$)NrDr4r�)r;rr8r�r�)r��mnt_list�
path_foundrbrs     r>�get_path_dev_freebsdr/G
s`���J����t�$���
�
����u�:��>�b�g�g�n�n�U�1�X��_�=�=��J����%�
�r=c��[R"SSU/SS/S9up[U5(a+[R"SS/5up2[X5nUcgUnUR5n[	US5nSU-$)Nr<z-prr�r�r�)r rr/r;r+)r�r{rgr-r.r��
label_parts       r>�get_freebsd_devpthr2Q
sx���I�I�w��d�3�!�Q��@�M�V�
�3�x�x��)�)�W�d�O�4���)�$�9�
������
�,�,�.�C�"�3�q�6�*�J��Z��r=c���[R"S/5up#SnURS5Vs/sH
oU(dMUPM nnSnSnSn	Sn
UR5GH�n[R"XK5nU(dM#URS5nURS5nURS5Vs/sH
oU(dMUPM n
n[
U
5[
U5:�aM�[[
U
5[
U55nU
SUUSU:waM�U
b[
U
5[
U
5:�aM�Un	U
n
URS5nURS	5nUbLS
RURS	5RS
5R5RS55n[RSUUUU5 [R"S
U5nU(d [5(aUS;a[U5nUnX�:XdGM� O U	(aX�;agU(a%W(aW(aU	(a
W(aUX�U4$ggggW(aW(aU	(aUX�4$gggs snfs snf)zReturn 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�Nrr?rryr�rQr!zNfound line in mount -> devpth: %s, mount_point: %s, fs_type: %s, options: '%s'z^(/dev/.+)[sp]([0-9])$)�zfs�nfs)r r;rXrWrBr]rrr]rEr[r�r<r2)r�r�mountoutputr��regexr�rrrrrrbrMrrrr�devm�match_devpths                   r>�parse_mountr:_
sQ���)�)�W�I�.��[�	C�
�
!%�
�
�3��5��1�1�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�
I�I�5
I"�I"c�8�S[R"5-n[RRU5(a%[	U5R5n[
XX5$[RRS5(a[U5$[X5$)Nz/proc/%s/mountinfor)	r8�getpidr�r�r�rXrr r:)r�rr�mountinfo_pathr�s     r>�get_mount_infor>�
sp��:*�B�I�I�K�7�N�	�w�w�~�~�n�%�%��~�.�9�9�;����S�?�?�	������	$�	$��$����4�.�.r=�optc�@�[USS9Gtp#XRS5;$)NT�rrQ�r>r;)r�r?r)�mnt_optss    r>�
has_mount_optrD�
s"��!�$�T�:�L�Q��.�.��%�%�%r=c�P�URSS5n[U5S:�aU$US4$)Nr3r�)�rsplitr)�dottedres  r>�expand_dotted_devnamerH�
s,���=�=��a� �D�
�4�y�1�}�����~�r=c��Uc/nUc/n/n0nX-Hn[X-U-SS9XV'M [U5(a'[	SRSR
U5S95eU$![a Xa;aURU5 MuMxf=f)NF�rzMissing required files: {files}rQ)�files)r�r�r
rrr�r])r��required�optional�delimrfr�r4s       r>�pathprefix2dictrO�
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�B�SSSSS.nSSSS	.n0n[U5R5HNnUR5upgnU(a[	U5X(-XF'M2Xc;dM9[	U5X(-XCU'MP U$![a UR5upgS
nN]f=f)N��r��@)�kB�mB�B�gB�total�free�	available)z	MemTotal:zMemFree:z
MemAvailable:rV)r�rXr;rr7)	�meminfo�raw�mpliers�kmapr�rbrJr��units	         r>�read_meminfor`s����%�a�u�=�G���$��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�A=�=B�Bc��UnURS5(aUSSnOURS5(aUSSnSSSS	S
S.nUnSnUH,nURU5(dMUnUS[U5*nM. [U5nUS:a[SU-5e[	X2U-5$![an[S
U-5UeSnAff=f)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
�iBN���rVr%r�rQrRrSl)rV�K�M�G�Trz'%s' is not valid input.z'%s': cannot be negative)r0r�floatrr7)r��size_inr]�num�mplierrMr�s       r>�human2bytesrls���"�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�V�_�$�%�%��
�F��3�g�=�>�A�E��F�s�9B(�(
C�2C�Cc��Uc[R"5SnUS:H=(d USS:H=(a USSS:HnU$)z$Return True if platform is x86-basedNri�x86_64rr�r4�86)r8r9)�
uname_arch�x86_arch_matchs  r>�is_x86rrEsM�����X�X�Z��]�
��8�+���1�
���7��A�B��4�!7���r=c�.�[R"U5$r�)�email�message_from_string)r�s r>ruruOs���$�$�V�,�,r=c�V�[R"SS/SS9n[5nURR5HXnUR	SS5up4nUR
S5(dM1UR[R"SSU55 MZ U$![
a Mkf=f)	Nz
dpkg-queryz--listTrBr4)�hi�iiz:.*r�)
r rkrDrXr;rr�rprW�sub)rF�	pkgs_instrb�stater
r)s      r>�get_installed_packagesr|Ss���
�)�)�\�8�,�d�
;�C���I��
�
�%�%�'��	�"�j�j��q�1�O�U�����L�)�)��M�M�"�&�&���C�0�1�
(�����	��	�s�B�
B(�'B(c��Sn[[USS95nURSS5R5S:Xag[5nSU;ag[S	SS9nSUR5;ag[RRS
5(agg![a n[
R
SX5 SnAN{SnAff=f)Nr`TrJrTr�zubuntu-corez!Unexpected error loading '%s': %sz
snap_core=z/etc/system-image/channel.iniz/etc/system-image/config.d/F)rir�rjr�rr[r\rEr8r�r)�orpath�orinfor�r?r�s     r>�system_is_snappyr�bs����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�7B�
B=�B8�8B=c�P�SnUR5H nURS5(dMUSSn O UcgURS5(aU$URS5(aSU[S5S-$URS5(aSU[S5SR5-$URS5(a^S	U[S5SR5-n[R
R
U5(aU$[U5nU(aUS
$U$SU-$)Nzroot=rr�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�)r?rrr��
disks_path�resultss     r>�rootdev_from_cmdliner�zs#���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��Sn0nU"U5H4nURSS5upgU(dUnU(d	U(dM0XtU'M6 U$)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�,�[R"USS9$)NT)�comments)�shlexr;)rhs r>�_shlex_split�(load_shell_content.<locals>._shlex_split�s���{�{�4�$�/�/r=r�r�)r;)r��	add_empty�	empty_valr�rarbrJr�s        r>riri�sL��0��D��W�%���Z�Z��Q�'�
����E������I�&��Kr=c	��[U5nSnU[UVs/sH+n[RRU5(dM)UPM- sn5-nU(d[RSUUU5 /$US:Xa[RSUUU5 XR-U:�aO[R"U5 XR-
nM�[RSX1U5 U$s snf)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)rkr8r�r�r[r�rz�sleep)�flist�maxwait�naplen�log_pre�need�waitedr4s       r>�wait_for_filesr��s����u�:�D�
�F�
����:��1������q�(9�Q��:�;�;����I�I�;����	
��I��Q�;��I�I�H����	
��?�W�$���
�
�6�����)�,�I�I�4�g����K��1;s�(C
�C
c�6�SnURSU/[S9 g)z-Helper to wait on completion of snap seeding.c��[R"S5(d[RS5 g[R"/SQ5 g)N�snapz+Skipping snap wait, no snap command present)r��waitr1zseed.loaded)r r�r[r�r<r=r>rY�&wait_for_snap_seeded.<locals>.callback�s.���z�z�&�!�!��I�I�C�D���	�	�;�<r=zsnap-seeded)�freqN)�runr')r]rYs  r>�wait_for_snap_seededr��s��=�
�I�I�m�X�r��I�9r=c�N�[USS9nUSRS5nUSS:H$)z1Check whether the given mount point is mounted rwTrAr%rQr�rwrB)rr{�
mount_optss   r>�mount_is_read_writer��s1��
�K�d�
;�F����!�!�#�&�J��a�=�D� � r=c�(�[R"S5(dgSS/nU(a:[RR	U5(agURSU-/5 U(aURSU-/5 [R"U5$)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��sx���:�:�i� � �	��X�&�J�
�
�7�7�>�>�&�!�!�����0�6�9�:�;�����>�G�3�4�5��9�9�Z� � r=rr(c�p�S/0n[R"[URS5SS95nSU;a/US'U$![a) [
R
SURS55 U$[Ra0n[
RS[RU5 SnAU$SnAff=f)N�scopeszhotplug.enabledFrJzFile not found: %sz>Ignoring contents of %s because it is not decodable. Error: %s)r#r$r�rr�r[r��JSONDecodeErrorr\r�HOTPLUG_ENABLED_FILE)rr�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�/B5�2B5�%B0�0B5c#�# �Sv� g7f)zlContext 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�rr
)z
/etc/hosts)NrXNFNr�)rQN)i�)NNN)NNNT)�)r�r�F)r`�created)T)r~r)z
/proc/meminfoF)FN)g�?r�)�rz�
contextlibrwrertr&r�rrrr#�loggingr8�os.pathr0r�r�rWr�r�rlr�r�r�r�rz�base64r�collectionsrrrr�r�	functoolsr�pathlibr	�typesr
�typingrrr
rrrrrrrrrrr�urllibrr�	cloudinitrrrrrrr r!r"r#r$�cloudinit.log.log_utilr%�cloudinit.settingsr&r'�cloudinit.helpersr(rj�	getLoggerr�r[�seprr�r�r	r�r�r?rGrOrnrsrpru�timedr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r
rr!r_r,r2r6r<r@rCrFrKrMrOr^rtr�r;r�r�r�r�r�r�r�r�r�r�r	r�r�r6r<rAr@rSrUr^rfr�r�r\r�r�r�r�r�r�r�r�r�r�PathLiker7r�r�r�rEr�r�r�r�r�rrrrrrr)r,rr:rNrcrgrjrrrur~r�r�r�r�r�r0r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr r+r/r2r:r>rDrHr�rOr`rlrrrur|r�r�rir�r�r�r�r�r�r<r=r>�<module>r�sp�������
���	���	���
�
�	��
�
��
��
����/��������� ������*�4��'���
����!���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�'�%�P4�n.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=

Filemanager

Name Type Size Permission Actions
__init__.cpython-313.pyc File 149 B 0644
apport.cpython-313.pyc File 9.96 KB 0644
atomic_helper.cpython-313.pyc File 4.39 KB 0644
cloud.cpython-313.pyc File 4.96 KB 0644
dmi.cpython-313.pyc File 9.85 KB 0644
event.cpython-313.pyc File 2.56 KB 0644
features.cpython-313.pyc File 1.85 KB 0644
gpg.cpython-313.pyc File 9.41 KB 0644
helpers.cpython-313.pyc File 21.72 KB 0644
importer.cpython-313.pyc File 2.82 KB 0644
lifecycle.cpython-313.pyc File 10.41 KB 0644
netinfo.cpython-313.pyc File 24.76 KB 0644
performance.cpython-313.pyc File 4.42 KB 0644
persistence.cpython-313.pyc File 3.04 KB 0644
registry.cpython-313.pyc File 1.86 KB 0644
safeyaml.cpython-313.pyc File 12.13 KB 0644
settings.cpython-313.pyc File 1.25 KB 0644
signal_handler.cpython-313.pyc File 5.39 KB 0644
simpletable.cpython-313.pyc File 3.36 KB 0644
socket.cpython-313.pyc File 7.08 KB 0644
ssh_util.cpython-313.pyc File 25.03 KB 0644
stages.cpython-313.pyc File 47.25 KB 0644
subp.cpython-313.pyc File 15.1 KB 0644
temp_utils.cpython-313.pyc File 3.96 KB 0644
templater.cpython-313.pyc File 9.34 KB 0644
type_utils.cpython-313.pyc File 755 B 0644
url_helper.cpython-313.pyc File 43.18 KB 0644
user_data.cpython-313.pyc File 13.78 KB 0644
util.cpython-313.pyc File 111.33 KB 0644
version.cpython-313.pyc File 576 B 0644
warnings.cpython-313.pyc File 4.48 KB 0644
Filemanager