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

�AdU�@s�dZddlZddlZddlZddlZddlmZddlmZ	ddlm
Z
mZmZddl
mZmZe	�e�ZdZdd	�Zd
edefdd
�Zdejefdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�de
j�Z e e
j!ffgZ"dd�Z#dS)zr
This file contains code used to gather the user data passed to an
instance on rootbox / hyperone cloud platforms
�N)�IPv4Address)�log)�sources�subp�util)�
EventScope�	EventTypez
/etc/hostscCs.tjtdd�}|rt�d�dSt�d�dS)NT)�quietz5/etc/hosts exists - setting manage_etc_hosts to FalseFz=/etc/hosts does not exists - setting manage_etc_hosts to True)r�	load_file�	ETC_HOSTS�LOG�debug)�hosts�r�F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceRbxCloud.py�get_manage_etc_hostss

r�inc�returncCstttt|��|��S�N)�strr�int)�addrrrrr�increment_ip#srcCs|t|d�t|d�gS)z�Return a list of 3 IP addresses: [addr, addr + 2, addr + 3]

    @param addr: an object that is passed to IPvAddress
    @return: list of strings
    ��)r)rrrr�
get_three_ips's�rcCst�dg|�S)z�
    Uses the preferred cloud-init subprocess def of subp.subp
    and runs arping.  Breaking this to a separate function
    for later use in mocking and unittests
    �arping)r)�cmdrrr�_sub_arp4srcCs|d}|jdvr	d}|D]0}ztdd||d|dg�Wqtjy;}zt�d|d|d|�WYd}~qd}~wwdS)	Nz-S)�fedora�centos�rhelz-sz-c�2�source�destinationz&Failed to arping from "%s" to "%s": %s)�namerr�ProcessExecutionErrorr�warning)�items�distro�source_param�item�errorrrr�gratuitous_arp=s$
�����r-cCs�tt�d�t�d��}|sdS|D]>}ztj|tgd�d�}|r&|WSWqty@}z
|jtjkr6�WYd}~qd}~wtjyPt�	t
d|�Yqwt
�dd	�|��dS)
zAReturns False (not found or error) or a dictionary with metadata.z
LABEL=CLOUDMDz
LABEL=cloudmdF)�vfat�fat�msdosfs)�device�callback�mtypeNz-Failed to mount %s when looking for user dataz0Did not find RbxCloud data, searched devices: %s�,)
�setr�find_devs_with�mount_cb�read_user_data_callback�OSError�errno�ENOENT�MountFailedError�logexcrr
�join)�devicesr1�rbx_data�errrrr�get_mdRs>���
�����
�rBcCsddd�t|�D�d�S)z�Generate network configuration

    @param netadps: A list of network adapter settings

    @returns: A dict containing network config
    �csBg|]\}�dd�t|���d���fdd��dD�d��qS)�physicalzeth{}�
macaddressc	s>g|]}d|d�ddd�dd�dddd��qS)	�static�address�network�netmask�auto�gateway�dns�nameservers)�typerGrI�controlrK�dns_nameserversr)�.0�ip��netadprr�
<listcomp>s�


���z6generate_network_config.<locals>.<listcomp>.<listcomp>rR)rNr%�mac_address�subnets)�formatr�lower)rQ�irrSrrUzs�

���z+generate_network_config.<locals>.<listcomp>)�version�config)�	enumerate)�netadpsrrr�generate_network_configqs
��r_c
Cstjtjtj�|d�dd�d�}tjtj�|d�dd�}d|vs$d	|vr,t�td
�dS|�di��d
�}|�di��dg�}d}|�di��d�rR|ddd}t	|d	�}||dd|ddgd�dd�|d	D�ddd||dg|d|d�i|t
�d�d�}t�d�t�|�|S)aThis callback will be applied by util.mount_cb() on the mounted
    drive.

    @param mount_dir: String representing path of directory where mounted drive
    is available

    @returns: A dict containing userdata, metadata and cfg based on metadata.
    z
cloud.jsonF)�fname�decode)�textz	user.dataT)r`r	�vmrTz(Failed to load metadata. Invalid format.N�additionalMetadata�username�sshKeys�password�sha512�_idr%)zinstance-idzlocal-hostname�public-keyscSs>g|]}|dD]}t|dd�D]	}|d|d��qqqS)rRrHrKrG)r#r$)r)rQrTrR�targetrrrrU�s���
�z+read_user_data_callback.<locals>.<listcomp>�default_userzALL=(ALL) NOPASSWD:ALL)r%�gecos�sudo�passwd�lock_passwd�ssh_authorized_keys)�
ssh_pwauth�disable_root�system_info�network_config�manage_etc_hosts)�userdata�metadatar-�cfgzreturning DATA object:)r�	load_jsonr
�os�pathr>r=r�getr_rr
)�	mount_dir�	meta_data�	user_datare�ssh_keys�hashrH�datarrrr8�sV	���

����
��

r8c@sjeZdZdZejejejej	hiZ
dd�Zdd�Zdd�Z
edd	��Zd
d�Zdd
�Zdd�Zdd�ZdS)�DataSourceRbxCloud�RbxCloudcCstj�||||�d|_dSr)r�
DataSource�__init__�seed)�self�sys_cfgr)�pathsrrrr��s
zDataSourceRbxCloud.__init__cCstj�|�}d||jfS)Nz%s [seed=%s])rr��__str__r�)r��rootrrrr��szDataSourceRbxCloud.__str__cCs>t�}|dur	dS|d|_|d|_|d|_|d|_dS)zw
        Metadata is passed to the launching instance which
        is used to perform instance configuration.
        Frwrxr-ryT)rB�userdata_rawrxr-ry)r�r@rrr�	_get_data�s



zDataSourceRbxCloud._get_datacC�
|jdS)Nru�ry�r�rrrru�s
z!DataSourceRbxCloud.network_configcCr�)Nrj)rxr�rrr�get_public_ssh_keys�s
z&DataSourceRbxCloud.get_public_ssh_keyscC�|jSr)r�r�rrr�get_userdata_raw��z#DataSourceRbxCloud.get_userdata_rawcCr�rr�r�rrr�get_config_obj�r�z!DataSourceRbxCloud.get_config_objcCst|j|j�dSr)r-r))r�ry�is_new_instancerrr�activateszDataSourceRbxCloud.activateN)�__name__�
__module__�__qualname__�dsnamer�NETWORKr�BOOT_NEW_INSTANCE�BOOT�BOOT_LEGACY�default_update_eventsr�r�r��propertyrur�r�r�r�rrrrr��s"��
r�cCst�|t�Sr)r�list_from_depends�datasources)�dependsrrr�get_datasource_listsr�)$�__doc__r:r{�os.path�typing�	ipaddressr�	cloudinitr�loggingrrr�cloudinit.eventrr�	getLoggerr�rrrrrr�Listrrr-rBr_r8r�r��DEP_FILESYSTEMr�r�rrrr�<module>s.
	
	!B
3�