o
    ¦®Øf  ã                   @   st   d Z ddlZddlmZ ddlmZmZ e e¡Z	G dd„ deƒZ
G dd„ deƒZd	ed
ee
ee f fdd„ZdS )z0Classes and functions related to event handling.é    N)ÚEnum)ÚDictÚSetc                   @   s   e Zd ZdZdd„ ZdS )Ú
EventScopeÚnetworkc                 C   ó   | j S ©N©Úvalue©Úself© r   ú1/usr/lib/python3/dist-packages/cloudinit/event.pyÚ__str__   ó   zEventScope.__str__N)Ú__name__Ú
__module__Ú__qualname__ÚNETWORKr   r   r   r   r   r      s    r   c                   @   s(   e Zd ZdZdZdZdZdZdd„ ZdS )	Ú	EventTypezCEvent types which can generate maintenance requests for cloud-init.Úbootzboot-new-instancezboot-legacyÚhotplugc                 C   r   r   r	   r   r   r   r   r   "   r   zEventType.__str__N)	r   r   r   Ú__doc__ÚBOOTÚBOOT_NEW_INSTANCEÚBOOT_LEGACYÚHOTPLUGr   r   r   r   r   r      s    r   Úuser_configÚreturnc                 C   s¼   i }|   ¡ D ]U\}}zt|ƒ}W n ty+ } zt dt|ƒ|¡ W Y d}~qd}~ww zdd„ |d D ƒ}W n tyT } zt dt|ƒ|¡ g }W Y d}~nd}~ww t|ƒ||< q|S )a  Convert userdata into update config format defined on datasource.

    Userdata is in the form of (e.g):
    {'network': {'when': ['boot']}}

    DataSource config is in the form of:
    {EventScope.Network: {EventType.BOOT}}

    Take the first and return the second
    z.%s! Update data will be ignored for '%s' scopeNc                 S   s   g | ]}t |ƒ‘qS r   )r   )Ú.0Úxr   r   r   Ú
<listcomp>=   s    z&userdata_to_events.<locals>.<listcomp>Úwhen)Úitemsr   Ú
ValueErrorÚLOGÚwarningÚstrÚset)r   Úupdate_configÚscopeÚ
scope_listÚ	new_scopeÚeÚ
new_valuesr   r   r   Úuserdata_to_events&   s4   ý€úý€úr/   )r   ÚloggingÚenumr   Útypingr   r   Ú	getLoggerr   r%   r   r   Údictr/   r   r   r   r   Ú<module>   s   

"