BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/cloudinit/sources/__pycache__/DataSourceRbxCloud.cpython-36.pyc
3

�q�hU�@s�dZddlZddlZddlZddlZddlmZddlmZ	ddlm
Z
mZmZddl
mZmZe	je�ZdZdd	�Zeed
�dd�Zejed
�dd�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�}|r tjd�dStjd�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)Zhosts�r�(/usr/lib/python3.6/DataSourceRbxCloud.py�get_manage_etc_hostss

r)�inc�returncCstttt|��|��S)N)�strr�int)�addrrrrr�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)rrrr�
get_three_ips'srcCstjdg|�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)�cmdrrr�_sub_arp4srcCs�d}|jdkrd}xh|D]`}ytdd||d|d	g�Wqtjk
rv}ztjd
|d|d	|�WYdd}~XqXqWdS)Nz-S�fedora�centos�rhelz-sz-c�2�source�destinationz&Failed to arping from "%s" to "%s": %s)rrr)�namerrZProcessExecutionErrorrZwarning)�items�distroZsource_param�item�errorrrr�gratuitous_arp=s

r'cCs�ttjd�tjd��}|s dSx�|D]z}y"tj|tdddgd�}|rJ|SWq&tk
r|}z|jtjkrl�WYdd}~Xq&tjk
r�tj	t
d	|�Yq&Xq&Wt
jd
dj|��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�errno�ENOENTZMountFailedError�logexcrr
�join)Zdevicesr(�rbx_data�errrrr�get_mdRs,
r4cCsddd�t|�D�d�S)z�Generate network configuration

    @param netadps: A list of network adapter settings

    @returns: A dict containing network config
    �csBg|]:\}�ddjt|���dj��fdd��dD�d��qS)Zphysicalzeth{}Z
macaddressc	s>g|]6}d|d�ddd�dd�dddd��qS)	Zstatic�address�network�netmask�auto�gatewayZdnsZnameservers)�typer6r8Zcontrolr:Zdns_nameserversr)�.0�ip)�netadprr�
<listcomp>�s
z6generate_network_config.<locals>.<listcomp>.<listcomp>r=)r;r"Zmac_addressZsubnets)�formatr�lower)r<�ir)r>rr?{sz+generate_network_config.<locals>.<listcomp>)�version�config)�	enumerate)Znetadpsrrr�generate_network_configqsrFc
Cstjtjtjj|d�dd�d�}tjtjj|d�dd�}d|ksHd	|krXtjtd
�dS|jdi�jd
�}|jdi�jdg�}d}|jdi�jd�r�|ddd}t	|d	�}||dd|ddgd�dd�|d	D�ddd||dg|d|d�i|t
�d�d�}tjd�tj|�|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)rGr	Zvmr>z(Failed to load metadata. Invalid format.NZadditionalMetadata�usernameZsshKeysZpasswordZsha512Z_idr")zinstance-idzlocal-hostnamezpublic-keyscSs>g|]6}|dD](}t|dd�D]}|d|d��q$qqS)r=r7r:r6)r r!)r)r<r>r=�targetrrrr?�sz+read_user_data_callback.<locals>.<listcomp>Zdefault_userzALL=(ALL) NOPASSWD:ALL)r"ZgecosZsudoZpasswdZlock_passwdZssh_authorized_keys)Z
ssh_pwauthZdisable_rootZsystem_info�network_configZmanage_etc_hosts)�userdata�metadatar'�cfgzreturning DATA object:)rZ	load_jsonr
�os�pathr1r0r�getrFrr
)Z	mount_dirZ	meta_dataZ	user_datarJZssh_keys�hashr7�datarrrr,�sD	




r,c@sjeZdZdZejejejej	hiZ
dd�Zdd�Zdd�Z
edd	��Zd
d�Zdd
�Zdd�Zdd�ZdS)�DataSourceRbxCloudZRbxCloudcCstjj||||�d|_dS)N)r�
DataSource�__init__�seed)�selfZsys_cfgr$�pathsrrrrW�szDataSourceRbxCloud.__init__cCstjj|�}d||jfS)Nz%s [seed=%s])rrV�__str__rX)rY�rootrrrr[�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.
        FrMrNr'rOT)r4�userdata_rawrNr'rO)rYr2rrr�	_get_data�s



zDataSourceRbxCloud._get_datacCs
|jdS)NrL)rO)rYrrrrL�sz!DataSourceRbxCloud.network_configcCs
|jdS)Nzpublic-keys)rN)rYrrr�get_public_ssh_keys�sz&DataSourceRbxCloud.get_public_ssh_keyscCs|jS)N)r])rYrrr�get_userdata_raw�sz#DataSourceRbxCloud.get_userdata_rawcCs|jS)N)rO)rYrrr�get_config_obj�sz!DataSourceRbxCloud.get_config_objcCst|j|j�dS)N)r'r$)rYrOZis_new_instancerrr�activateszDataSourceRbxCloud.activateN)�__name__�
__module__�__qualname__ZdsnamerZNETWORKrZBOOT_NEW_INSTANCEZBOOTZBOOT_LEGACYZdefault_update_eventsrWr[r^�propertyrLr_r`rarbrrrrrU�s
rUcCstj|t�S)N)rZlist_from_depends�datasources)Zdependsrrr�get_datasource_listsrh)$�__doc__r.rPZos.pathZtypingZ	ipaddressrZ	cloudinitrZloggingrrrZcloudinit.eventrrZ	getLoggerrcrrrrrrZListrrr'r4rFr,rVrUZDEP_FILESYSTEMrgrhrrrr�<module>s*
	
	!B3