3 \me# @ s0 d Z ddlZddlZddlZddlZddlZddlZddlmZm Z m Z ddlmZm Z ddlmZ ddlmZ ddlmZ ddlmZmZ dd lmZ ejeZd ZdddZG d d dejZG dd deZ de ej!fiZ"dd Z#ee$dddZ%edddZ&dd Z'edkr,e j( Z)e'ee) dS )z)Handle reconfiguration on hotplug events. N)log reportingstages) EventScope EventType)read_sys_net_safe)parse_net_config_data)events) DataSourceDataSourceNotFoundException)Initzhotplug-hookc C s | st jttd} t| _| jdddddgd | jdd d }d|_|jddd |jddd }|jdddddd |jddddddgd | S )a Build 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. )progdescriptionz-sz--subsystemTzsubsystem to act onnet)requiredhelpchoiceszHotplug Actionhotplug_action)titledestqueryz0Query if hotplug is enabled for given subsystem.)r ZhandlezHandle the hotplug event.z-dz --devpathPATHzSysfs path to hotplugged device)r metavarr z-uz--udevactionzSpecify action to take.addremove) argparseArgumentParserNAME__doc__r add_argumentZadd_subparsersr Z add_parser)parserZ subparsersZ parser_handle r! "/usr/lib/python3.6/hotplug_hook.py get_parser s: r# c @ s` e Zd Zdd Zejdd Zeejdd Zeje ddd Z d d Zdd Zdd Z dS ) UeventHandlerc C s" || _ || _|| _|| _|| _d S )N)id datasourcedevpathaction success_fn)selfr% r&