3 \�me � @ sV d dl Z d dlZd dlmZmZmZmZ e je�Z G dd� dejj j�Zddd�Z dS )� N)�distros�net�subp�utilc s@ e Zd Zd � fdd� Zdd� Zdd� Zdd d �Zdd� Z� ZS )�RendererNc s d| _ tt| �j� d S )Nr )� _route_cpt�superr �__init__)�self�config)� __class__� �/usr/lib/python3.6/freebsd.pyr s zRenderer.__init__c C s | j d| |� d S )Nzifconfig_%s_name)�set_rc_config_value)r Zcur_name�device_namer r r �rename_interface s zRenderer.rename_interfacec C s� xp| j j� D ]b\}}t|t�rRd|jd�|jd�f }|jd�}|r^|d| 7 }n|dkr^d}| jd| |� qW xb| jj� D ]T\}}t|t�r�d|jd�|jd �f }|jd�}|r�|d| 7 }| jd | |� q~W d S )Nzinet %s netmask %sZaddress�netmask�mtuz mtu %dZDHCPZ ifconfig_zinet6 %s/%d�prefixzifconfig_%s_ipv6)Zinterface_configurations�items� isinstance�dict�getr Zinterface_configurations_ipv6)r r �vZ net_configr r r r �write_config s* zRenderer.write_configFc C s� |st jd� d S x$| j� D ]}tjjj|tjj � qW t j dddgdd� t j dddgddd gd � x$| j� D ]}tjjj|tjj � qpW d S )Nz!freebsd generate postcmd disabledZserviceZnetifZrestartT)�captureZroutingr � )r �rcs)�LOG�debugZdhcp_interfacesr ZdhcpZIscDhclientZstop_servicer ZfreebsdZDistror Z start_service)r ZrunZdhcp_interfacer r r �start_services. s zRenderer.start_servicesc C s� |dkr| j d|� nz|dkr,| j d|� ndd| j� �}d|� d|� d|� �}| j d | |� | j� d|� �| _| j d | jj� � | jd7 _d S )Nz0.0.0.0Z defaultrouterz::Zipv6_defaultrouterr z-net z -netmask � Zroute_Z static_routesr )r r Zroute_names�strip)r Znetworkr ZgatewayZ route_nameZ route_cmdr r r � set_routeH s zRenderer.set_route)N)F) �__name__� __module__�__qualname__r r r r r# � __classcell__r r )r r r s r c C s t j� pt j� S )N)r Z is_FreeBSDZis_DragonFlyBSD)�targetr r r � availableV s r) )N)ZloggingZcloudinit.net.bsdZ cloudinitr r r r Z getLoggerr$ r ZbsdZBSDRendererr r) r r r r �<module> s K