File: //lib/python2.7/site-packages/azurelinuxagent/common/dhcp.pyo
�
d�bc @ s d d l Z d d l Z d d l Z d d l Z d d l j j Z d d l m Z d d l m
Z
d d l m Z d d l
m Z m Z m Z m Z m Z m Z m Z d Z d � Z d e f d � � YZ d
� Z d � Z d � Z d
� Z d � Z d � Z d � Z d S( i����N( t DhcpError( t
get_osutil( t KNOWN_WIRESERVER_IP( t hex_dumpt hex_dump2t hex_dump3t
compare_bytest
str_to_ordt unpack_big_endiant int_to_ip4_addrt 10813FA8c C s t � S( N( t DhcpHandler( ( ( s? /usr/lib/python2.7/site-packages/azurelinuxagent/common/dhcp.pyt get_dhcp_handler$ s R c B sb e Z d Z d � Z d � Z d � Z e d � � Z e d � � Z d � Z d � Z
d � Z RS( s?
Azure use DHCP option 245 to pass endpoint ip to VMs.
c C s= t � | _ d | _ d | _ d | _ t | _ t | _ d S( N( R t osutilt Nonet endpointt gatewayt routest Falset _request_broadcastt
skip_cache( t self( ( s? /usr/lib/python2.7/site-packages/azurelinuxagent/common/dhcp.pyt __init__- s c C s. | j s | j r d S| j � | j � d S( s{
Send dhcp request
Configure default gateway and routes
Save wire server endpoint if found
N( t wireserver_route_existst dhcp_cache_existst
send_dhcp_reqt conf_routes( R ( ( s? /usr/lib/python2.7/site-packages/azurelinuxagent/common/dhcp.pyt run5 s
c C su | j j � } x_ | d k s* | d k rp t j d � t j d � t j d � | j j � | j j � } q Wd S( s;
Wait for network stack to be initialized.
t s 0.0.0.0s Waiting for network.i
s Try to start network interface.N( R
t get_ip4_addrt loggert infot timet sleept
start_network( R t ipv4( ( s? /usr/lib/python2.7/site-packages/azurelinuxagent/common/dhcp.pyt wait_for_networkA s
c C s� t } t j d j t � � yy | j j � } t d � | D� � r~ t | _ d | _
d | _ t } t j d j t � � n t j
d j t � � Wn, t k
r� } t j d j t | � � n X| S( s�
Determine whether a route to the known wireserver
ip already exists, and if so use that as the endpoint.
This is true when running in a virtual network.
:return: True if a route to KNOWN_WIRESERVER_IP exists.
s Test for route to {0}c s s | ] } t | k Vq d S( N( t KNOWN_WIRESERVER_IP_ENTRY( t .0t route( ( s? /usr/lib/python2.7/site-packages/azurelinuxagent/common/dhcp.pys <genexpr>Y s s Route to {0} existss No route exists to {0}s4 Could not determine whether route exists to {0}: {1}N( R R R t formatR R
t read_route_tablet anyR R R R t Truet warnt Exceptiont error( R t route_existst route_tablet e( ( s? /usr/lib/python2.7/site-packages/azurelinuxagent/common/dhcp.pyR M s c C sg | j r
t St } t j d � | j j � } | d k rM | | _ t } n t j d j | � � | S( s�
Check whether the dhcp options cache exists and contains the
wireserver endpoint, unless skip_cache is True.
:return: True if the cached endpoint was found in the dhcp lease
s Checking for dhcp lease caches Cache exists [{0}]N(
R R R R R
t get_dhcp_lease_endpointR R R+ R( ( R t existst cached_endpoint( ( s? /usr/lib/python2.7/site-packages/azurelinuxagent/common/dhcp.pyR j s
c C s� t j d � t j d | j � t j d | j � | j d k rm | j j � rm | j j d d | j � n | j d k r� x6 | j D]( } | j j | d | d | d � q� Wn d S( Ns Configure routess Gateway:{0}s
Routes:{0}i i i ( R R R R R R
t is_missing_default_routet route_add( R R'