HEX
Server: nginx/1.24.0
System: Linux webserver 6.8.0-90-generic #91-Ubuntu SMP PREEMPT_DYNAMIC Tue Nov 18 14:14:30 UTC 2025 x86_64
User: wpuser (1002)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/hotplug_hook.cpython-312.pyc
�

쑛hI,����dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
ddlmZmZddlmZddlmZddlmZdd	lmZdd
lmZmZddlmZej<e�Z dZ!dd
�Z"Gd�dejF�Z$Gd�de$�Z%de%ejLfiZ'd�Z(dede)fd�Z*deddfd�Z+dd�Z,dede-fd�Z.d�Z/edk(re"�ja�Z1e/e!e1�yy)z)Handle reconfiguration on hotplug events.�N)�	reporting�stages�util)�install_hotplug)�
EventScope�	EventType)�loggers)�read_sys_net_safe)�parse_net_config_data)�events)�
DataSource�DataSourceNotFoundException)�Initzhotplug-hookc��|stjtt��}t|_|jdddddg��|j
dd	�
�}d|_|jdd�
�|jdd�
�}|jddddd��|jdddddg��|jdd�
�|S)aBuild or extend an arg parser for hotplug-hook utility.

    @param parser: Optional existing ArgumentParser instance representing the
        subcommand which will be extended to support the args of this utility.

    @returns: ArgumentParser with proper argument configuration.
    )�prog�descriptionz-sz--subsystemTzsubsystem to act on�net)�required�help�choiceszHotplug Action�hotplug_action)�title�dest�queryz0Query if hotplug is enabled for given subsystem.)r�handlezHandle the hotplug event.z-dz	--devpath�PATHzSysfs path to hotplugged device)r�metavarrz-uz--udevactionzSpecify action to take.�add�enablez%Enable hotplug for a given subsystem.)	�argparse�ArgumentParser�NAME�__doc__r�add_argument�add_subparsersr�
add_parser)�parser�
subparsers�
parser_handles   �B/usr/lib/python3/dist-packages/cloudinit/cmd/devel/hotplug_hook.py�
get_parserr+s����(�(�d��H�� �F��
������
"������&�&��%5�'��J��J������H����)�)��2�*��M��������
.���������
&���������>����M�c��eZdZd�Zej
d��Zeej
d���Zej
de	fd��Z
d�Zd�Zd�Z
y	)
�
UeventHandlerc�J�||_||_||_||_||_y�N)�id�
datasource�devpath�action�
success_fn)�selfr1r2r3r4r5s      r*�__init__zUeventHandler.__init__Rs%�����&0���������$��r,c��t��r0��NotImplementedError�r6s r*�applyzUeventHandler.applyY���!�#�#r,c��t��r0r9r;s r*�configzUeventHandler.config]s
��"�#�#r,�returnc��t��r0r9r;s r*�device_detectedzUeventHandler.device_detectedbr=r,c��d}|jdk(rd}ntd|jz��||j�k7rtd|jz��y)NrTzUnknown action: %sz'Failed to detect %s in updated metadata)r4�
ValueErrorrB�RuntimeErrorr1)r6�detect_presences  r*�detect_hotplugged_devicez&UeventHandler.detect_hotplugged_devicefs\�����;�;�%��"�O��1�D�K�K�?�@�@��d�2�2�4�4��9�D�G�G�C��
�5r,c�"�|j�Sr0)r5r;s r*�successzUeventHandler.successrs����� � r,c��|jjtjg�}|s)t	d|j�dtj����|S)NzDatasource z not updated for event )r2�update_metadata_if_supportedr�HOTPLUGrE)r6�results  r*�update_metadatazUeventHandler.update_metadatausO�����=�=�
�
�
��
�����?�?�I�$5�$5�7��
��
r,N)�__name__�
__module__�__qualname__r7�abc�abstractmethodr<�propertyr?�boolrBrGrIrN�r,r*r.r.Qss��%�	���$��$�����$���$�	���$��$��$�
�!�	r,r.c�@��eZdZ�fd�Zd�Zed��Zdefd�Z�xZ	S)�
NetHandlerc�~��ttjj|�d�}t�|�|||||�y)N�address)r
�os�path�basename�superr7)r6r2r3r4r5r1�	__class__s      �r*r7zNetHandler.__init__�s3���
�r�w�w�/�/��8�)�
D��
����Z��&�*�Er,c��|jjj|jd��tj
j
|j�}|jjj�}|jdk(r6|j|�s$tdj|j���yy)NF)�bring_uprzFailed to bring up device: {})
r2�distro�apply_network_configr?r[r\r]r3�network_activatorr4�bring_up_interfacerE�format)r6�interface_name�	activators   r*r<zNetHandler.apply�s��������3�3��K�K��	4�	
����)�)�$�,�,�7���O�O�*�*�<�<�>�	��;�;�%���/�/��?�"�3�:�:�4�<�<�H���@� r,c�.�|jjSr0)r2�network_configr;s r*r?zNetHandler.config�s�����-�-�-r,r@c�
�t|j�}|j�D�cgc]"}|jd�|jk(r|��$}}t
j
d|j|�t|�dkDScc}w)N�mac_addresszIfaces with ID=%s : %sr)rr?�iter_interfaces�getr1�LOG�debug�len)r6�netstate�iface�founds    r*rBzNetHandler.device_detected�sw��(����5��"�1�1�3�
���y�y��'�4�7�7�2�
�
��
�
	�	�	�*�D�G�G�U�;��5�z�A�~���

s�'B)
rOrPrQr7r<rTr?rUrB�
__classcell__)r_s@r*rXrX�s.���F�
��.��.���r,rXrc���	t|d}t	j
|j|jtj|��S#t$r }tdj|��|�d}~wwxYw)N�z4hotplug-hook: cannot handle events for subsystem: {})r2�cfg�event_source_type�scope)
�SUBSYSTEM_PROPERTIES_MAP�KeyErrorrErfr�update_event_enabledr2rxrrL)�hotplug_init�	subsystemrz�es    r*�
is_enabledr��s~���(��3�A�6���&�&��*�*����#�+�+��	������B�I�I��
�
��		���s�A	�		A2�A-�-A2r~rc��tjd�|jd��}|jtj
g�stjd|�yt
||�stjd|�y|S)NzFetching datasource�trust��existingz*hotplug not supported for event of type %sz(hotplug not enabled for event of type %s)rorp�fetch�get_supported_eventsrrLr�)r~rr2s   r*�initialize_datasourcer��sm���I�I�#�$��#�#�W�#�5�J��*�*�I�,=�,=�+>�?��	�	�>�	�J���l�I�.��	�	�<�i�H���r,r@c�T�t||�}|syt|d}tjd|�|||||j��}tj
�}|jjst|||�ytj
�|z
|jjkr{t|||�tjd�tj|jj�tj
�|z
|jjkr�zyy)NrzCreating %s event handler)r2r3r4r5z>Gathering network configuration again due to IMDS limitations.)r�r{rorp�_write_to_cache�time�hotplug_retry_settings�force_retry�try_hotplug�sleep_total�sleep�sleep_period)r~r3r�
udevactionr2�handler_cls�
event_handler�starts        r*�handle_hotplugr��s���&�|�Y�?�J���*�9�5�a�8�K��I�I�)�9�5�#.�����/�/�	$�M�
�I�I�K�E��,�,�8�8��I�}�j�9��
�)�)�+��
�
� A� A� M� M�
M��I�}�j�9��	�	�L�	
�	
�
�
�:�4�4�A�A�B��)�)�+��
�
� A� A� M� M�
Mr,c	�X�gd�}td�}t|�D]�\}}tjd||t	|��	tjd�|j�|js%tjd�|j�tjd�|j�tjd�|j�y|�#t$r8}tjd|�tj|�|}Yd}~��	d}~wwxYw)	N)rw���
�z#Bug while processing hotplug event.z!subsystem=%s update attempt %s/%szRefreshing metadataz$Detecting device in updated metadatazApplying config changezUpdating cachez,Exception while processing hotplug event. %s)�	Exception�	enumeraterorprqrN�skip_hotplug_detectrGr<rIr�r�)rr�r2�
wait_times�last_exception�attempt�waitr�s        r*r�r��s���"�J��D�E�N�"�:�.��
����	�	�/����
�O�		
�	��I�I�+�,��)�)�+��1�1��	�	�@�A��6�6�8��I�I�.�/����!��I�I�&�'��!�!�#��#�.����	��I�I�D�a�H��J�J�t���N��	�s�B C(�(	D)�1-D$�$D)c��|jd��}|syt|d}tj|j	tjg�j|t
��v}|std|��tj��ytj|j�}|j|dvr td|�d	�tj��y
|dj|j�tj|jj!d�t#j$|�dd
��t'|d
|j(��y
)Nr�r�Frwz#hotplug not supported for event of )�file�scopesz)Not installing hotplug for event of type z. Reason: Already done.Tzhotplug.enabled�wi�)�omode�mode)�network_hotplug_enabledrx)r�r{rrLr�rn�set�print�sys�stderrr�read_hotplug_enabled_file�paths�value�append�
write_file�	get_cpath�json�dumpsrrx)r~rr2rz�hotplug_supported�hotplug_enabled_files      r*�enable_hotplugr��s9���#�#�W�#�5�J���$�Y�/��2�E�!�)�)��'�'��):�):�(;�<�@�@����N����
�1�)��=�C�J�J�	
���9�9�,�:L�:L�M���{�{�*�8�4�4�
�7�	�{�C%�
%����	
�
���"�)�)�%�+�+�6��O�O����$�$�%6�7��
�
�'�(��
�	���D�l�6F�6F��r,c	���tj|td��}tg|��}|j	�tj|j�d|jvr.tj|jjd��tjd||j|jd|vr|jndd|vr|j nd�|5	|jdk(r'	t#||j�}t'rdnd�n�|jd
k(r.t-||j |j|j��n�t/j0�dk7r4t(j2j5d�t)j*d
�t7||j��st)j*d
�t'd|j���ddd�tjd�tj<�y#t$$r$t'd	�t)j*d
�Y��:wxYw#t8$rtj;d��wxYw#1swY��xYw)NT)�reporting_enabled)�ds_deps�reporterrzh%s called with the following arguments: {hotplug_action: %s, subsystem: %s, udevaction: %s, devpath: %s}r�r3rz9Unable to determine hotplug state. No datasource detectedrw�enabled�disabledr)r~r3rr�rz9Root is required. Try prepending your command with sudo.
)r~rz)Enabled cloud-init hotplug for subsystem=z*Received fatal exception handling hotplug!zExiting hotplug handler)r�ReportEventStackr#r�read_cfgr	�
setup_loggingrxr�update_configurationrnrorprrr�r3r�rr�r��exitr�r[�getuidr��writer�r��	exception�flush_events)�name�args�hotplug_reporterr~r2s     r*�handle_argsr� s���.�.��g������-=�>�L��������,�*�*�+��l�&�&�&��&�&�|�'7�'7�';�';�K�'H�I��I�I�	J��������'�4�/����T�!�T�)����t��
�'�&	��"�"�g�-�	 �!6�$�d�n�n�"�J��:�i�:�>��$�$��0��!-� �L�L�"�n�n�#���	��9�9�;�!�#��J�J�$�$�#���H�H�Q�K�%�!-������H�H�Q�K��!�!%��� 0�2��A'�R�I�I�'�(�
�����G3� ��#���H�H�Q�K� ��<�	��M�M�F�G��	��K'�'�sC�%I.�'I�7H�
CI�)I�I�I�I� I+�+I.�.I7�__main__r0)r@N)2r#rRr r��loggingr[r�r��	cloudinitrrr�#cloudinit.config.cc_install_hotplugr�cloudinit.eventrr�
cloudinit.logr	�
cloudinit.netr
�cloudinit.net.network_stater�cloudinit.reportingr�cloudinit.sourcesr
r�cloudinit.stagesr�	getLoggerrOror"r+�ABCr.rX�NETWORKr{r��strr�r�r�rUr�r��
parse_argsr�rVr,r*�<module>r�s	��0�
����	�
��-�-�?�1�!�+�=�&�E�!��g����!����3�l-�C�G�G�-�`���F
�J�
�*�*�+���
�$�����C��C�$�C�0�: �� �T� �FB�J�z���<�"�"�$�D���d��r,