Current File : //lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyc
�
oB�]c@s�ddlZddlZddlZddlZddlZddlmZddlmZddl	m
Zddl	mZddl	m
Z
ddl	mZddl	mZdd	lmZmZdd
lmZeje�ZdZiedd
6edd6edd6ZdZdZd�Zdejjfd��YZd�Z d�Z!dej"fd��YZ#e#ej$ffgZ%d�Z&dS(i����N(tHTTPConnection(tPoolManager(tlog(tsources(t
url_helper(tutil(tnet(tEphemeralDHCPv4tNoDHCPLeaseError(t	EventTypeshttp://169.254.42.42s/conf?format=jsontmetadata_urls/user_data/cloud-inittuserdata_urls/vendor_data/cloud-inittvendordata_urlii
cCsUtjd�}|dkrtStjjd�r5tStj�}d|krQtStS(s
    There are three ways to detect if you are on Scaleway:

    * check DMI data: not yet implemented by Scaleway, but the check is made to
      be future-proof.
    * the initrd created the file /var/run/scaleway.
    * "scaleway" is in the kernel cmdline.
    ssystem-manufacturertScaleways/var/run/scalewaytscaleway(Rt
read_dmi_datatTruetostpathtexiststget_cmdlinetFalse(tvendor_nametcmdline((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyton_scaleway2s	tSourceAddressAdaptercBs#eZdZd�Zed�ZRS(sF
    Adapter for requests to choose the local address to bind to.
    cKs#||_tt|�j|�dS(N(tsource_addresstsuperRt__init__(tselfRtkwargs((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyRMs	cCsPtjtjtjdfg}td|d|d|d|jd|�|_dS(Nit	num_poolstmaxsizetblockRtsocket_options(Rtdefault_socket_optionstsockett
SOL_SOCKETtSO_REUSEPORTRRtpoolmanager(RtconnectionsR R!R"((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytinit_poolmanagerQs	(t__name__t
__module__t__doc__RRR)(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyRIs	cCswyDtj|dd	d|ddd|dd��}tj|j�SWn,tjk
rr}|jdkrld	S�nXd	S(
sQ
    Retrieve user data or vendor data.

    Scaleway user/vendor data API returns HTTP/404 if user/vendor data is not
    set.

    This function calls `url_helper.readurl` but instead of considering
    HTTP/404 as an error that requires a retry, it considers it as empty
    user/vendor data.

    Also, be aware the user data/vendor API requires the source port to be
    below 1024 to ensure the client is root (since non-root users can't bind
    ports below 1024). If requests raises ConnectionError (EADDRINUSE), the
    caller should retry to call this function on an other port.
    tdatattimeouttretriesitsessiontexception_cbcSs&|jdko%t|jtjj�S(Ni�(tcodet
isinstancetcausetrequestst
exceptionstConnectionError(t_texc((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyt<lambda>wsi�N(RtreadurltNoneRt
decode_binarytcontentstUrlErrorR2(tapi_addressR.trequests_sessiontrespR9((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytquery_data_api_once\sc	Cs�x�tdt|d��D]�}yntjd||�tj�}|jdtdd|f��t|d|d|�}tjd	|�|SWqt	j
k
r�}tjd
||�tj
d�|}qqXqW|�dS(
s/Get user or vendor data.

    Handle the retrying logic in case the source port is used.

    Scaleway metadata service requires the source port of the client to
    be a privileged port (<1024).  This is done to ensure that only a
    privileged user on the system can access the metadata service.
    iis*Trying to get %s data (bind on port %d)...shttp://Rs0.0.0.0R.RAs%s-data downloadeds%Error while trying to get %s data: %siN(trangetmaxtLOGtdebugR5tSessiontmountRRCRR?twarningttimetsleep(	tapi_typeR@R/R.tportRAR-R9tlast_exc((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytquery_data_api�s*
	
tDataSourceScalewaycBs�eZdZiejejgd6Zd�Zd�Zd�Z	e
d��Ze
d��Zd�Z
d�Zeeed	�Ze
d
��Ze
d��ZRS(R
tnetworkcCs�tt|�j|||�tjtj|ddgi�tg�|_|jd|_|jd|_	|jd|_
t|jjdt
��|_t|jjdt��|_d|_d|_dS(Nt
datasourceR
R
RRR/R.(RRQRRt
mergemanydicttget_cfg_by_pathtBUILTIN_DS_CONFIGtds_cfgtmetadata_addresstuserdata_addresstvendordata_addresstinttgettDEF_MD_RETRIESR/tDEF_MD_TIMEOUTR.R<t_fallback_interfacet_network_config(Rtsys_cfgtdistrotpaths((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyR�s	cCs�tj|jd|jd|j�}tjtj|j	��|_
td|j|j|j�|_
td|j|j|j�|_dS(NR.R/s	user-datasvendor-data(RR;RXR.R/tjsontloadsRR=R>tmetadataRPRYtuserdata_rawRZtvendordata_raw(RRB((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyt_crawl_metadata�s			cCs�t�s
tS|jdkr.tj�|_ny<t|j��'tjdt	j
ddd|j�WdQXWn*tk
r�}tj
t	t|��tSXtS(NtlogfunctmsgsCrawl of metadata servicetfunc(RRR_R<Rtfind_fallback_nicRRtlog_timeRFRGRiRtlogexctstrR(Rte((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyt	_get_data�s		cCs�|jr|jS|jdkr1tj�|_nidd6d|jd6}idd6g}|jdr�|idd6d|jddd6d|jdd	d	6d|jdd
d
6g7}n||d<idd
6|gd6|_|jS(s`
        Configure networking according to data received from the
        metadata API.
        tphysicalttypes%stnametdhcp4tipv6tstatictaddresstgatewaytnetmasktsubnetsitversiontconfigN(R`R_R<RRmRf(RtnetcfgR|((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytnetwork_config�s	

 
cCsdS(N(R<(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytlaunch_index�scCs|jdS(Ntid(Rf(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytget_instance_id�scCs�g|jdD]}|d^q}d}t|�}xO|jjdg�D]8}|j|�sgqLn|j|| jdd��qLW|S(Ntssh_public_keystkeysAUTHORIZED_KEY=ttagsR8t (RftlenR\t
startswithtappendtreplace(RR�tssh_keystakeypretplenttag((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytget_public_ssh_keys�s$!cCs|jdS(Nthostname(Rf(Rtfqdnt
resolve_ipt
metadata_only((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytget_hostnamescCsdS(N(R<(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytavailability_zonescCsdS(N(R<(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytregions(R*R+tdsnameR	tBOOT_NEW_INSTANCEtBOOTt
update_eventsRRiRrtpropertyR�R�R�R�RR�R�R�(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyRQ�s					cCstj|t�S(N(Rtlist_from_dependstdatasources(tdepends((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytget_datasource_lists('RdRR$RKR5t$requests.packages.urllib3.connectionRt%requests.packages.urllib3.poolmanagerRt	cloudinitRtloggingRRRRtcloudinit.net.dhcpRRtcloudinit.eventR	t	getLoggerR*RFtDS_BASE_URLRVR]R^RtadapterstHTTPAdapterRRCRPt
DataSourceRQtDEP_FILESYSTEMR�R�(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyt<module>s8		'	)l