Viewing File: /usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyc


oB]c@sddlZddlZddlZddlZddlZddlmZddlmZddl	m
Zddl	mZddl	m
Z
ddl	mZddl	mZdd	lmZmZdd
lmZejeZdZiedd
6edd6edd6ZdZdZdZdejjfdYZdZ dZ!dej"fdYZ#e#ej$ffgZ%dZ&dS(iN(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}|dkrtStjjdr5tStj}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#eZdZdZedZRS(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|jSWn,tjk
rr}|jdkrld	SnXd	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>wsiN(RtreadurltNoneRt
decode_binarytcontentstUrlErrorR2(tapi_addressR.trequests_sessiontrespR9((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytquery_data_api_once\sc	Csxtdt|dD]}yntjd||tj}|jdtdd|ft|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_apis*
	
tDataSourceScalewaycBseZdZiejejgd6ZdZdZdZ	e
dZe
dZdZ
dZeeed	Ze
d
Ze
dZRS(R
tnetworkcCstt|j|||tjtj|ddgitg|_|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.pyRs	cCstj|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_metadatas			cCsts
tS|jdkr.tj|_ny<t|j'tjdt	j
ddd|jWdQXWn*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_datas		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_configs	

 
cCsdS(N(R<(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytlaunch_indexscCs|jdS(Ntid(Rf(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytget_instance_idscCsg|jdD]}|d^q}d}t|}xO|jjdgD]8}|j|sgqLn|j|| jddqLW|S(Ntssh_public_keystkeysAUTHORIZED_KEY=ttagsR8t (RftlenR\t
startswithtappendtreplace(RRtssh_keystakeypretplenttag((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pytget_public_ssh_keyss$!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_eventsRRiRrtpropertyRRRRRRRR(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyRQs					cCstj|tS(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_FILESYSTEMRR(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceScaleway.pyt<module>s8		'	)l
Back to Directory File Manager