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


oB]c@sdZddlZddlZddlZddlmZddlmZddlmZddl	m
Z
ejeZ
dZdZd	Zd
ZdZd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-ct2tsourcetdestination(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
krqqVtjk
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|dd6|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
macaddresstmac_addresstiptstatictaddresstnetworktnetmasktautotcontroltgatewaytdnstnameserverstdns_nameserverstsubnetstconfig(t	enumeratetformatRtlower(tnetadpsRtnetadpRF((sH/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceRbxCloud.pytgenerate_network_config]scCsStjdtjdtjj|ddt}tjdtjj|ddt}d|ksrd|krtjt	d	d/S|jd
ijd}|jd
ijdg}d/}|jd
ijd
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_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


tDataSourceRbxCloudcBsueZdZiejejgd6ZdZdZdZ	e
dZdZ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(Nspublic-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_dependstdatasources(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<module>s(										L.
Back to Directory File Manager