3 \�me� � @ sb d dl Z d dlZd dlmZ d dlmZ d dlmZ dd� Zdd� Z ed �Z G d d� de j�ZdS )� N)�Optional)�NetworkState)�generate_udev_rulec s � fdd�S )Nc s � | d kS )N�type� )�iface)� match_typer �/usr/lib/python3.6/renderer.py�<lambda> s z filter_by_type.<locals>.<lambda>r )r r )r r �filter_by_type s r c s � fdd�S )Nc s � | ko| � S )Nr )r )� match_namer r r s z filter_by_attr.<locals>.<lambda>r )r r )r r �filter_by_attr s r Zphysicalc @ sF e Zd Zd dd�Zeed�dd��Zejdee e dd�dd ��ZdS )�RendererNc C s d S )Nr )�self�configr r r �__init__ s zRenderer.__init__)� network_statec C s^ t j� }xL| jt�D ]>}d|kr|jd�r|jdd�}|jt|d |d |d�� qW |j� S )z2Given state, emit udev rules to map mac to ifname.�nameZmac_address�driverN)r )�io�StringIOZiter_interfaces�filter_by_physical�get�writer �getvalue)r Zcontentr r r r r �_render_persistent_net s zRenderer._render_persistent_net)r � templates�returnc C s dS )zRender network state.Nr )r r r �targetr r r �render_network_state0 s zRenderer.render_network_state)N)NN)�__name__� __module__�__qualname__r �staticmethodr r �abc�abstractmethodr �dictr r r r r r s r ) r$ r Ztypingr Zcloudinit.net.network_stater Zcloudinit.net.udevr r r r �ABCr r r r r �<module> s