HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/hotplug_hook.cpython-311.pyc
�

܍~c�#���dZddlZddlZddlZddlZddlZddlmZmZm	Z	ddl
mZmZddl
mZddlmZddlmZddlmZmZdd	lmZeje��Zd
Zdd�ZGd�d
ej��ZGd�de��Zdeej fiZ!d�Z"dede#fd�Z$defd�Z%d�Z&edkr*e���'��Z(e&ee(��dSdS)z)Handle reconfiguration on hotplug events.�N)�log�	reporting�stages)�
EventScope�	EventType)�read_sys_net_safe)�parse_net_config_data)�events)�
DataSource�DataSourceNotFoundException)�Initzhotplug-hookc��|s tjtt���}t|_|�dddddg���|�dd	�
��}d|_|�dd�
��|�dd�
��}|�ddddd���|�ddddddg���|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�remove)	�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)s1���I��(�d��H�H�H�� �F��
������
"��������&�&��%5�'���J��J������H������)�)��2�*���M��������
.�����������
&���!������M�c��eZdZd�Zejd���Zeejd�����Zejde	fd���Z
d�Zd�Zd�Z
d	S)
�
UeventHandlerc�L�||_||_||_||_||_dS�N)�id�
datasource�devpath�action�
success_fn)�selfr/r0r1r2r3s      r(�__init__zUeventHandler.__init__Js)�����&0���������$����r*c��t���r.��NotImplementedError�r4s r(�applyzUeventHandler.applyQ���!�#�#�#r*c��t���r.r7r9s r(�configzUeventHandler.configUs��"�#�#�#r*�returnc��t���r.r7r9s r(�device_detectedzUeventHandler.device_detectedZr;r*c���d}|jdkrd}n%|jdkrd}ntd|jz���||���krtd|jz���dS)NrTrFzUnknown action: %sz'Failed to detect %s in updated metadata)r2�
ValueErrorr@�RuntimeErrorr/)r4�detect_presences  r(�detect_hotplugged_devicez&UeventHandler.detect_hotplugged_device^s������;�%���"�O�O�
�[�H�
$�
$�#�O�O��1�D�K�?�@�@�@��d�2�2�4�4�4�4��9�D�G�C���
�5�4r*c�*�|���Sr.)r3r9s r(�successzUeventHandler.successls����� � � r*c��|j�tjg��}|s$t	d|j�dtj�����|S)NzDatasource z not updated for event )r0�update_metadata_if_supportedr�HOTPLUGrC)r4�results  r(�update_metadatazUeventHandler.update_metadataos]����=�=�
�
��
�
���	��,��?�?�?�I�$5�$5�7���
��
r*N)�__name__�
__module__�__qualname__r5�abc�abstractmethodr:�propertyr=�boolr@rErGrL�r*r(r,r,Is�������%�%�%�	��$�$���$����$�$����X�$�	��$��$�$�$���$����!�!�!�	�	�	�	�	r*r,c�F��eZdZ�fd�Zd�Zed���Zdefd�Z�xZ	S)�
NetHandlerc���ttj�|��d��}t	���|||||��dS)N�address)r�os�path�basename�superr5)r4r0r1r2r3r/�	__class__s      �r(r5zNetHandler.__init__|sH���
�r�w�/�/��8�8�)�
D�
D��
������Z��&�*�E�E�E�E�Er*c��|jj�|jd���tj�|j��}|jj���}|j	dkr>|�
|��s'td�|j�����dS|j	dkr<|�
|��s)td�|j�����dSdS)NF)�bring_uprzFailed to bring up device: {}rzFailed to bring down device: {})r0�distro�apply_network_configr=rYrZr[r1�network_activatorr2�bring_up_interfacerC�format�bring_down_interface)r4�interface_name�	activators   r(r:zNetHandler.apply�s	�����3�3��K��	4�	
�	
�	
���)�)�$�,�7�7���O�*�<�<�>�>�	��;�%����/�/��?�?�
�"�3�:�:�4�<�H�H����
�
��[�H�
$�
$��1�1�.�A�A�
�"�5�<�<�T�\�J�J����%�
$�
�
r*c��|jjSr.)r0�network_configr9s r(r=zNetHandler.config�s
����-�-r*r>c����t�j��}�fd�|���D��}t�d�j|��t
|��dkS)Nc�P��g|]"}|�d���jk� |��#S)�mac_address)�getr/)�.0�ifacer4s  �r(�
<listcomp>z.NetHandler.device_detected.<locals>.<listcomp>�s<���
�
�
���y�y��'�'�4�7�2�2�
�2�2�2r*zIfaces with ID=%s : %sr)r	r=�iter_interfaces�LOG�debugr/�len)r4�netstate�founds`  r(r@zNetHandler.device_detected�sq���(���5�5��
�
�
�
�!�1�1�3�3�
�
�
��
	�	�	�*�D�G�U�;�;�;��5�z�z�A�~�r*)
rMrNrOr5r:rRr=rSr@�
__classcell__)r]s@r(rVrV{s��������F�F�F�F�F�
���$�.�.��X�.����������r*rVrc���	t|d}n5#t$r(}td�|����|�d}~wwxYwt	j|j|jtj	|���S)N�z4hotplug-hook: cannot handle events for subsystem: {})r0�cfg�event_source_type�scope)
�SUBSYSTEM_PROPERTES_MAP�KeyError�	Exceptionrdr�update_event_enabledr0rzrrJ)�hotplug_init�	subsystemr|�es    r(�
is_enabledr��s����'�	�2�1�5���������B�I�I��
�
�
�
��		����������&��*���#�+��	���s��
A�#A�Ar�r�c�:�t�d��|�d���}|�tjg��st�d|��dSt
||��st�d|��dS|S)NzFetching datasource�trust)�existingz*hotplug not supported for event of type %sz(hotplug not enabled for event of type %s)rrrs�fetch�get_supported_eventsrrJr�)r�r�r0s   r(�initialize_datasourcer��s����I�I�#�$�$�$��#�#�W�#�5�5�J��*�*�I�,=�+>�?�?���	�	�>�	�J�J�J����l�I�.�.���	�	�<�i�H�H�H����r*c	�n�t||��}|sdSt|d}t�d|��|||||j���}gd�}td��}t
|��D�]:\}	}
t�d||	t|����	t�d��|���|j	s.t�d��|�
��t�d	��|���t�d
��|���dS#t
$r<}t�d|��tj|
��|}Yd}~��4d}~wwxYw|�)NrzCreating %s event handler)r0r1r2r3)ry���
�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)r�r}rrrs�_write_to_cacher�	enumeratertrL�skip_hotplug_detectrEr:rG�time�sleep)r�r1r��
udevactionr0�handler_cls�
event_handler�
wait_times�last_exception�attempt�waitr�s            r(�handle_hotplugr��s���&�|�Y�?�?�J�����)�)�4�Q�7�K��I�I�)�9�5�5�5�#.�;�����/�	$�$�$�M�#�"�"�J��D�E�E�N�"�:�.�.���
����	�	�/����
�O�O�		
�	
�	
�	��I�I�+�,�,�,��)�)�+�+�+��1�
9��	�	�@�A�A�A��6�6�8�8�8��I�I�.�/�/�/����!�!�!��I�I�&�'�'�'��!�!�#�#�#��E�E���	�	�	��I�I�D�a�H�H�H��J�t�����N�N�N�N�N�N�����	����
�s�*B?E,�,
F2�61F-�-F2c	��tj|td���}tg|���}|���tj|j��d|jvr,tj	|j�
d����t�d||j
|jd|vr|jndd|vr|jnd��|5	|j
dkr^	t#||j��}n3#t$$r&t'd	��t)jd
��YnwxYwt'|rdnd��n"t-||j|j|j�
��n)#t.$rt�d���wxYwddd��n#1swxYwYt�d��tj��dS)NT)�reporting_enabled)�ds_deps�reporterrzh%s called with the following arguments: {hotplug_action: %s, subsystem: %s, udevaction: %s, devpath: %s}r�r1rz9Unable to determine hotplug state. No datasource detectedry�enabled�disabled)r�r1r�r�z*Received fatal exception handling hotplug!zExiting hotplug handler)r
�ReportEventStackr!r
�read_cfgr�setupLoggingrzr�update_configurationrmrrrsrr�r�r1r�r�print�sys�exitr�r�	exception�flush_events)�name�args�hotplug_reporterr�r0s     r(�handle_argsr��sU���.��g��������-=�>�>�>�L���������\�%�&�&�&��l�&�&�&��&�|�'7�';�';�K�'H�'H�I�I�I��I�I�	J������'�4�/�/����T�!�T�)�)����t����
���	��"�g�-�-�	 �!6�$�d�n�"�"�J�J��3� � � ��#�����H�Q�K�K�K�K�K� �����:�=�i�i�:�>�>�>�>��!-� �L�"�n�#��	�������	�	�	��M�M�F�G�G�G��	����+������������������2�I�I�'�(�(�(�
������sN�F�E�C5�4E�5-D%�"E�$D%�%9E�F�&F�F�F�F�__main__r.))r!rPrrYr�r��	cloudinitrrr�cloudinit.eventrr�
cloudinit.netr�cloudinit.net.network_stater	�cloudinit.reportingr
�cloudinit.sourcesrr�cloudinit.stagesr
�	getLoggerrMrrr r)�ABCr,rV�NETWORKr}r��strr�r�r��
parse_argsr�rTr*r(�<module>r�s��0�/�
�
�
�
�����	�	�	�	�
�
�
�
�����,�,�,�,�,�,�,�,�,�,�1�1�1�1�1�1�1�1�+�+�+�+�+�+�=�=�=�=�=�=�&�&�&�&�&�&�E�E�E�E�E�E�E�E�!�!�!�!�!�!��c�m�H������/�/�/�/�d/�/�/�/�/�C�G�/�/�/�d$�$�$�$�$��$�$�$�P
�J�
�*�+���
���$��������%��%�%�%�%�P2�2�2�j�z����:�<�<�"�"�$�$�D��K��d�������r*