Current File : //usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyo
�
oB�]c@sdZddlmZmZmZddlmZmZmZddl	m
Z
ddl	mZddl	mZddlm
Z
ddl	mZdd	lZdd	lZeje�Zied
6ZdZdZd
ZdZd�Zd�Zdejfd��YZd�Zd�Z d�Z!d�Z"ed	dd�Z$eej%ffgZ&d�Z'edkrdd	l(Z(dd	l)Z)e(j*dd�Z+e+j,dddd d!d"e�e+j-�Z.e)j/�d#kr�d$nd	Z0e$d%e.j1d&e0�Z2e �e2d'<ej3e2�GHnd	S((sdDatasource for Oracle (OCI/Oracle Cloud Infrastructure)

OCI provides a OpenStack like metadata service which provides only
'2013-10-17' and 'latest' versions..

Notes:
 * This datasource does not support the OCI-Classic. OCI-Classic
   provides an EC2 lookalike metadata service.
 * The uuid provided in DMI data is not the same as the meta-data provided
   instance-id, but has an equivalent lifespan.
 * We do need to support upgrade from an instance that cloud-init
   identified as OpenStack.
 * Both bare-metal and vms use iscsi root
 * Both bare-metal and vms provide chassis-asset-tag of OracleCloud.com
i����(tcombine_urltreadurltUrlError(tdhcptget_interfaces_by_mactis_netfail_master(tnet(tsources(tutil(tcmdline(tlogNtconfigure_secondary_nicssOracleCloud.coms!http://169.254.169.254/openstack/s$http://169.254.169.254/opc/v1/vnics/i(#cCsTtt�}tjt|��}d|dkrBtjd�dSt�}x|dD]�}|dj�}||kr�tj	d|�qVn||}|ddkr�id	d
6|dd6}|d
j
i|d6dd
6|d6td6|gd6�qV|ddkrVi|dgd6td6td6td6i|d6d6|d|<qVqVWdS(s�
    Fetch data from Oracle's IMDS, generate secondary NIC config, merge it.

    The primary NIC configuration should not be modified based on the IMDS
    values, as it should continue to be configured for DHCP.  As such, this
    takes an existing network_config dict which is expected to have the primary
    NIC configuration already present.  It will mutate the given dict to
    include the secondary VNICs.

    :param network_config:
        A v1 or v2 network config dict with the primary NIC already configured.
        This dict will be mutated.

    :raises:
        Exceptions are not handled within this function.  Likely exceptions are
        those raised by url_helper.readurl (if communicating with the IMDS
        fails), ValueError/JSONDecodeError (if the IMDS returns invalid JSON),
        and KeyError/IndexError (if the IMDS returns valid JSON with unexpected
        contents).
    tnicIndexis\VNIC metadata indicates this is a bare metal machine; skipping secondary VNIC configuration.NitmacAddrs)Interface with MAC %s not found; skippingtversiontstaticttypet	privateIptaddresstconfigtnametphysicaltmac_addresstmtutsubnetsit	addressestdhcp4tdhcp6t
macaddresstmatcht	ethernets(
RtVNIC_METADATA_URLtjsontloadststrtLOGtwarningRtlowertdebugtappendtMTUtFalse(tnetwork_configtresptvnicstinterfaces_by_mact	vnic_dictRRtsubnet((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyt!_add_network_config_from_opc_imds+s8	

cCs�d|krdS|ddkr8tjd|d�dSt�}|ddkr�xJg|dD]}d|kr_|^q_D]c}|ddkr{d	|kr�|d	}|j|�}|s�q{q�t|�r�|d	=q�q�q{q{Wn�|ddkr�x�|jd
i�j�D]�\}}d|kr|jdi�jd�}|r�|j|�}|sbqq�t|�r�|dd=|d
=||dd<q�q�qqWndS(sP
    Search network config physical interfaces to see if any of them are
    a netfailover master.  If found, we prevent matching by MAC as the other
    failover devices have the same MAC but need to be ignored.

    Note: we rely on cloudinit.net changes which prevent netfailover devices
    from being present in the provided network config.  For more details about
    netfailover devices, refer to cloudinit.net module.

    :param network_config
       A v1 or v2 network config dict with the primary NIC, and possibly
       secondary nic configured.  This dict will be mutated.

    RNiis+Ignoring unknown network config version: %sRRRRRRRsset-nameR(ii(R#R&RtgetRtitems(R*tmac_to_nametctcfgtmactcur_namet_tmacaddr((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyt_ensure_netfailover_safeos:		0
%tDataSourceOraclecBs�eZdZd	Zd	Zejjejj	ejj
ejjfZej
Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed��ZRS(
tOraclecOsPtt|�j|||�tjtj|d|jgi�tg�|_dS(Nt
datasource(	tsuperR;t__init__Rt
mergemanydicttget_cfg_by_pathtdsnametBUILTIN_DS_CONFIGtds_cfg(tselftsys_cfgtargstkwargs((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyR?�scCst�S(s@Check platform environment to report if this datasource may run.(t_is_platform_viable(RE((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyRI�scCs�|j�stSt�r(|j�}n(tjtj���|j�}WdQX||_|d}|j	d�|_
|d|_|j	d�}|r�||_yt
j|�|_Wq�tk
r�}tjd|�d|_q�Xnd}tg|D]/}||dkr�||dj	|�f^q��}ddddf}x9|D]1\}	}
|	|dkrI|d|	||
<qIqIW||_tS(Ns
2013-10-17t	user_datatsystem_uuidtvendor_datas"Invalid content in vendor-data: %stpublic_keyst	meta_datatavailability_zonesavailability-zonethostnameslocal-hostnametlaunch_indexslaunch-indextuuidsinstance-id(RM(ROsavailability-zone(RPslocal-hostname(RQslaunch-index(RRsinstance-id(RIR)t_is_iscsi_roottcrawl_metadataRtEphemeralDHCPv4Rtfind_fallback_nict_crawled_metadataR1tuserdata_rawRKtvendordata_pureRtconvert_vendordatatvendordata_rawt
ValueErrorR#R$tNonetdicttmetadatatTrue(REtdatatvdatatvdtetmdcopiestktmdtmdtransRBtciname((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyt	_get_data�s<		

	<		cCst�S(N(t
read_metadata(RE((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyRT�scCsdtS(s/Return the subplatform metadata source details.s
metadata (%s)(tMETADATA_ENDPOINT(RE((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyt_get_subplatform�scCstj|j�S(s�quickly check (local only) if self.instance_id is still valid

        On Oracle, the dmi-provided system uuid differs from the instance-id
        but has the same life-span.(Rtinstance_id_matches_system_uuidRK(RERF((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pytcheck_instance_id�scCstj|jjd��S(NRM(Rtnormalize_pubkey_dataR_R1(RE((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pytget_public_ssh_keys�scCs�|jtjkr�tj�|_|js?|jj�|_n|jjd�r�yt	|j�Wq�t
k
r�tjt
d�q�Xnt|j�n|jS(s�Network config is read from initramfs provided files
        If none is present, then we fall back to fallback configuration.

        One thing to note here is that this method is not currently
        considered at all if there is is kernel/initramfs provided
        data.  In that case, stages considers that the cmdline data
        overrides datasource provided data and does not consult here.

        We nonetheless return cmdline provided config if present
        and fallback to generate fallback.Rs0Failed to fetch secondary network configuration!(t_network_configRtUNSETR	tread_initramfs_configtdistrotgenerate_fallback_configRDR1R0t	ExceptionRtlogexcR#R:(RE((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyR*�s	
N(t__name__t
__module__RBR]RKRYRtNetworkConfigSourceR	tdst	initramfst
system_cfgtnetwork_config_sourcesRsRrR?RIRjRTRmRoRqtpropertyR*(((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyR;�s 							-				cCs)tjd�}|dkrdS|j�S(Nssystem-uuid(Rt
read_dmi_dataR]R%(tsys_uuid((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyt_read_system_uuidscCstjd�}|tkS(Nschassis-asset-tag(RR�tCHASSIS_ASSET_TAG(t	asset_tag((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyRI"scCsttj��S(N(tboolR	Rt(((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyRS'scCsd|j�jd�s|j�Stjd|tjtjB�}g|D]}|jd�sE|^qES(s�Return a list entries parsed from content.

    OpenStack's metadata service returns a newline delimited list
    of items.  Oracle's implementation has html formatted list of links.
    The parser here just grabs targets from <a href="target">
    and throws away "../".

    Oracle has accepted that to be buggy and may fix in the future
    to instead return a '
' delimited plain text list.  This function
    will continue to work if that change is made.s<html>shref="(?P<target>[^"]*)"t.(R%t
startswitht
splitlinestretfindallt	MULTILINEt
IGNORECASE(tcontentR2ti((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyt_load_index+s

s
2013-10-17cCs�t||�d}|d
kr+t�}n|sCtjd��ny;t|�}|j�s}tjd||jf��nWn,tk
r�}tjd||f��nXt	|j
jd��}tj
d||�d}||krtjd||f��ni|d	6}xn|D]f}	tt||	��}
|	jd
�rstj|
j
jd��||	jd�d<q|
j
||	<qWi||6S(sRead metadata, return a dictionary.

    Each path listed in the index will be represented in the dictionary.
    If the path ends in .json, then the content will be decoded and
    populated into the dictionary.

    The system uuid (/sys/class/dmi/id/product_uuid) is also populated.
    Example: given paths = ('user_data', 'meta_data.json')
    This would return:
      {version: {'user_data': b'blob', 'meta_data': json.loads(blob.decode())
                 'system_uuid': '3b54f2e0-3ab2-458d-b770-af9926eee3b2'}}
    t/sFailed to read system uuid.sBad response from %s: %ssFailed to read index at %s: %ssutf-8sindex url %s contained: %ssmeta_data.jsons*Required field '%s' missing in index at %sRKs.jsonR�iN(RR]R�RtBrokenMetadataRtoktcodeRR�tcontentstdecodeR#R&tendswithR R!t
rpartition(t
endpoint_baseR�RtendpointR+Rdtentriestmdjtrettpathtresponse((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyRk=s4

/cCstj|t�S(N(Rtlist_from_dependstdatasources(tdepends((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pytget_datasource_listvst__main__tdescriptionsQuery Oracle Cloud Metadatas
--endpointtmetavartURLthelps The url of the metadata service.tdefaultisuuid-not-available-not-rootR�R�tis_platform_viable(4t__doc__tcloudinit.url_helperRRRt
cloudinit.netRRRt	cloudinitRRRR	R
tloggingR R�t	getLoggerRyR#R)RCR�RlRR(R0R:t
DataSourceR;R�RIRSR�R]RktDEP_FILESYSTEMR�R�targparsetostArgumentParsertparsertadd_argumentt
parse_argsRGtgeteuidR�R�Rat
json_dumps(((sF/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceOracle.pyt<module>sN
	D	2|				3