/usr/lib/python3/dist-packages/cloudinit/sources/__pycache__
Edit: /usr/lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceRbxCloud.cpython-310.pyc (7552B)
o
thg @ s d Z ddlZddlZddlZddlZddlZddlmZ ddlm Z m
Z
mZ ddlm
Z
mZ eeZdZdd Zd ed
efddZd
eje fd
dZdd Zdd Zdd Zdd Zdd ZG dd de jZee 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)sourcessubputil)
EventScope EventTypez
/etc/hostsc C s. t jtdd} | rtd dS td 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_HOSTSLOGdebug)hosts r F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceRbxCloud.pyget_manage_etc_hosts s
r increturnc C s t ttt| | S N)strr int)addrr r r r increment_ip# s r c C s | t | dt | dgS )zReturn 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 )r r r r
get_three_ips' s r c C s t 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 )cmdr r r _sub_arp4 s r c C s| d}|j dv r d}| D ]0}ztdd||d |d g W q tjy; } ztd|d |d | W Y d }~qd }~ww d S ) Nz-S)fedoracentosrhelz-sz-c2sourcedestinationz&Failed to arping from "%s" to "%s": %s)namer r ProcessExecutionErrorr warning)itemsdistrosource_paramitemerrorr r r gratuitous_arp= s$
r, c C s t tdtd } | sdS | D ]>}ztj|tg dd}|r&|W S W q ty@ } z
|jtjkr6 W Y d}~qd}~w tjyP t t
d| Y qw t
dd | dS )
zAReturns False (not found or error) or a dictionary with metadata.z
LABEL=CLOUDMDz
LABEL=cloudmdF)vfatfatmsdosfs)devicecallbackmtypeNz-Failed to mount %s when looking for user dataz0Did not find RbxCloud data, searched devices: %s,)
setr find_devs_withmount_cbread_user_data_callbackOSErrorerrnoENOENTMountFailedErrorlogexcr r join)devicesr0 rbx_dataerrr r r get_mdR s>
rA c C s ddd t | D dS )zGenerate network configuration
@param netadps: A list of network adapter settings
@returns: A dict containing network config
c sB g | ]\} d d t| d fdd d D dqS )physicalzeth{}
macaddressc s> g | ]}d |d d d d d d d d d dqS ) staticaddressnetworknetmaskautogatewaydnsnameservers)typerF rH controlrJ dns_nameserversr ).0ipnetadpr r
s
z6generate_network_config...rQ )rM r$ mac_addresssubnets)formatr lower)rP ir rR r rT z s
z+generate_network_config..)versionconfig) enumerate)netadpsr r r generate_network_configq s
r^ c
C s t jt jtj| ddd}t jtj| ddd}d|vs#d|vr+t td d
S | di d}| di d
g }d
}| di drQ|d d d }t
|d }||d d |d d g ddd |d D ddd||dg|d|di|t dd}td t| |S )a This 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)r_ r vmrS z(Failed to load metadata. Invalid format.NadditionalMetadatausernamesshKeyspasswordsha512_idr$ )zinstance-idzlocal-hostnamepublic-keysc S s> g | ]}|d D ]}t |d d D ] }|d |dqqqS )rQ rG rJ rF )r" r# )r )rP rS rQ targetr r r rT s
z+read_user_data_callback..default_userzALL=(ALL) NOPASSWD:ALLF)r$ gecossudopasswdlock_passwdssh_authorized_keys)
ssh_pwauthdisable_rootsystem_infonetwork_configmanage_etc_hosts)userdatametadatar, cfgzreturning DATA object:)
r load_jsonload_binary_fileospathr= r r<