Current File : //lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyc
�
oB�]c@sdZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
eje�Z
dZd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zdejfd��YZeejffgZd�ZdS(sr
This file contains code used to gather the user data passed to an
instance on rootbox / hyperone cloud platforms
i����N(tlog(tsources(tutil(t	EventTypes
/etc/hostscCs=tjtdt�}|r,tjd�tStjd�tS(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|d�d>t|d�d>t|d�d>t|d�S(	Nt.iiiiiii(tsplittint(taddrtparts((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytip2int"scCsEdjgtd�ddd�D]}t||d>?d@�^q �S(NR
ii����ii�(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	g�q%WdS(Ns-Stfedoratcentostrhels-ss-ct2tsourcetdestination(RRR(tnameR(titemstdistrotsource_paramtitem((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytgratuitous_arp5s	

c	Csd}gtj�j�D]0\}}|jdd�j�dkr|^q}x�|D]�}y2tjd|dtdddg�}|r�PnWqVtk
r�}|j	t	j
kr��q�qVtjk
r�tj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	Cs�idd6gt|�D]�\}}idd6djt|��d6|dj�d6g|d	D]V}id
d6|dd6|dd
d
6dd6|ddd6|dddd6^q_d6^qd6S(s�Generate network configuration

    @param netadps: A list of network adapter settings

    @returns: A dict containing network config
    itversiontphysicalttypeseth{}R"t
macaddresstmac_addresstiptstatictaddresstnetworktnetmasktautotcontroltgatewaytdnstnameserverstdns_nameserverstsubnetstconfig(t	enumeratetformatRtlower(tnetadpsRtnetadpRF((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytgenerate_network_config]scCsStjdtjdtjj|d�dt��}tjdtjj|d�dt�}d|ksrd|kr�tjt	d	�d/S|jd
i�jd�}|jd
i�jdg�}d/}|jd
i�jd
�r�|d
d
d}nt|d�}i|d6i|ddd6|ddd6gd6d6g|dD]}}|dD]l}|ddt
t|dd�d�t
t|dd�d�gD]}	i|dd6|	d6^q�qTqFd6itd6td 6ii|d6|d!6d"gd#6|d$6td%6|d&6d'd(6d)6d*6|d+6t�d,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_idsinstance-idR"slocal-hostnamespublic-keystmetadataRFRIRMiiRHR R!R't
ssh_pwauthtdisable_roottgecossALL=(ALL) NOPASSWD:ALLtsudotpasswdtlock_passwdtssh_authorized_keyss	/bin/bashtshelltdefault_usertsystem_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


tDataSourceRbxCloudcBsueZdZiejejgd6Zd�Zd�Zd�Z	e
d��Zd�Zd�Z
d�Zd	�ZRS(
tRbxCloudRIcCs&tjj||||�d|_dS(N(Rt
DataSourcet__init__R0tseed(tselftsys_cfgR$tpaths((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyR�scCs#tjj|�}d||jfS(Ns%s [seed=%s](RR~t__str__R�(R�troot((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyR��scCsAt�}|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(R�R;((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyt	_get_data�s	



cCs|jdS(NRo(Rq(R�((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyRo�scCs|jdS(Nspublic-keys(Rd(R�((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_public_ssh_keys�scCs|jS(N(R�(R�((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_userdata_raw�scCs|jS(N(Rq(R�((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_config_obj�scCst|j|j�dS(N(R'R$(R�Rqtis_new_instance((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytactivate�s(t__name__t
__module__tdsnameRtBOOT_NEW_INSTANCEtBOOTt
update_eventsRR�R�tpropertyRoR�R�R�R�(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyR|�s						cCstj|t�S(N(Rtlist_from_dependstdatasources(tdepends((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytget_datasource_list�s(t__doc__R7Rstos.patht	cloudinitRtloggingRRtcloudinit.eventRt	getLoggerR�RRRRRRR'R@RXR5R~R|tDEP_FILESYSTEMR�R�(((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pyt<module>s(										L.