ó oBú]c@s[ddlZddlmZddlmZmZddlmZddlmZddlm Z ddl m Z ddl m ZejeƒZd Zd Zied 6Zd Zd ZeegZdZegZde jejfd„ƒYZdefd„ƒYZdddd„Ze d„Z!eej"ffeej"ej#ffgZ$d„Z%dS(iÿÿÿÿN(tlog(tEphemeralDHCPv4tNoDHCPLeaseError(tsources(t url_helper(tutil(t openstack(tDataSourceOracleshttp://169.254.169.254siid-dsopenstacks instance-idsOpenStack NovasOpenStack ComputetOpenTelekomCloudtDataSourceOpenStackcBsbeZdZejZeZd„Zd„Z d„Z d„Z e d„ƒZ d„Zd„ZRS(t OpenStackcCshtt|ƒj|||ƒd|_tj|jƒ|_d|_ i|_ t j |_ t j |_dS(N(tsuperR t__init__tNonetmetadata_addressRtfetch_ssl_detailstpathst ssl_detailstversiontfilesRtUNSETt ec2_metadatat network_json(tselftsys_cfgtdistroR((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyR ,s    cCs/tjj|ƒ}d||j|jf}|S(Ns%s [%s,ver=%s](Rt DataSourcet__str__tdsmodeR(Rtroottmstr((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyR5sc Cs|jjdtgƒ}g|D]}tj|ƒr|^q}t|ƒt|ƒkrtjdtt|ƒt|ƒƒƒnt |ƒr–|}ntj dƒtg}g}i}x7|D]/}t j |dƒ}|j |ƒ|||t|jƒ)tjdt j ddd|j ƒ}WdQXWqìt t jfk r¨}tjt t|ƒƒtSXn@y|j ƒ}Wn-t jk rë}tjt t|ƒƒtSX|j|jd ƒgƒ|_|jt jkr tS|jd iƒ}tj|tgƒ}||_|jd ƒ|_|jd ƒ|_|jd ƒ|_|d|_|jj|jdiƒƒ|jdƒ}||_yt j|ƒ|_Wn,t k r }t j!d|ƒd|_nXt#S(s Crawl metadata, parse and persist that data for this instance. @return: True when metadata discovered indicates OpenStack datasource. False when unable to contact metadata service or when metadata format is invalid or disabled. tOracletdatasource_listt accept_oracletlogfunctmsgsCrawl of metadata servicetfuncNRtmetadatas ec2-metadatat networkdatatuserdataRRt vendordatas"Invalid content in vendor-data: %s($RR$tdetect_openstacktFalsetperform_dhcp_setupRtfallback_interfaceRtlog_timeR(R)t_crawl_metadataRRtInvalidMetaDataExceptiontlogexctstrt_determine_dsmodeRtDSMODE_DISABLEDt mergemanydicttDEFAULT_METADATARQRRt userdata_rawRRtupdatetvendordata_puretconvert_vendordatatvendordata_rawt ValueErrorR,R RH(Rtoracle_consideredtresultstetmdtvd((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyt _get_datavsH      c Cs y"|jƒs!tjdƒ‚nWn4tk rX}tjdjdt|ƒƒƒ‚nX|jƒ}yLtjt j dt d|j gdi|j d6|jd6|jd 6ƒ}Wnhtjk rÞ}tjt|ƒƒ‚n>tjtfk rd jd |j ƒ}tj|ƒ‚nX|S( sÖCrawl metadata service when available. @returns: Dictionary with all metadata discovered for this datasource. @raise: InvalidMetaDataException on unreadable or broken metadata. s No active metadata service founds,IOError contacting metadata service: {error}terrors#Crawl of openstack metadata servicetargstkwargsRtretriesR"sBroken metadata address {addr}taddr(R@RR[tIOErrortformatR]R/RRYR(R)tread_metadata_serviceRRt num_retriesR3Rt NonReadabletBrokenMetadata(RRjR<tresultRO((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyRZ§s.        (t__name__t __module__tdsnameRRRFRVRWR RR@RCtpropertyRJRmRZ(((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyR #s   !  1tDataSourceOpenStackLocalcBseZdZeZRS(suRun 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. (RzR{t__doc__RHRW(((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyR~ÉsicCs+tj|d|d|d|ƒ}|jƒS(NRR"Rq(RtMetadataReadertread_v2(tbase_urlRR"Rqtreader((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyRuÕscCs„tjƒstStjdƒ}|tkr/tStjdƒtkrHtS|r^tjƒr^tStjdƒj dƒt kr€tSt S(s<Return True when a potential OpenStack platform is detected.ssystem-product-nameschassis-asset-tagit product_name( Rtis_x86RHt read_dmi_datatVALID_DMI_PRODUCT_NAMEStVALID_DMI_ASSET_TAGStoraclet_is_platform_viablet get_proc_envR$tDMI_PRODUCT_NOVARV(RMR„((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyRUÜs  cCstj|tƒS(N(Rtlist_from_dependst datasources(tdepends((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pytget_datasource_listôs(&R0t cloudinitRtloggingtcloudinit.net.dhcpRRRRRtcloudinit.sources.helpersRtcloudinit.sourcesRR‰t getLoggerRzR(R%t DEFAULT_IIDRaRŒtDMI_PRODUCT_COMPUTER‡tDMI_ASSET_TAG_OPENTELEKOMRˆt SourceMixinRR R~R RuRVRUtDEP_FILESYSTEMt DEP_NETWORKRŽR(((sI/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOpenStack.pyts2    ¦