
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
\¼me  ã               @   sr   d Z ddlZddlmZ ddlmZmZ ejeƒZ	G dd„ deƒZ
G dd„ deƒZeee
ee f d	œ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 )Ú
EventScopeZnetworkc             C   s   | j S )N)Úvalue)Úself© r   ú/usr/lib/python3.6/event.pyÚ__str__   s    zEventScope.__str__N)Ú__name__Ú
__module__Ú__qualname__Z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.Zbootzboot-new-instancezboot-legacyZhotplugc             C   s   | j S )N)r   )r   r   r   r	   r
   "   s    zEventType.__str__N)	r   r   r   Ú__doc__ZBOOTZBOOT_NEW_INSTANCEZBOOT_LEGACYZHOTPLUGr
   r   r   r   r	   r      s   r   )Úuser_configÚreturnc              C   s¾   i }x´| j ƒ D ]¨\}}yt|ƒ}W n6 tk
rX } ztjdt|ƒ|ƒ wW Y dd}~X nX ydd„ |d D ƒ}W n8 tk
r¨ } ztjdt|ƒ|ƒ g }W Y dd}~X nX t|ƒ||< qW |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>Zwhen)Úitemsr   Ú
ValueErrorÚLOGZwarningÚstrÚset)r   Zupdate_configZscopeZ
scope_listZ	new_scopeÚeZ
new_valuesr   r   r	   Úuserdata_to_events&   s(    r   )r   ZloggingÚenumr   Ztypingr   r   Z	getLoggerr   r   r   r   Údictr   r   r   r   r	   Ú<module>   s   

