HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceRbxCloud.cpython-38.pyc
U

Ӈgg�@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZddlm
Z
mZe�e�ZdZdd�Zeed	�d
d�Zejed�d
d�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�de	j�Zee	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)�sources�subp�util)�
EventScope�	EventTypez
/etc/hostscCs.tjtdd�}|r t�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_text_file�	ETC_HOSTS�LOG�debug)Zhosts�r
�F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceRbxCloud.py�get_manage_etc_hostss

r)�inc�returncCstttt|��|��S�N)�strr�int)�addrrr
r
r�increment_ip#sr)rcCs|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)rr
r
r�
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
    Zarping)r)�cmdr
r
r�_sub_arp4srcCs|d}|jdkrd}|D]`}ztdd||d|dg�Wqtjk
rt}zt�d|d|d|�W5d}~XYqXqdS)	Nz-S)ZfedoraZcentosZrhelz-sz-c�2�source�destinationz&Failed to arping from "%s" to "%s": %s)�namerrZProcessExecutionErrorrZwarning)�items�distroZsource_param�item�errorr
r
r�gratuitous_arp=s
��r$cCs�tt�d�t�d��}|s dS|D]�}z(tj|tdddgd�}|rN|WSWq$tk
r�}z|jtjkrp�W5d}~XYq$tjk
r�t�	t
d	|�Yq$Xq$t
�d
d�|��dS)zAReturns False (not found or error) or a dictionary with metadata.z
LABEL=CLOUDMDz
LABEL=cloudmdFZvfatZfatZmsdosfs)�device�callbackZmtypeNz-Failed to mount %s when looking for user dataz0Did not find RbxCloud data, searched devices: %s�,)
�setrZfind_devs_withZmount_cb�read_user_data_callback�OSError�errnoZENOENTZMountFailedError�logexcrr�join)Zdevicesr%�rbx_data�errr
r
r�get_mdRs<�����r0cCsddd�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)Zphysicalzeth{}Z
macaddressc	s>g|]6}d|d�ddd�dd�dddd��qS)	Zstatic�address�network�netmask�auto�gatewayZdnsZnameservers)�typer2r4Zcontrolr6Zdns_nameserversr
)�.0�ip��netadpr
r�
<listcomp>s�


��z6generate_network_config.<locals>.<listcomp>.<listcomp>r9)r7rZmac_addressZsubnets)�formatr�lower)r8�ir
r:rr<zs�

��z+generate_network_config.<locals>.<listcomp>)�versionZconfig)�	enumerate)Znetadpsr
r
r�generate_network_configqs
��rBc
Cstjtjtj�|d�d�d�}tjtj�|d�dd�}d|ksFd|krVt�td	�d
S|�	di��	d�}|�	di��	d
g�}d
}|�	di��	d�r�|ddd}t
|d�}||dd|ddgd�dd�|dD�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.json)�fname)�textz	user.dataT)rCrZvmr;z(Failed to load metadata. Invalid format.NZadditionalMetadata�usernameZsshKeysZpasswordZsha512Z_idr)zinstance-idzlocal-hostname�public-keyscSs>g|]6}|dD](}t|dd�D]}|d|d��q$qqS)r9r3r6r2)rr)r)r8r;r9�targetr
r
rr<�s
�z+read_user_data_callback.<locals>.<listcomp>Zdefault_userzALL=(ALL) NOPASSWD:ALLF)rZgecosZsudoZpasswdZlock_passwdZssh_authorized_keys)Z
ssh_pwauthZdisable_rootZsystem_info�network_configZmanage_etc_hosts)�userdata�metadatar$�cfgzreturning DATA object:)
rZ	load_jsonZload_binary_file�os�pathr-r	r,r�getrBrr)Z	mount_dirZ	meta_dataZ	user_datarEZssh_keys�hashr3�datar
r
rr)�sT	��

����
��

r)c@sjeZdZdZejejejej	hiZ
dd�Zdd�Zdd�Z
edd	��Zd
d�Zdd
�Zdd�Zdd�ZdS)�DataSourceRbxCloudZRbxCloudcCs(tj�||||�d|_d|_d|_dSr)r�
DataSource�__init__�seedr$rK)�selfZsys_cfgr!�pathsr
r
rrS�szDataSourceRbxCloud.__init__cCstj�|�}d||jfS)Nz%s [seed=%s])rrR�__str__rT)rU�rootr
r
rrW�szDataSourceRbxCloud.__str__cCs>t�}|dkrdS|d|_|d|_|d|_|d|_dS)zw
        Metadata is passed to the launching instance which
        is used to perform instance configuration.
        FrIrJr$rKT)r0�userdata_rawrJr$rK)rUr.r
r
r�	_get_data�s



zDataSourceRbxCloud._get_datacCs
|jdS)NrH�rK�rUr
r
rrH�sz!DataSourceRbxCloud.network_configcCs
|jdS)NrF)rJr\r
r
r�get_public_ssh_keys�sz&DataSourceRbxCloud.get_public_ssh_keyscCs|jSr)rYr\r
r
r�get_userdata_raw�sz#DataSourceRbxCloud.get_userdata_rawcCs|jSrr[r\r
r
r�get_config_obj�sz!DataSourceRbxCloud.get_config_objcCst|j|j�dSr)r$r!)rUrKZis_new_instancer
r
r�activateszDataSourceRbxCloud.activateN)�__name__�
__module__�__qualname__ZdsnamerZNETWORKrZBOOT_NEW_INSTANCEZBOOTZBOOT_LEGACYZdefault_update_eventsrSrWrZ�propertyrHr]r^r_r`r
r
r
rrQ�s ��
rQcCst�|t�Sr)rZlist_from_depends�datasources)Zdependsr
r
r�get_datasource_listsrf)#�__doc__r+ZloggingrL�os.path�typingZ	ipaddressrZ	cloudinitrrrZcloudinit.eventrrZ	getLoggerrarr
rrrrZListrrr$r0rBr)rRrQZDEP_FILESYSTEMrerfr
r
r
r�<module>s,
	
	!@5
�