HEX
Server: nginx/1.24.0
System: Linux webserver 6.8.0-87-generic #88-Ubuntu SMP PREEMPT_DYNAMIC Sat Oct 11 09:28:41 UTC 2025 x86_64
User: wpuser (1002)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceCloudStack.cpython-312.pyc
�

쑛hv3���ddlZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
mZmZmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZej8e�ZdZGd
�d�Z Gd�dejB�Z"Gd�de"�Z#d�Z$d�Z%d�Z&de'fd�Z(e#ejRffe"ejRejTffgZ+d�Z,y)�N)�suppress)�gaierror�getaddrinfo�	inet_ntoa)�pack)�dmi�net�performance�sources�subp)�
url_helper)�util)�dhcp)�NoDHCPLeaseError)�EphemeralIPNetwork)�ec2�
CloudStackc�P�eZdZdZd�Zd�Zejdd��d��Zy)	�CloudStackPasswordServerClienta�
    Implements password fetching from the CloudStack password server.

    http://cloudstack-administration.readthedocs.org/
       en/latest/templates.html#adding-password-management-to-your-templates
    has documentation about the system.  This implementation is following that
    found at
    https://github.com/shankerbalan/cloudstack-scripts/
       blob/master/cloud-set-guest-password-debian
    c��||_y�N)�virtual_router_address)�selfrs  �H/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudStack.py�__init__z'CloudStackPasswordServerClient.__init__/s
��&<��#�c��tjddddddddd	d
j|�dj|j�g�\}}|j�S)N�wgetz--quietz--tries�3z	--timeout�20z--output-document�-z--headerzDomU_Request: {0}z{0}:8080)r�formatr�strip)r�domu_request�output�_s    r�_do_requestz*CloudStackPasswordServerClient._do_request2sf���I�I�������#���#�*�*�<�8��!�!�$�"=�"=�>�
�
�	����|�|�~�rzGetting password�always��log_modec�t�|jd�}|dvry|dk(rtd��|jd�|S)N�send_my_password)��saved_password�bad_requestz-Error when attempting to fetch root password.r.)r'�RuntimeError)r�passwords  r�get_passwordz+CloudStackPasswordServerClient.get_passwordGsG���#�#�$6�7���-�-���}�$��N�O�O����)�*��rN)	�__name__�
__module__�__qualname__�__doc__rr'r
�timedr2�rrrr#s5��	�=��*�[���)�H�=��>�rrc���eZdZdZdZdZdZ�fd�Zd�Z			d�fd�	Z	d�Z
d	�Zed
e
fd��Zd�Zej"d
d��d��Zd�Zed��Z�xZS)�DataSourceCloudStackFr�x�2c���t�|�|||�tjj	|j
d�|_d|_i|_y)N�cs�latest)�superr�os�path�join�seed_dir�api_ver�cfg)r�sys_cfg�distro�paths�	__class__s    �rrzDataSourceCloudStack.__init__Zs>���
����&�%�0������U�^�^�T�:��
� �����rc���tjd�tjd�}|r|Stjd�t	tj
�5tj�j|jd�}|r|cddd�S	ddd�tjd|jjj�t	t�5|jjj|jj�}|jd�xsd}|cddd�S#1swY��xYw#1swYnxYwtjd�y)z�
        Try obtaining a "domain-name" DHCP lease parameter:
        - From systemd-networkd lease
        - From dhclient lease
        z.Try obtaining domain name from networkd leases�
DOMAINNAMEzHCould not obtain FQDN from networkd leases. Falling back to ISC dhclientzdomain-nameNzBCould not obtain FQDN from ISC dhclient leases. Falling back to %szNo dhcp leases found)�LOG�debugr�networkd_get_option_from_leasesr�NoDHCPLeaseMissingDhclientError�IscDhclient�get_key_from_latest_leaserH�dhcp_client�client_name�FileNotFoundError�get_newest_lease�fallback_interface�get)r�
domainname�domain_name�latest_leases    r�_get_domainnamez$DataSourceCloudStack._get_domainnamebs7��	�	�	�B�C��9�9�,�G�
�����	�	�
+�	
��d�:�:�
;�	#��*�*�,�F�F����]��K��"�	#�	#��		#�	�	�	�
!��K�K�#�#�/�/�	
��'�
(�	��;�;�2�2�C�C����.�.��L�'�*�*�=�9�A�T�K��	�	�	#�	#��	�	��	�	�	�(�)�s�2D?�%AE�?E�Ec�R��t�|�|||�}|r�d|jvr�tj	d�|j�}|rG|j�d|��}tj	d|�t
j||j�Stj	d|�|S)z�
        Returns instance's hostname / fqdn
        First probes the parent class method.

        If fqdn is requested, and the parent method didn't return it,
        then attach the domain-name from DHCP response.
        �.zFQDN requestedzObtained the following FQDN: %szNCould not determine domain name for FQDN. Fall back to hostname as an FQDN: %s)	r@�get_hostname�hostnamerMrNr\r�DataSourceHostname�
is_default)r�fqdn�
resolve_ip�
metadata_onlyr`rYrJs      �rr_z!DataSourceCloudStack.get_hostname�s�����7�'��j�-�H���C�x�0�0�0��I�I�&�'��-�-�/�J��"�+�+�,�A�j�\�:���	�	�;�T�B��1�1�$��8K�8K�L�L��I�I�7��
�
�rc���|j�}|jdkrytj|jd�g}tj�}tj||j|jtj��\}}|r!tjd|�t|�Stjd|ttj�|z
��t|�S)NrFzlatest/meta-data/instance-id)�urls�max_wait�timeout�	status_cbzUsing metadata source: '%s'z>Giving up on waiting for the metadata from %s after %s seconds)�get_url_params�max_wait_seconds�uhelp�combine_url�metadata_address�time�	monotonic�wait_for_url�timeout_secondsrM�warningrN�critical�int�bool)r�
url_paramsrg�
start_time�url�	_responses      r�wait_for_metadata_servicez.DataSourceCloudStack.wait_for_metadata_service�s����(�(�*�
��&�&�!�+��
����%�%�'E�
�
��
�^�^�%�
��+�+���0�0��.�.��k�k�	
���Y���I�I�3�S�9��C�y��
�L�L�$���D�N�N�$�z�1�2�	
��C�y�rc��|jSr)rF�rs r�get_config_objz#DataSourceCloudStack.get_config_obj�s���x�x�r�returnc��t�S)z#Check if running on this datasource)�is_platform_viabler8rr�	ds_detectzDataSourceCloudStack.ds_detect�s
��"�#�#rc�|�i}tj||jdz��r5|d|_|d|_t
j
d|j�y|jrAtj�}t
j
d|�t|j|�}ntj�}	|5t|j�}t|t�r|j!d�n||_|j"st%d	��d
|j"�d�|_|j)�s
	ddd�y|j+�cddd�S#1swYyxYw#t,$rt
j/d�Yyt0$r)}t
j/d
t3|��Yd}~yd}~wwxYw)N�/)�basez	user-dataz	meta-dataz%Using seeded cloudstack data from: %sTzAttempting DHCP on: %s�dhcp-server-identifierzNo virtual router found!zhttp://Fz#Unable to obtain a DHCP lease on %sz$Failed fetching metadata service: %s)r�read_optional_seedrD�userdata_raw�metadatarMrN�perform_dhcp_setupr	�find_fallback_nicrrH�nullcontext�get_vr_address�
isinstance�dictrX�vr_addrr0ror|�_crawl_metadatarrt�	Exception�str)r�seed_ret�primary_nic�network_contextr��es      r�	_get_datazDataSourceCloudStack._get_data�su�����"�"�8�4�=�=�3�3F�H� (�� 5�D��$�[�1�D�M��I�I�=�t�}�}�M���"�"��/�/�1�K��I�I�.��<�0����k�J�O�"�.�.�0�O�	� �
.�(����5��"�'�4�0��K�K� 8�9� ���
�|�|�&�'A�B�B�*1�$�,�,��q�(A��%��5�5�7� �
.�
.��+�+�-�
.�
.�
.�� �	��K�K�=�{�K���	��K�K�>��A��G���	�sI�>E)�A;E�;E)�E�	E)�E&�"E)�&E)�)F;�
F;�F6�6F;zCrawling metadatar(r)c��tj|j|j�|_tj
|j|j�|_t|j�}	|j�}|r
d|ddid�|_
y#t$r(tjtd|j�YywxYw)NT�expireF)�
ssh_pwauthr1�chpasswdz/Failed to fetch password from virtual router %s)r�get_instance_userdatarEror��get_instance_metadatar�rr�r2rFr�r�logexcrM)r�password_client�set_passwords   rr�z$DataSourceCloudStack._crawl_metadata�s����5�5��L�L�$�/�/�
����1�1��L�L�$�/�/�
��
�9����F��	�*�7�7�9�L��"&� ,� �%�!�������	��K�K��A����
��	�s�5B�.C�Cc� �|jdS)Nzinstance-id�r�r~s r�get_instance_idz$DataSourceCloudStack.get_instance_ids���}�}�]�+�+rc� �|jdS)Nzavailability-zoner�r~s r�availability_zonez&DataSourceCloudStack.availability_zones���}�}�0�1�1r)FFF)r3r4r5r��dsname�url_max_wait�url_timeoutrr\r_r|r�staticmethodrwr�r�r
r7r�r��propertyr��
__classcell__)rJs@rr:r:Rs������
�F��L��K��(�X���	�8�>��$�t�$��$�"�H�[���*�X�>��?��8,��2��2rr:c��eZdZdZdZy)�DataSourceCloudStackLocalauRun in init-local using a dhcp discovery prior to metadata crawl.

    In init-local, no network is available. This subclass sets up minimal
    networking with dhclient on a viable nic so that it can talk to the
    metadata service. If the metadata service provides network configuration
    then render the network configuration for that instance based on metadata.
    TN)r3r4r5r6r�r8rrr�r�s����rr�c�z�	tdd�}|dddS#t$rtjd�YywxYw)Nzdata-server�Pr�zDNS Entry data-server not found)rrrMrN)�addrinfos r�get_data_serverr�$sI��!��}�b�1��
��{�1�~�a� � ��	���	�	�3�4���s��:�:c
��tjd�j�}|D]W}|jd�}|ddk(s�t	tdt
|dd���}tjd|�|cSy)	Nz/proc/net/route�	��00000000z<L��z"Found default route, gateway is %s)	r�load_text_file�
splitlines�splitrrrvrMrN)�lines�line�items�gws    r�get_default_gatewayr�/sz����� 1�2�=�=�?�E�����
�
�4� ����8�z�!��4��c�%��(�B�&7�8�9�B��I�I�:�B�?��I�
�rc���t�}|rtjd|�|Stjd�}|rtjd|�|Sttj�5tj�j|d�}|r!tjd|�|cddd�S	ddd�tt�5|jj|�}|r6tjd||jj�|cddd�S	ddd�tjd�t�S#1swY��xYw#1swY�4xYw)Nz4Found metadata server '%s' via data-server DNS entry�SERVER_ADDRESSz-Found SERVER_ADDRESS '%s' via networkd_leasesr�z&Found SERVER_ADDRESS '%s' via dhclientz1Found SERVER_ADDRESS '%s' via ephemeral %s lease z$No DHCP found, using default gateway)r�rMrNrrOrrPrQrRrUrSrVrTr�)rH�latest_addressr[s   rr�r�<sF��%�&�N���	�	�B��	
����9�9�:J�K�N���	�	�;�^�	
���

�$�6�6�	7�"��)�)�+�E�E��,�
����I�I�>��O�!�
"�"��	"�
�#�	$� ��)�)�:�:�6�B����I�I�C���"�"�.�.�
�
 � � �� ��I�I�4�5�� � �)"�"�� � �s�->E	�
A
E�	E�Er�c��tjd�}|stjd�y|j	t
�S)Nzsystem-product-namez-system-product-name not available in dmi dataF)r�
read_dmi_datarMrN�
startswith�CLOUD_STACK_DMI_NAME)�product_names rr�r�ls8���$�$�%:�;�L���	�	�A�B���"�"�#7�8�8rc�6�tj|t�Sr)r�list_from_depends�datasources)�dependss r�get_datasource_listr�|s���$�$�W�k�:�:r)-�loggingrArp�
contextlibr�socketrrr�structr�	cloudinitrr	r
rrr
rmr�
cloudinit.netr�cloudinit.net.dhcpr�cloudinit.net.ephemeralr�cloudinit.sources.helpersr�	getLoggerr3rMr�r�
DataSourcer:r�r�r�r�rwr��DEP_FILESYSTEM�DEP_NETWORKr�r�r8rr�<module>r�s����	���3�3��:�:�)���/�6�)��g����!��#��,�,�^C2�7�-�-�C2�L	� 4�	�!�
�-!�`9�D�9���!7�!7� 9�:��G�2�2�G�4G�4G�H�I���;r