oB]c@sdZddlZddlZddlZddlmZddlmZddlmZddl m Z ej e Z dZdZd Zd Zd Zd Zd ZdZdZdejfdYZeejffgZdZdS(sr This file contains code used to gather the user data passed to an instance on rootbox / hyperone cloud platforms iN(tlog(tsources(tutil(t EventTypes /etc/hostscCs=tjtdt}|r,tjdtStjdtS(Ntquiets5/etc/hosts exists - setting manage_etc_hosts to Falses=/etc/hosts does not exists - setting manage_etc_hosts to True(Rt load_filet ETC_HOSTStTruetLOGtdebugtFalse(thosts((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_manage_etc_hostss   cCsS|jd}t|dd>t|dd>t|dd>t|dS( Nt.iiiiiii(tsplittint(taddrtparts((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytip2int"scCsEdjgtddddD]}t||d>?d@^q S(NR iiii(tjointrangetstr(Rti((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytint2ip(scCstjdg|S(s Uses the prefered cloud-init subprocess def of util.subp and runs arping. Breaking this to a separate function for later use in mocking and unittests tarping(Rtsubp(tcmd((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyt_sub_arp,scCsTd}|jd krd}nx/|D]'}tdd||d|d gq%WdS( Ns-Stfedoratcentostrhels-ss-ct2tsourcet destination(RRR(tnameR(titemstdistrot source_paramtitem((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytgratuitous_arp5s   c Csd}gtjjD]0\}}|jddjdkr|^q}x|D]}y2tjd|dtdddg}|rPnWqVtk r}|j t j krqqVtj k rtj t d |qVXqVW|stj t d tS|S( NtLABELttCLOUDMDtdevicetcallbacktmtypetvfattfats-Failed to mount %s when looking for user datas$Failed to load metadata and userdata(tNoneRtblkidR#tgettuppertmount_cbtread_user_data_callbacktOSErrorterrnotENOENTtMountFailedErrortlogexcRR (trbx_datatdevtbdatatdevicesR+terr((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_mdAs,*    c Csidd6gt|D]\}}idd6djt|d6|djd6g|d D]V}id d6|d d 6|d d d 6dd6|d dd6|d ddd6^q_d6^qd6S(sGenerate network configuration @param netadps: A list of network adapter settings @returns: A dict containing network config itversiontphysicalttypeseth{}R"t macaddresst mac_addresstiptstatictaddresstnetworktnetmasktautotcontroltgatewaytdnst nameserverstdns_nameserverstsubnetstconfig(t enumeratetformatRtlower(tnetadpsRtnetadpRF((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytgenerate_network_config]sc CsStjdtjdtjj|ddt}tjdtjj|ddt}d|ksrd|krtjt d d/S|j d ij d }|j d ij d g}d/}|j d ij d r|d d d}nt |d}i|d6i|ddd6|ddd6gd6d6g|dD]}}|dD]l}|ddt t|dddt t|dddgD]} i|dd6| d6^qqTqFd6itd6td 6ii|d6|d!6d"gd#6|d$6td%6|d&6d'd(6d)6d*6|d+6td,6d-6} t jd.t j| | S(0sThis callback will be applied by util.mount_cb() on the mounted drive. @param mount_dir: String representing path of directory where mounted drive is available @returns: A dict containing userdata, metadata and cfg based on metadata. ttexttfnames cloud.jsontdecodes user.dataRtvmRWs(Failed to load metadata. Invalid format.tadditionalMetadatatusernametsshKeystpasswordtsha512tuserdatat_ids instance-idR"slocal-hostnames public-keystmetadataRFRIRMiiRHR R!R't ssh_pwautht disable_roottgecossALL=(ALL) NOPASSWD:ALLtsudotpasswdt lock_passwdtssh_authorized_keyss /bin/bashtshellt default_usert system_infotnetwork_configtmanage_etc_hoststcfgsreturning DATA object:N(Rt load_jsonRtostpathRR RR:RR0R2RXRRR R ( t mount_dirt meta_datat user_dataR^tssh_keysthashRIRWRFttargettdata((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyR5{sZ       J   tDataSourceRbxCloudcBsueZdZiejejgd6ZdZdZdZ e dZ dZ dZ dZd ZRS( tRbxCloudRIcCs&tjj||||d|_dS(N(Rt DataSourcet__init__R0tseed(tselftsys_cfgR$tpaths((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyRscCs#tjj|}d||jfS(Ns %s [seed=%s](RR~t__str__R(Rtroot((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyRscCsAt}|d|_|d|_|d|_|d|_tS(sw Metadata is passed to the launching instance which is used to perform instance configuration. RbRdR'Rq(R@t userdata_rawRdR'RqR(RR;((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyt _get_datas      cCs |jdS(NRo(Rq(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyRoscCs |jdS(Ns public-keys(Rd(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_public_ssh_keysscCs|jS(N(R(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_userdata_rawscCs|jS(N(Rq(R((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_config_objscCst|j|jdS(N(R'R$(RRqtis_new_instance((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytactivates(t__name__t __module__tdsnameRtBOOT_NEW_INSTANCEtBOOTt update_eventsRRRtpropertyRoRRRR(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyR|s      cCstj|tS(N(Rtlist_from_dependst datasources(tdepends((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_datasource_lists(t__doc__R7Rstos.patht cloudinitRtloggingRRtcloudinit.eventRt getLoggerRRRR RRRR'R@RXR5R~R|tDEP_FILESYSTEMRR(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyt s(        L.