CasperSecurity

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

o

쑛hI,�@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�|jdddddgd�|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�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.r/r0r1r(r(r)�__init__Rs

zUeventHandler.__init__cC�t��r,��NotImplementedError�r2r(r(r)�applyY�zUeventHandler.applycCr4r,r5r7r(r(r)�config]szUeventHandler.config�returncCr4r,r5r7r(r(r)�device_detectedbr9zUeventHandler.device_detectedcCs@d}|jdkr
d}ntd|j��||��krtd|j��dS)NrTzUnknown action: %sz'Failed to detect %s in updated metadata)r0�
ValueErrorr<�RuntimeErrorr-)r2�detect_presencer(r(r)�detect_hotplugged_devicefs
��z&UeventHandler.detect_hotplugged_devicecCs|��Sr,)r1r7r(r(r)�successrszUeventHandler.successcCs,|j�tjg�}|std|jtjf��|S)Nz&Datasource %s not updated for event %s)r.�update_metadata_if_supportedr�HOTPLUGr>)r2�resultr(r(r)�update_metadataus�
��zUeventHandler.update_metadataN)�__name__�
__module__�__qualname__r3�abc�abstractmethodr8�propertyr:�boolr<r@rArEr(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�superr3)r2r.r/r0r1r-��	__class__r(r)r3�szNetHandler.__init__cCsZ|jjj|jdd�tj�|j�}|jj��}|j	dkr)|�
|�s+td�|j���dSdS)NF)�bring_uprzFailed to bring up device: {})
r.�distro�apply_network_configr:rOrPrQr/�network_activatorr0�bring_up_interfacer>�format)r2�interface_name�	activatorr(r(r)r8�s�


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

�zNetHandler.device_detected)
rFrGrHr3r8rKr:rLr<�
__classcell__r(r(rSr)rM�s
rMrc
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>rZr�update_event_enabledr.rkrrC)�hotplug_init�	subsystemrm�er(r(r)�
is_enabled�s$������rtrqrrcCsRt�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)rdre�fetch�get_supported_eventsrrCrt)rqrrr.r(r(r)�initialize_datasource�s

rzr;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.r/r0r1z>Gathering network configuration again due to IMDS limitations.)rzrnrdre�_write_to_cache�time�hotplug_retry_settings�force_retry�try_hotplug�sleep_total�sleep�sleep_period)rqr/rr�
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)rj���
�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�	enumeraterdrerfrE�skip_hotplug_detectr@r8rAr|r�)rrr�r.�
wait_times�last_exception�attempt�waitrsr(r(r)r�s6�




��rcCs�|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)NrurvFrjz#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_enabledrk)rxrnrrCryr_�set�print�sys�stderrr�read_hotplug_enabled_file�paths�value�append�
write_file�	get_cpath�json�dumpsrrk)rqrrr.rm�hotplug_supported�hotplug_enabled_filer(r(r)�enable_hotplug�s<��
�
��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�r/rz9Unable to determine hotplug state. No datasource detectedrj�enabled�disabledr)rqr/rrr�rz9Root is required. Try prepending your command with sudo.
)rqrrz)Enabled cloud-init hotplug for subsystem=z*Received fatal exception handling hotplug!zExiting hotplug handler)r�ReportEventStackr!r�read_cfgr�
setup_loggingrkr�update_configurationr_rdrerrrr�r/rzr
r�r��exitr�rO�getuidr��writer�r��	exception�flush_events)�name�args�hotplug_reporterrqr.r(r(r)�handle_args sx�
�

���
��
�
���
���
)r��__main__r,)r;N)2r!rIrr��loggingrOr�r|�	cloudinitrrr�#cloudinit.config.cc_install_hotplugr�cloudinit.eventrr�
cloudinit.logr�
cloudinit.netr	�cloudinit.net.network_stater
�cloudinit.reportingr�cloudinit.sourcesrr
�cloudinit.stagesr�	getLoggerrFrdr r*�ABCr+rM�NETWORKrnrt�strrzr�rrLr�r��
parse_argsr�r(r(r(r)�<module>sD

60
#�
#E
�
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY