%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__/DataSourceCloudStack.cpython-312.pyc

�

�f�,��8�ddlZddlZddlZddlmZddlmZmZmZddl	m
Z
ddlmZm
Z
ddlmZddlmZddlmZdd	lmZej*e�ZGd
�d�ZGd�d
ej2�Zd�Zd�Zd�Zeej<ej>ffgZ d�Z!y)�N)�suppress)�gaierror�getaddrinfo�	inet_ntoa)�pack)�sources�subp)�
url_helper)�util)�dhcp)�ec2c�"�eZdZdZd�Zd�Zd�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_request.sf���I�I�������#���#�*�*�<�8��!�!�$�"=�"=�>�
�
�	����|�|�~�rc�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_passwordCsG���#�#�$6�7���-�-���}�$��N�O�O����)�*��rN)�__name__�
__module__�__qualname__�__doc__rr!r)�rrrrs��	�=��*rrc�f��eZdZdZdZdZd�Zd�Z			d�fd�	Zd�Z	d�Z
d	�Zd
�Ze
d��Z�xZS)
�DataSourceCloudStack�
CloudStack�x�2c�\�tjj||||�tjj|jd�|_d|_||_t|j�|_
|jstd��d|j�d�|_i|_
y)N�cs�latestzNo virtual router found!zhttp://�/)r�
DataSourcer�os�path�join�seed_dir�api_ver�distro�get_vr_address�vr_addrr'�metadata_address�cfg)r�sys_cfgr>�pathss    rrzDataSourceCloudStack.__init__Us������#�#�D�'�6�5�A������U�^�^�T�:��
� ������%�d�k�k�2����|�|��9�:�:�")�$�,�,��q� 9�����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_leaser>�dhcp_client�client_name�FileNotFoundError�get_newest_lease�fallback_interface�get)r�
domainname�domain_name�latest_leases    r�_get_domainnamez$DataSourceCloudStack._get_domainnamecs7��	�	�	�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)	�super�get_hostname�hostnamerGrHrVr�DataSourceHostname�
is_default)r�fqdn�
resolve_ip�
metadata_onlyr[rS�	__class__s      �rrZz!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_urlrA�time�wait_for_url�timeout_secondsrG�warningrH�critical�int�bool)r�
url_paramsrc�
start_time�url�	_responses      r�wait_for_metadata_servicez.DataSourceCloudStack.wait_for_metadata_service�s����(�(�*�
��&�&�!�+��
����%�%�'E�
�
��
�Y�Y�[�
��+�+���0�0��.�.��k�k�	
���Y���I�I�3�S�9��C�y��
�L�L�$���D�I�I�K�*�,�-�	
��C�y�rc��|jSr)rB�rs r�get_config_objz#DataSourceCloudStack.get_config_obj�s���x�x�rc�d�i}tj||jdz��r5|d|_|d|_t
j
d|j�y	|j�sytj�}tj|j|j�|_tj|j|j�|_t
j
dttj�|z
��t|j �}	|j#�}|r
d|d	did
�|_y#t&$r(tj(t
d|j �YywxYw#t&$r(tj(t
d|j�YywxYw)
Nr7)�basez	user-dataz	meta-dataz%Using seeded cloudstack data from: %sTFz)Crawl of metadata service took %s seconds�expire)�
ssh_pwauthr(�chpasswdz/Failed to fetch password from virtual router %sz(Failed fetching from metadata service %s)r�read_optional_seedr<�userdata_raw�metadatarGrHrvrkr
�get_instance_userdatar=rA�get_instance_metadatarprr@r)rB�	Exception�logexc)r�seed_retrs�password_client�set_passwords     r�	_get_datazDataSourceCloudStack._get_data�s|�����"�"�8�4�=�=�3�3F�H� (�� 5�D��$�[�1�D�M��I�I�=�t�}�}�M��'	��1�1�3������J� #� 9� 9����d�3�3�!�D�� �5�5����d�3�3��D�M�
�I�I�;��D�I�I�K�*�,�-�
�=�T�\�\�J�O�
�.�;�;�=�� �&*�$0�$�e�%� �D�H����
�����E��L�L���
�� �	��K�K��:��%�%�
�
�
	�s=�E>�.B;E>�*E
�:E>�
.E;�8E>�:E;�;E>�>.F/�.F/c� �|jdS)Nzinstance-id�r�rxs r�get_instance_idz$DataSourceCloudStack.get_instance_id�s���}�}�]�+�+rc� �|jdS)Nzavailability-zoner�rxs r�availability_zonez&DataSourceCloudStack.availability_zone�s���}�}�0�1�1r)FFF)r*r+r,�dsname�url_max_wait�url_timeoutrrVrZrvryr�r��propertyr��
__classcell__)ras@rr0r0MsX���
�F��L��K��(�X���	�8�>�.�`,��2��2rr0c�z�	tdd�}|dddS#t$rtjd�YywxYw)Nzdata-server�Pr�zDNS Entry data-server not found)rrrGrH)�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�splitrrrprGrH)�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_leaseszdhcp-server-identifierz&Found SERVER_ADDRESS '%s' via dhclientz1Found SERVER_ADDRESS '%s' via ephemeral %s lease z$No DHCP found, using default gateway)r�rGrHrrIrrJrKrLrOrMrPrNr�)r>�latest_addressrUs   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�Ec�6�tj|t�Sr)r�list_from_depends�datasources)�dependss r�get_datasource_listr�Rs���$�$�W�k�:�:r)"�loggingr9rk�
contextlibr�socketrrr�structr�	cloudinitrr	r
rir�
cloudinit.netr�cloudinit.sources.helpersr
�	getLoggerr*rGrr8r0r�r�r?�DEP_FILESYSTEM�DEP_NETWORKr�r�r.rr�<module>r�s����	���3�3��#�)���)��g����!��+�+�\s2�7�-�-�s2�l!�
�-!�d�G�2�2�G�4G�4G�H�I���;r

Zerion Mini Shell 1.0