HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceCloudStack.cpython-310.pyc
o

�Adj'�@s�ddlZddlZddlmZmZmZddlmZddlm	Z
ddlmZmZddlm
ZddlmZddlmZdd	lmZe
�e�ZGd
d�d�ZGdd
�d
ej�Zdd�Zdd�Zdd�Zddd�Zdd�Zeejej ffgZ!dd�Z"dS)�N)�gaierror�getaddrinfo�	inet_ntoa)�pack)�log)�sources�subp)�
url_helper)�util)�dhcp)�ec2c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�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
    cCs
||_dS�N)�virtual_router_address)�selfr�r�H/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudStack.py�__init__*�
z'CloudStackPasswordServerClient.__init__cCs:t�ddddddddd	d
�|�d�|j�g�\}}|��S)N�wgetz--quietz--tries�3z	--timeout�20z--output-document�-z--headerzDomU_Request: {0}z{0}:8080)r�formatr�strip)r�domu_request�output�_rrr�_do_request-s
��z*CloudStackPasswordServerClient._do_requestcCs4|�d�}|dvrdS|dkrtd��|�d�|S)N�send_my_password)��saved_password�bad_requestz-Error when attempting to fetch root password.r!)r�RuntimeError)r�passwordrrr�get_passwordBs

z+CloudStackPasswordServerClient.get_passwordN)�__name__�
__module__�__qualname__�__doc__rrr%rrrrr
s
r
c@sLeZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
edd��ZdS)�DataSourceCloudStack�
CloudStack�x�2cCsXtj�||||�tj�|jd�|_d|_t�|_	|j	s t
d��d|j	f|_i|_dS)N�cs�latestzNo virtual router found!z
http://%s/)
r�
DataSourcer�os�path�join�seed_dir�api_ver�get_vr_address�vr_addrr#�metadata_address�cfg)r�sys_cfg�distro�pathsrrrrTs
zDataSourceCloudStack.__init__cCs�|��}|jdkrdSt�|jd�g}t��}tj||j|jtj	d�\}}|r1t�
d|�t
|�St�d|tt��|��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_urlr8�time�wait_for_url�timeout_seconds�LOG�warning�debug�critical�int�bool)r�
url_paramsr=�
start_time�url�	_responserrr�wait_for_metadata_service`s.
��
�	��z.DataSourceCloudStack.wait_for_metadata_servicecCs|jSr)r9�rrrr�get_config_objsz#DataSourceCloudStack.get_config_objcCsi}tj||jdd�r|d|_|d|_t�d|j�dSzV|��s'WdSt��}t	�
|j|j�|_t	�
|j|j�|_t�dtt��|��t|j�}z|��}Wntygt�td	|j�YWdSw|rsd|d
did�|_WdSty�t�td|j�YdSw)
N�/)�basez	user-dataz	meta-dataz%Using seeded cloudstack data from: %sTFz)Crawl of metadata service took %s secondsz/Failed to fetch password from virtual router %s�expire)�
ssh_pwauthr$�chpasswdz(Failed fetching from metadata service %s)r
�read_optional_seedr4�userdata_raw�metadatarHrJrRrEr�get_instance_userdatar5r8�get_instance_metadatarLr
r7r%�	Exception�logexcr9)r�seed_retrO�password_client�set_passwordrrr�	_get_data�s\

���
������zDataSourceCloudStack._get_datacC�
|jdS)Nzinstance-id�r\rSrrr�get_instance_id�rz$DataSourceCloudStack.get_instance_idcCre)Nzavailability-zonerfrSrrr�availability_zone�s
z&DataSourceCloudStack.availability_zoneN)
r&r'r(�dsname�url_max_wait�url_timeoutrrRrTrdrg�propertyrhrrrrr*Ls0r*cCs>ztdd�}Wntyt�d�YdSw|dddS)Nzdata-server�PzDNS Entry data-server not foundr�)rrrHrJ)�addrinforrr�get_data_server�s
�rpcCs^t�d���}|D]#}|�d�}|ddkr,ttdt|dd���}t�d|�|Sq	dS)	Nz/proc/net/route�	��00000000z<L��z"Found default route, gateway is %s)	r
�	load_file�
splitlines�splitrrrLrHrJ)�lines�line�items�gwrrr�get_default_gateway�s
�r}cCsHgd�}|D]}tj�|�r!tt�|��dkr!t�d|�|SqdS)N)z/var/lib/dhclientz
/var/lib/dhcpz/var/lib/NetworkManagerrzUsing %s lease directory)r1r2�exists�len�listdirrHrJ)�supported_dirs�drrr�get_dhclient_d�s�r�cCs�|durt�}|sdSt�|�}d}d}|D](}|�d�rq|�d�s)|�d�s)qtj�||�}tj�|�}||kr>|}|}q|S)N����	dhclient6z.leasez.leases)r�r1r��
startswith�endswithr2r3�getmtime)�lease_d�lease_files�latest_mtime�latest_file�fname�abs_path�mtimerrr�get_latest_lease�s&


�r�cCs�t�}|r
t�d|�|St�d�}|rt�d|�|St�}|s)t�d�t�St|d��+}|D] }d|vrQ|�d��	d�}t
|�d	krQ|d	}t�d
|�|}q1Wd�n1s\wY|skt�d�t�S|S)Nz4Found metadata server '%s' via data-server DNS entry�SERVER_ADDRESSz-Found SERVER_ADDRESS '%s' via networkd_leasesz*No lease file found, using default gateway�rzdhcp-server-identifierz ;
� rtzFound DHCP identifier %sz$No DHCP found, using default gateway)rprHrJr�networkd_get_option_from_leasesr�r}�openrrxr)�latest_address�
lease_file�fdrz�words�dhcptokrrrr6s@�
�
���
r6cCst�|t�Sr)r�list_from_depends�datasources)�dependsrrr�get_datasource_list3sr�r)#r1rE�socketrrr�structr�	cloudinitr�loggingrrr	rCr
�
cloudinit.netr�cloudinit.sources.helpersr�	getLoggerr&rHr
r0r*rpr}r�r�r6�DEP_FILESYSTEM�DEP_NETWORKr�r�rrrr�<module>s*
.n
!-�