HOME


Mini Shell 1.0
DIR: /lib/python3/dist-packages/cloudinit/sources/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/sources/__pycache__/DataSourceRbxCloud.cpython-312.pyc
�

�f,��2�dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZddlm
Z
mZeje�ZdZd�Zded	efd
�Zd	ej.efd�Zd�Zd
�Zd�Zd�Zd�ZGd�de	j<�Zee	j@ffgZ!d�Z"y)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/hostsc��tjtd��}|rtj	d�ytj	d�y)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)�hostss �F/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceRbxCloud.py�get_manage_etc_hostsrs7�����	��6�E���	�	�I�J���I�I�M�N���inc�returnc	�T�tttt|��|z��S�N)�strr�int)�addrrs  r�increment_ipr#s!���{�3�{�4�0�1�C�7�8�9�9rc�4�|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)rs r�
get_three_ipsr's%��	
��T�1���T�1���rc�4�tjdg|z�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)�cmds r�_sub_arpr"4s���9�9�h�Z�#�%�&�&rc	���d}|jdvrd}|D]}	tdd||d|dg��y#tj$r(}tjd|d|d|�Yd}~�Sd}~wwxYw)	Nz-S)�fedora�centos�rhelz-sz-c�2�source�destinationz&Failed to arping from "%s" to "%s": %s)�namer"r�ProcessExecutionErrorr
�warning)�items�distro�source_param�item�errors     r�gratuitous_arpr2=s����L�
�{�{�2�2������
	���s�L�$�x�.�$�}�:M�N�
���
�)�)�		�
�K�K�8��X���]�#��	
�
��			�s�2�A-�A(�(A-c���ttjd�tjd�z�}|sy|D]'}	tj|tgd���}|r|cS�)tjdd	j|��y#t
$r(}|jtjk7r�Yd}~�|d}~wtj$rtjtd|�Y��wxYw)
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)�devicesr7�rbx_data�errs    r�get_mdrHRs�������O�,�
�
�
�o�
.�	/��G������	��}�}��0�0��H�
�����"�I�I�:�C�H�H�W�<M�����	��y�y�E�L�L�(��)���$�$�	��K�K��D�f�
�	�s�!B
�
	C*�B6�61C*�)C*c��dt|�D���cgc]e\}}ddjt|��|dj�|dD�cgc]#}d|d|dd	d
|dd|ddd
d���%c}d���gc}}}d�Scc}wcc}}}w)z�Generate network configuration

    @param netadps: A list of network adapter settings

    @returns: A dict containing network config
    ��physicalzeth{}�
macaddress�ip�static�address�network�netmask�auto�gateway�dns�nameservers)�typerOrQ�controlrS�dns_nameservers)rVr*�mac_address�subnets)�version�config)�	enumerate�formatr�lower)�netadps�i�netadprMs    r�generate_network_configrcqs����('�w�/�'
�
�&��6�##����s�1�v�.�%�l�3�9�9�;�%�T�l���!)�#%�i�=�#)�)�#4�Y�#?�#)�#)�)�#4�Y�#?�+1�)�+<�U�+C�)�,�
	��	
�
������
s�;B
�(B�4B
�B
c
�z�tjtjtjj|d�����}tjtjj|d�d��}d|vsd|vrtjtd	�y
|jdi�jd�}|jdi�jd
g�}d
}|jdi�jd�r|ddd}t|d�}||dd|ddgd�|dD���	cgc]*}|dD] }t|dd�D]
}	|d|	d����"�,c}	}}ddd||dg|d|d�i|t�d�d�}
tjd�tj|
�|
Scc}	}}w)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)rer
�vmrbz(Failed to load metadata. Invalid format.N�additionalMetadata�username�sshKeys�password�sha512�_idr*)zinstance-idzlocal-hostname�public-keysrMrPrSrO)r(r)�default_userzALL=(ALL) NOPASSWD:ALLF)r*�gecos�sudo�passwd�lock_passwd�ssh_authorized_keys)�
ssh_pwauth�disable_root�system_info�network_config�manage_etc_hosts)�userdata�metadatar2�cfgzreturning DATA object:)r�	load_json�load_binary_file�os�pathrDrrCr
�getrcrrr)�	mount_dir�	meta_data�	user_datari�ssh_keys�hashrPrbrM�target�datas           rr>r>�s������
�
"�
"������i��)N�
O��I��#�#��g�g�l�l�9�k�2�$��I��9���	� 9����C�C�D���}�}�1�2�6�:�:�:�F�H��}�}�1�2�6�:�:�9�b�I�H��D��}�}�)�2�.�2�2�:�>��-�.�z�:�8�D��%�i��&9�:�G��$�T�?�5�1�'��o�f�5��
�$�H�-�
�
���T�l�
��'��y�(9�)�(D�E�	
���)�}�V�<�
�<�
�<�
�� ��$�%�5�6�"�#(�+3�
!�	�&� 4� 6�
��D�>�I�I�&�'��I�I�d�O��K��7
s�;/F6c��eZdZdZej
ejejejhiZ
d�Zd�Zd�Z
ed��Zd�Zd�Zd�Zd	�Zy
)�DataSourceRbxCloud�RbxCloudc�V�tjj||||�d|_yr)r�
DataSource�__init__�seed)�self�sys_cfgr.�pathss    rr�zDataSourceRbxCloud.__init__�s#�����#�#�D�'�6�5�A���	rc�d�tjj|�}|�d|j�d�S)Nz [seed=�])rr��__str__r�)r��roots  rr�zDataSourceRbxCloud.__str__�s'���!�!�)�)�$�/��!%�t�y�y�1�1rc�r�t�}|dury|d|_|d|_|d|_|d|_y)zw
        Metadata is passed to the launching instance which
        is used to perform instance configuration.
        Frzr{r2r|T)rH�userdata_rawr{r2r|)r�rFs  r�	_get_datazDataSourceRbxCloud._get_data�sK��
�8���u���$�Z�0��� ��,��
�&�'7�8����E�?���rc� �|jdS)Nrx�r|�r�s rrxz!DataSourceRbxCloud.network_config�s���x�x�(�)�)rc� �|jdS)Nrn)r{r�s r�get_public_ssh_keysz&DataSourceRbxCloud.get_public_ssh_keys�s���}�}�]�+�+rc��|jSr)r�r�s r�get_userdata_rawz#DataSourceRbxCloud.get_userdata_raw�s��� � � rc��|jSrr�r�s r�get_config_objz!DataSourceRbxCloud.get_config_obj�s���x�x�rc�D�t|j|j�yr)r2r.)r�r|�is_new_instances   r�activatezDataSourceRbxCloud.activate�s���t�*�*�D�K�K�8rN)�__name__�
__module__�__qualname__�dsnamer�NETWORKr�BOOT_NEW_INSTANCE�BOOT�BOOT_LEGACY�default_update_eventsr�r�r��propertyrxr�r�r�r��rrr�r��sm��
�F�����'�'��N�N��!�!�
����2���*��*�,�!��9rr�c�6�tj|t�Sr)r�list_from_depends�datasources)�dependss r�get_datasource_listr�
s���$�$�W�k�:�:r)#�__doc__r@�loggingr�os.path�typing�	ipaddressr�	cloudinitrrr�cloudinit.eventrr�	getLoggerr�r
rrrrr�Listrr"r2rHrcr>r�r��DEP_FILESYSTEMr�r�r�rr�<module>r�s����
��	��
�!�)�)�1��g����!���	��:�C�:�C�:�
�6�;�;�s�+�
�'��*�>�B=�@.9��+�+�.9�f�'�0�0�2�3���;r