%PDF- %PDF-
Mini Shell

Mini Shell

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

�

���f7���ddlZddlZddlZddlmZddlmZmZmZm	Z	m
Z
ddlmZddl
mZmZddlmZddlmZddlmZej,e�Zd	Zd
eiZdZdZd
diZdZGd�d�ZGd�dej@�Z!Gd�de!�Z"d�Z#d�Z$d1d�Z%d2d�Z&d�Z'e"ejPffe!ejPejRffgZ*d�Z+edk(r�ddl,Z,ddl-Z-ddlm.Z.e,j^d� �Z0e0jcd!d"d#e�$�e0jcd%d&d'd(d�)�e0je�Z3e&e3jhe3jj�*�Z6d+e6vr	e6d+jo�e6d+<e;ejxe6d.dd/�0��yy#e8$r=e-jrjud,�e6d+=e.e6d+�jo�e6d-<Y�_wxYw)3�N)�	b64decode)�dmi�net�sources�
url_helper�util)�ug_util)�
EventScope�	EventType)�NoDHCPLeaseError)�EphemeralDHCPv4)�DataSourceHostnamez3http://metadata.google.internal/computeMetadata/v1/�metadata_urlzLhttp://metadata.google.internal/computeMetadata/v1/instance/guest-attributes�hostkeyszMetadata-Flavor�Google�ens4c��eZdZd�Zdd�Zy)�GoogleMetadataFetcherc�.�||_||_||_y�N)�metadata_address�num_retries�sec_between_retries)�selfrrrs    �A/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceGCE.py�__init__zGoogleMetadataFetcher.__init__s�� 0���&���#6�� �c���d}	|j|z}|r|dz
}tj|t|j|j
��}|jdk(r@|r!tj|j�}|S|jjd�}|Stjd||j�|S#tj$r$}d}tj|||�Yd}~|Sd}~wwxYw)Nz/?recursive=True)�url�headers�retries�sec_between���utf-8zurl %s returned code %szurl %s raised exception %s)rr�readurl�HEADERSrr�coder�
decode_binary�contents�decode�LOG�debug�UrlError)	r�path�is_text�is_recursive�valuer�resp�exc�msgs	         r�	get_valuezGoogleMetadataFetcher.get_value$s�����	F��'�'�$�.�C���)�)���%�%����(�(� �4�4�	�D��y�y�C��� �.�.�t�}�}�=�E�
��!�M�M�0�0��9�E����	�	�3�T�4�9�9�E�����"�"�	&�.�C��I�I�c�4��%�%����	&�s�AB=�=C4�C/�/C4N)F)�__name__�
__module__�__qualname__rr5�rrrrs��7�
rrc��eZdZdZdZejejejhiZ
d�Zd�Ze
d��Zd�Zd�Zd�Zd
d	�Ze
d
��Ze
d��Zy)�
DataSourceGCE�GCEFc�z�tjj||||�d|_|r6t	j
||�\}}t	j|�\|_}t�|_tjtj|ddgi�tg�|_
|jd|_y)N�
datasourcer<r)r�
DataSourcer�default_userr	�normalize_users_groups�extract_default�dict�metadatar�
mergemanydict�get_cfg_by_path�BUILTIN_DS_CONFIG�ds_cfgr)r�sys_cfg�distro�paths�users�_groups�_user_configs       rrzDataSourceGCE.__init__Is������#�#�D�'�6�5�A� ����&�=�=�g�v�N��U�G�07�0G�0G��0N�-�T�
�����
��(�(��$�$�W�|�U�.C�R�H�!�
�
���!%���N� ;��rc
�j�|j�}|j�r;tj�}t|vr+|jt�|j
dt�tjd|�t|�dk\sJd��|D]�}t|j|��}	|5	tjtjdt|j|d���}	ddd�d
s�f||j_tjd|�n|jj$�Ytj'd|j(�n8tjtjdt|j|d���}d
s7|d
rtj'|d�ytj|d�y|d|_|d|_y#t $r*}tjd	||�Yd}~ddd���~d}~wwxYw#1swY��0xYw#t"$rY���wxYw)Nrz"Looking for the primary NIC in: %s�z3The instance has to have at least one candidate NIC)�ifacezCrawl of GCE metadata service)�address�
url_params)�kwargsz,Error fetching IMD with candidate NIC %s: %s�successzPrimary NIC found: %s.z(Did not find a fallback interface on %s.�platform_reports_gce�reasonF�	meta-data�	user-dataT)�get_url_params�perform_dhcp_setupr�find_candidate_nics�DEFAULT_PRIMARY_INTERFACE�remove�insertr+r,�lenr
rJr�log_time�read_mdr�	Exceptionr�fallback_interface�warning�
cloud_namerD�userdata_raw)rrS�candidate_nics�
candidate_nic�network_context�ret�es       r�	_get_datazDataSourceGCE._get_dataXs���(�(�*�
��"�"� �4�4�6�N�(�N�:��%�%�&?�@��%�%�a�)B�C��I�I�:�N�K��N�#�q�(�
E�D�
E�(�!/�
�
�"1��K�K�'�#���(�%�%�"&�-�-� #�	�	� ?� '�/3�/D�/D�2<�("�	#�C�%�(�y�>�5B�D�K�K�2��I�I�6�
�F��;
�<�{�{�-�-�5����>������-�-��	�	�/��#�4�4�",��	�C��9�~��)�*����C��M�*���	�	�#�h�-�(���K�(��
���,�����I )�%��I�I� N� -� !��
%�#%�%��%��%�%��$(����sT�-H%�/H�18G"�*H%�"	H�+H�H�H%�H�H�H"	�H%�%	H2�1H2c��yrr9�rs r�launch_indexzDataSourceGCE.launch_index�s��rc� �|jdS)N�instance-id�rDros r�get_instance_idzDataSourceGCE.get_instance_id�s���}�}�]�+�+rc�L�|jd}t||j�S)N�public-keys-data)rD�_parse_public_keysr@)r�public_keys_datas  r�get_public_ssh_keysz!DataSourceGCE.get_public_ssh_keys�s&���=�=�);�<��!�"2�D�4E�4E�F�Frc�"�|D]
}t|��yr)�#_write_host_key_to_guest_attributes)rr�keys   r�publish_host_keyszDataSourceGCE.publish_host_keys�s���	6�C�/��5�	6rc�X�t|jdjd�dd�S)N�local-hostname�.rF)rrD�split)r�fqdn�
resolve_ip�
metadata_onlys    r�get_hostnamezDataSourceGCE.get_hostname�s.��!��M�M�*�+�1�1�#�6�q�9�5�
�	
rc� �|jdS)N�availability-zonersros r�availability_zonezDataSourceGCE.availability_zone�s���}�}�0�1�1rc�@�|jjdd�dS)N�-rPr)r��rsplitros r�regionzDataSourceGCE.region�s ���%�%�,�,�S�!�4�Q�7�7rN)FFF)r6r7r8�dsnamer[r
�NETWORKr�BOOT_NEW_INSTANCE�BOOT�default_update_eventsrrm�propertyrprtryr}r�r�r�r9rrr;r;>s���
�F�������'�'��N�N�
���
<�@�D����,�G�6�
��2��2��8��8rr;c��eZdZdZy)�DataSourceGCELocalTN)r6r7r8r[r9rrr�r��s���rr�c��t�dt�d|��}|jd�}tj||t
dd��}|j
�rtjd|�ytjd|�y)N�/r$�PUTF)r�datar �request_method�check_statusz&Wrote %s host key to guest attributes.z0Unable to write %s host key to guest attributes.)	�GUEST_ATTRIBUTES_URL�HOSTKEY_NAMESPACE�encoderr%r&�okr+r,)�key_type�	key_valuerr2s    rr{r{�sg��,�.?��
J�C�� � ��)�I�����
�����D��w�w�y��	�	�:�H�E��	�	�D�h�Orc�n�	|jdd�dd\}}|dk7ry	tj|�}d|vry|d}d}	t
j
j
||�}t
j
j�|kDS#ttf$rYywxYw#t$rYywxYw#t$rYywxYw)N��Fz
google-ssh�expireOnz%Y-%m-%dT%H:%M:%S+0000)r��
ValueError�AttributeError�json�loads�datetime�strptime�utcnow)�
public_key�schema�json_str�json_obj�
expire_str�
format_str�expire_times       r�_has_expiredr��s����%�+�+�D�!�4�Q�R�8����
������:�:�h�'��
��!���*�%�J�)�J���'�'�0�0��Z�H��
���#�#�%��3�3��1
��'��������������s4�B�B� B(�B�B�	B%�$B%�(	B4�3B4c���g}|s|S|D]a}|rtd�|D��s�|jdd�}t|�dk7r�9|\}}|d|fvs�Et|�r�Q|j	|��c|S)Nc3�8K�|]}t|�dk���y�w)�N)�ord)�.0�cs  r�	<genexpr>z%_parse_public_keys.<locals>.<genexpr>�s����$F�a�S��V�c�\�$F�s��:rPr��	cloudinit)�allr�r`r��append)rxr@�public_keysr��split_public_key�userr|s       rrwrw�s���
�K����&�$�
���$F�:�$F�!F��%�+�+�C��3���� �A�%��$�	��c��K��.�.�|�C�7H����s�#�$��rTc��|�t}ddddd�}t�|d<|r|dsd|d<|Stj|�s tjd|�d|z|d<|Sgd�}t
||j|j�}i}|D]@\}}}	}
}d}|D]}
|j|
|
|�}|��|}�|	r|�d	}||z|d<|cS|||<�Btj|d
xsd�}tj|dxsd�}|jd
�|jd�g}|jdd�j�}|dk7rQ|jd
�s@|j|jd��|j|jd
��dj|D�cgc]}|s�|��	c}�}|j!�|d<|dr|dj#d�d|d<d|vrS|dj%d�}|jd�}|dk(rt'|�}n|rtj)d|�||d<||d<d|d<|Scc}w)NF)rXrYrUrWrVzNot running on GCE.rWz%s is not resolvablezaddress "%s" is not resolvable))rr)zinstance/idTTF)r�)z
instance/zoneTTF)r)zinstance/hostnameTTF)�
instance-data)zinstance/attributesFFT)�project-data)zproject/attributesFFTz)required key %s returned nothing. not GCEr�z{}r��sshKeyszssh-keyszblock-project-ssh-keys��true�
rvr�r����rYr$zuser-data-encoding�base64z(unknown user-data-encoding: %s, ignoringrXTrU)�	MD_V1_URLrVr�is_resolvable_urlr+r,rrrr5r�r��get�lowerr��join�
splitlinesr�r�rre)rRrS�platform_checkrk�url_map�metadata_fetcher�md�mkeyrK�requiredr/r0r1r.�	new_valuer4�
instance_data�project_data�
valid_keys�
block_projectr|rx�ud�encodings                        rrbrbs�����������	�C�#7�"8�C����c�"8�9�-��H�
��
��!�!�'�*��	�	�(�'�2�8�7�B��H�
��
��G�-���'�'��)G�)G���
�B�8?�
�4��e�X�w�����	"�D�(�2�2�4��,�O�I��$�!��	"���
�=�C��$�J�C��M��J���4��
��J�J�r�/�2�:�d�;�M��:�:�b��0�8�D�9�L��#�#�I�.�
�0A�0A�*�0M�N�J�!�%�%�&>��C�I�I�K�M����}�'8�'8��'C����,�*�*�:�6�7����,�*�*�9�5�6��y�y��!C�#�s�#�!C�D��-�8�8�:�B���	�
��"$�%8�"9�"?�"?��"D�R�"H�����m�#�
�;�
'�
.�
.�w�
7�� �$�$�%9�:���x���2��B�
��K�K�B�H�M���K���C����C�	�N��J��'"Ds�+I�3Ic���tjd�xsd}|dk(s|dk(rytjd�xsd}|jd�rytj	d||�y	)
Nzsystem-product-namezN/AzGoogle Compute EnginerTzsystem-serial-numberzGoogleCloud-z6Not running on google cloud. product-name=%s serial=%sF)r�
read_dmi_data�
startswithr+r,)�pname�serials  rrVrVPsl�����3�4�=��E��'�'�5�H�+<���
�
�5�
6�
?�%�F�
����(���I�I�@�%���rc�6�tj|t�Sr)r�list_from_depends�datasources)�dependss r�get_datasource_listr�hs���$�$�W�k�:�:r�__main__)�	b64encodezQuery GCE Metadata Service)�descriptionz
--endpoint�URLz The url of the metadata service.)�metavar�help�defaultz--no-platform-checkr�zIgnore smbios platform check�store_false)�destr��actionr�)rRr�rYz/User-data cannot be decoded. Writing as base64
z
user-data-b64rP)�,z: )�indent�	sort_keys�
separatorsr)NNT)=r�r��loggingr�rr�rrrrr�cloudinit.distrosr	�cloudinit.eventr
r�cloudinit.net.dhcpr�cloudinit.net.ephemeralr
�cloudinit.sourcesr�	getLoggerr6r+r�rGr�r�r&r]rr?r;r�r{r�rwrbrV�DEP_FILESYSTEM�DEP_NETWORKr�r��argparse�sysr��ArgumentParser�parser�add_argument�
parse_args�args�endpointr�r�r*�UnicodeDecodeError�stderr�write�print�dumpsr9rr�<module>rs��
����9�9�%�1�/�3�0��g����!��A�	�#�Y�/��#�����h�
'��"����@x8�G�&�&�x8�v���
P� 4�D�(J�Z
�$�'�0�0�2�3��W�+�+�W�-@�-@�A�B���;��z���� �
$�X�
$�
$�1M�
N�F�
�����
/��	������
�
+���������D��4�=�=��9L�9L�M�D��d��	J� $�[� 1� 8� 8� :�D���
�*�$�*�*�T�!�t��
L�M�G��6"�	J��J�J���B�
��[�!�$-�d�;�.?�$@�$G�$G�$I�D��!�
	J�s�F�?G�G

Zerion Mini Shell 1.0