509318396
Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­Â�Â­
<!DOCTYPE html>
<html>
3
\¼meé  ã               @   s°   d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ e jeƒZddiZd	Zd
Zd
ZG dd„ dejƒZG dd„ deƒZeejffeejejffgZdd„ ZdS )é    N)Únet)ÚsourcesÚutil)ÚNoDHCPLeaseError)ÚEphemeralDHCPv4)ÚupcloudÚmetadata_urlz'http://169.254.169.254/metadata/v1.jsoné   é   c               @   sH   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	e
dd„ ƒZdS )ÚDataSourceUpCloudÚUpCloudFc             C   s„   t jj| |||ƒ || _tƒ | _tjtj|ddgi ƒt	gƒ| _
| j
d | _| j
jdtƒ| _| j
jdtƒ| _| j
jdtƒ| _d | _d S )NZ
datasourcer   r   ÚretriesÚtimeoutÚ
wait_retry)r   Ú
DataSourceÚ__init__ÚdistroÚdictÚmetadatar   ZmergemanydictZget_cfg_by_pathÚBUILTIN_DS_CONFIGZds_cfgÚmetadata_addressÚgetÚ
MD_RETRIESr   Ú
MD_TIMEOUTr   ÚMD_WAIT_RETRYr   Ú_network_config)ÚselfÚsys_cfgr   Úpaths© r   ú'/usr/lib/python3.6/DataSourceUpCloud.pyr   "   s    
zDataSourceUpCloud.__init__c             C   s   t jƒ S )N)Ú	uc_helperZread_sysinfo)r   r   r   r    Ú_get_sysinfo2   s    zDataSourceUpCloud._get_sysinfoc             C   s   t j| j| j| j| jd�S )N)r   Zsec_betweenr   )r!   Zread_metadatar   r   r   r   )r   r   r   r    Ú_read_metadata5   s
    z DataSourceUpCloud._read_metadatac             C   sŒ  | j ƒ \}}|sdS tjd|ƒ | jr®yNtjdƒ tjƒ }tjd|ƒ t| j|ƒ� t	j
tjd| jd�}W d Q R X W n6 ttjfk
rª } zt	jtt|ƒƒ dS d }~X nX ndy"tjdƒ t	j
tjd| jd�}W n@ tjk
�r } z t	jtt|ƒƒ tjd|ƒ dS d }~X nX || _|jd	|ƒ| jd
< |jdƒ| jd< |jdƒ| jd< |jdƒ| jd< |jddƒ| jd< |jdd ƒ| _|jdd ƒ| _dS )NFz"Running on UpCloud. server_uuid=%szFinding a fallback NICz*Discovering metadata via DHCP interface %szReading from metadata service)ZlogfuncÚmsgÚfuncz7Discovering metadata without DHCP-configured networkingzENo DHCP-enabled interfaces available, unable to fetch metadata for %sZinstance_idzinstance-idZhostnamezlocal-hostnameÚnetworkZpublic_keyszpublic-keysZregionÚdefaultZavailability_zoneZvendor_dataZ	user_dataT)r"   ÚLOGÚinfoÚperform_dhcp_setupÚdebugÚcloudnetZfind_fallback_nicr   r   r   Zlog_timer#   r   r   ZInvalidMetaDataExceptionZlogexcÚstrZmetadata_fullr   r   Zvendordata_rawZuserdata_raw)r   Z
is_upcloudZserver_uuidZnicZmdÚer   r   r    Ú	_get_data=   sN    
zDataSourceUpCloud._get_datac             C   s   t j| jƒ ƒS )N)r   Zinstance_id_matches_system_uuidZget_instance_id)r   r   r   r   r    Úcheck_instance_idr   s    z#DataSourceUpCloud.check_instance_idc             C   s6   | j r| j S | jjdƒ}|s$tdƒ‚tj|ƒ| _ | j S )z®
        Configure the networking. This needs to be done each boot,
        since the IP and interface information might have changed
        due to reconfiguration.
        r&   z/Unable to get network meta-data from server....)r   r   r   ÚRuntimeErrorr!   Zconvert_network_config)r   Zraw_network_configr   r   r    Únetwork_configu   s    z DataSourceUpCloud.network_configN)Ú__name__Ú
__module__Ú__qualname__Zdsnamer*   r   r"   r#   r/   r0   Úpropertyr2   r   r   r   r    r      s   5r   c               @   s   e Zd ZdZdZdS )ÚDataSourceUpCloudLocalaz  
    Run in init-local using a DHCP discovery prior to metadata crawl.

    In init-local, no network is available. This subclass sets up minimal
    networking with dhclient on a viable nic so that it can talk to the
    metadata service. If the metadata service provides network configuration
    then render the network configuration for that instance based on metadata.
    TN)r3   r4   r5   Ú__doc__r*   r   r   r   r    r7   �   s   r7   c             C   s   t j| tƒS )N)r   Zlist_from_dependsÚdatasources)Zdependsr   r   r    Úget_datasource_list¢   s    r:   )ZloggingZ	cloudinitr   r,   r   r   Zcloudinit.net.dhcpr   Zcloudinit.net.ephemeralr   Zcloudinit.sources.helpersr   r!   Z	getLoggerr3   r(   r   r   r   r   r   r   r7   ZDEP_FILESYSTEMZDEP_NETWORKr9   r:   r   r   r   r    Ú<module>   s   
r
