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__/DataSourceScaleway.cpython-310.pyc
o

�Ad�%�@s*ddlZddlZddlZddlZddlZddlmZddlmZddl	m
Z
ddl	mZddl	m
Z
mZmZmZddlmZmZddlmZdd	lmZdd
lmZe�e�ZdZeded
edd�ZdZdZ dd�Z!Gdd�dej"j#�Z$dd�Z%dd�Z&Gdd�dej'�Z(e(ej)ffgZ*dd�Z+dS)�N)�HTTPConnection)�PoolManager)�dmi)�log)�net�sources�
url_helper�util)�
EventScope�	EventType)�NoDHCPLeaseError)�EphemeralDHCPv4)�DataSourceHostnamezhttp://169.254.42.42z/conf?format=jsonz/user_data/cloud-initz/vendor_data/cloud-init)�metadata_url�userdata_url�vendordata_url��
cCs>t�d�}|dkrdStj�d�rdSt��}d|vrdSdS)a
    There are three ways to detect if you are on Scaleway:

    * check DMI data: not yet implemented by Scaleway, but the check is made to
      be future-proof.
    * the initrd created the file /var/run/scaleway.
    * "scaleway" is in the kernel cmdline.
    zsystem-manufacturer�ScalewayTz/var/run/scaleway�scalewayF)r�
read_dmi_data�os�path�existsr	�get_cmdline)�vendor_name�cmdline�r�F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceScaleway.py�on_scaleway)s
	rcs*eZdZdZ�fdd�Zddd�Z�ZS)�SourceAddressAdapterzF
    Adapter for requests to choose the local address to bind to.
    cs ||_tt|�jdi|��dS)Nr)�source_address�superr �__init__)�selfr!�kwargs��	__class__rrr#EszSourceAddressAdapter.__init__FcCs0tjtjtjdfg}t||||j|d�|_dS)N�)�	num_pools�maxsize�blockr!�socket_options)r�default_socket_options�socket�
SOL_SOCKET�SO_REUSEPORTrr!�poolmanager)r$�connectionsr*r+r,rrr�init_poolmanagerIs��z%SourceAddressAdapter.init_poolmanager)F)�__name__�
__module__�__qualname__�__doc__r#r3�
__classcell__rrr&rr @sr c
Cs^ztj|d|d|dd�d�}t�|j�WStjy.}z
|jdkr)WYd}~dS�d}~ww)aQ
    Retrieve user data or vendor data.

    Scaleway user/vendor data API returns HTTP/404 if user/vendor data is not
    set.

    This function calls `url_helper.readurl` but instead of considering
    HTTP/404 as an error that requires a retry, it considers it as empty
    user/vendor data.

    Also, be aware the user data/vendor API requires the source port to be
    below 1024 to ensure the client is root (since non-root users can't bind
    ports below 1024). If requests raises ConnectionError (EADDRINUSE), the
    caller should retry to call this function on an other port.
    NrcSs|jdko
t|jtjj�S)N�)�code�
isinstance�cause�requests�
exceptions�ConnectionError)�_�excrrr�<lambda>qs
z%query_data_api_once.<locals>.<lambda>)�data�timeout�retries�session�exception_cbr9)r�readurlr	�
decode_binary�contents�UrlErrorr:)�api_addressrD�requests_session�resprArrr�query_data_api_onceVs �
��rOc	Cs�tdt|d��D]K}z(t�d||�t��}|�dtd|fd��t|||d�}t�d|�|WSt	j
yS}zt�d	||�t�
d
�|}WYd}~qd}~ww|�)a/Get user or vendor data.

    Handle the retrying logic in case the source port is used.

    Scaleway metadata service requires the source port of the client to
    be a privileged port (<1024).  This is done to ensure that only a
    privileged user on the system can access the metadata service.
    r(�z*Trying to get %s data (bind on port %d)...zhttp://z0.0.0.0)r!)rDrMz%s-data downloadedz%Error while trying to get %s data: %srN)�range�max�LOG�debugr=�Session�mountr rOrrK�warning�time�sleep)	�api_typerLrErD�portrMrCrA�last_excrrr�query_data_api~s.���

��r]cs�eZdZdZejejejej	hiZ
�fdd�Zdd�Zdd�Z
edd	��Zed
d��Zdd
�Zdd�Zddd�Zedd��Zedd��Z�ZS)�DataSourceScalewayrcs�tt|��|||�t�t�|ddgi�tg�|_|jd|_|jd|_	|jd|_
t|j�dt
��|_t|j�dt��|_d|_tj|_dS)N�
datasourcerrrrrErD)r"r^r#r	�
mergemanydict�get_cfg_by_path�BUILTIN_DS_CONFIG�ds_cfg�metadata_address�userdata_address�vendordata_address�int�get�DEF_MD_RETRIESrE�DEF_MD_TIMEOUTrD�_fallback_interfacer�UNSET�_network_config)r$�sys_cfg�distro�pathsr&rrr#�s��zDataSourceScaleway.__init__cCsZtj|j|j|jd�}t�t�|j	��|_
td|j|j|j�|_
td|j|j|j�|_dS)N)rDrEz	user-datazvendor-data)rrHrdrDrE�json�loadsr	rIrJ�metadatar]re�userdata_rawrf�vendordata_raw)r$rNrrr�_crawl_metadata�s��
�z"DataSourceScaleway._crawl_metadatac
Cs�t�sdS|jdurt��|_z)t|j|j��d��tjt	j
d|jd�Wd�WdS1s1wYWdStyS}zt�
t	t|��WYd}~dSd}~ww)NF)�tmp_dirzCrawl of metadata service)�logfunc�msg�funcT)rrkr�find_fallback_nicr
ro�get_tmp_exec_pathr	�log_timerSrTrvr�logexc�str)r$�errr�	_get_data�s.

�������zDataSourceScaleway._get_datac	Cs�|jdurt�dtj�tj|_|jtjkr|jS|jdur#t��|_dd|jd�}ddig}|jdrY|d	d|jdd
d|jdddd
d|jddd�gd�g7}||d<d|gd�|_|jS)z`
        Configure networking according to data received from the
        metadata API.
        Nz5Found None as cached _network_config. Resetting to %s�physicalz%s)�type�namer��dhcp4�ipv6�static�address�netmaskz::�0�gateway)�network�prefixr�)r�r�r��routes�subnetsr()�version�config)	rmrSrWrrlrkrr{rs)r$�netcfgr�rrr�network_config�s6
�



����z!DataSourceScaleway.network_configcC�dS�Nr�r$rrr�launch_index�zDataSourceScaleway.launch_indexcCs
|jdS)N�id)rsr�rrr�get_instance_ids
z"DataSourceScaleway.get_instance_idcCs^dd�|jdD�}d}t|�}|j�dg�D]}|�|�sq|�|d|��dd��q|S)NcSsg|]}|d�qS)�keyr)�.0r�rrr�
<listcomp>sz:DataSourceScaleway.get_public_ssh_keys.<locals>.<listcomp>�ssh_public_keyszAUTHORIZED_KEY=�tagsr@� )rs�lenrh�
startswith�append�replace)r$�ssh_keys�akeypre�plen�tagrrr�get_public_ssh_keyss
z&DataSourceScaleway.get_public_ssh_keysFcCst|jdd�S)N�hostnameF)rrs)r$�fqdn�
resolve_ip�
metadata_onlyrrr�get_hostnameszDataSourceScaleway.get_hostnamecCr�r�rr�rrr�availability_zone!r�z$DataSourceScaleway.availability_zonecCr�r�rr�rrr�region%r�zDataSourceScaleway.region)FFF)r4r5r6�dsnamer
�NETWORKr�BOOT_NEW_INSTANCE�BOOT�BOOT_LEGACY�default_update_eventsr#rvr��propertyr�r�r�r�r�r�r�r8rrr&rr^�s,��

'


r^cCst�|t�Sr�)r�list_from_depends�datasources)�dependsrrr�get_datasource_list/sr�),rqrr.rXr=�urllib3.connectionr�urllib3.poolmanagerr�	cloudinitrr�loggingrrrr	�cloudinit.eventr
r�cloudinit.net.dhcpr�cloudinit.net.ephemeralr
�cloudinit.sourcesr�	getLoggerr4rS�DS_BASE_URLrbrirjr�adapters�HTTPAdapterr rOr]�
DataSourcer^�DEP_FILESYSTEMr�r�rrrr�<module>s>
�(&
�