f{BdZddlZddlZddlZddlZddlZddlmZddlm Z m Z m Z ddl m Z mZmZmZmZddlmZddlmZmZmZmZddlmZej6eZd d iZd Zd Z e d zZ!dZ"ddiZ#eddZ$GddejJZ&deddfdZ'GddejPZ)Gdde)Z*de e+fdZ,de-fdZ.de+de/fdZ0de+de e e+e+ffd Z1d e)jde)jfd!d"e-de e$fd#Z4e)ejjffe*ejjejlffgZ7d$Z8ed%k(rOddl9Z9d&Z:e9jve:'Ze j~e4e.d(yy))a3Datasource for Oracle (OCI/Oracle Cloud Infrastructure) Notes: * This datasource does not support 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. * Bare metal instances use iSCSI root, virtual machine instances do not. * Both bare metal and virtual machine instances provide a chassis-asset-tag of OracleCloud.com. N) namedtuple)DictOptionalTuple) atomic_helperdminetsourcesutil) NetworkConfig)cmdline ephemeralget_interfaces_by_macis_netfail_master) wait_for_urlconfigure_secondary_nicsFzOracleCloud.comz&http://169.254.169.254/opc/v{version}/z{path}/i(# Authorizationz Bearer Oracle OpcMetadataz version instance_data vnics_dataceZdZdZdefdZy)KlibcOracleNetworkConfigSourcezOverride super class to lower the applicability conditions. If any `/run/net-*.cfg` files exist, then it is applicable. Even if `/run/initramfs/open-iscsi.interface` does not exist. returnc,t|jS)zOverride is_applicable)bool_filesselfs D/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceOracle.py is_applicablez,KlibcOracleNetworkConfigSource.is_applicable:sDKK  N)__name__ __module__ __qualname____doc__rrrrrr3s !t!rrnetwork_configrc<d|vry|ddvrtjd|dyt}|ddk(rT|dDcgc] }d|vs| c}D]8}|ddk(s d |vs|d }|j|}|s*t |s6|d =:y|dd k(r|jd ij D]_\}}d |vs |jd ijd }|s/|j|}|sCt |sO|d d =|d=||d d<ayycc}w)aP 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. versionN)z+Ignoring unknown network config version: %sr(configtypephysical mac_addressr) ethernetsmatch macaddresszset-namename)LOGdebugrgetritems)r% mac_to_nameccfgmaccur_name_macaddrs r_ensure_netfailover_safer=?sY &i . 9 9 %  ')Ki A%-h7G!6Q;AG /C6{j( C'm,C*s3H# *84 . /  "a '$((b9??A 8FAs#~'''2.22<@*w7H# *84L6 O/7G V, 8 (Hs D DceZdZUdZdZdZejjejjejjejjfZ e ejdfed<gddZeed<dZd Zd Zfd Zd ed dffd Zd efdZed efdZdZd efdZdZd efdZd efdZe dZ!ddefdZ"xZ#S)DataSourceOracleOracleN.network_config_sourcesr()r*r'_network_configTcFtt| |g|i|d|_t j t j |d|jgitg|_ t|_ |j}|j|_|j|_y)N datasource)superr?__init__ _vnics_datar mergemanydictget_cfg_by_pathdsnameBUILTIN_DS_CONFIGds_cfgr_network_config_sourceget_url_paramsmax_wait_seconds url_max_waittimeout_seconds url_timeout)rsys_cfgargskwargs url_params __class__s rrHzDataSourceOracle.__init__s .wHHH(($$W|T[[.I2N!   'E&F#((* &77%55rci_pkl_versionrct||t|ds t|ddt|dst|dt yy)NrIrO)rG _unpicklehasattrsetattrr)rrZrYs rr\zDataSourceOracle._unpicklesJ .)t]+ D- .t56 (.0 7rcLt|jjdgS)Nr*)rrBr4rs r_has_network_configz$DataSourceOracle._has_network_configs D((,,Xr:;;rctS)z@Check platform environment to report if this datasource may run.)_is_platform_viabler$rr ds_detectzDataSourceOracle.ds_detects #$$rcZt|_|jrQtj|j t jtjddtd}ntj}|j }|jjdt d}|5t#|xs||j$|j&}dddsy|j(x}|_t,j|j. |_|j2|_|d |d d |d |dd|_d|vrQ|djd}|rt9j:||_|djd|j6d<y#1swYxYw)Nr)instancer'path)urlheaders)ifaceconnectivity_url_datarfetch_vnics_datamax_waittimeoutF)r' ociAdNameidrhostname displayName)zavailability-zonez instance-idz launch-indexzlocal-hostnamer1metadata user_datassh_authorized_keys public_keysT)_read_system_uuid system_uuidperform_dhcp_setuprEphemeralDHCPv4distror find_fallback_nicMETADATA_PATTERNformat V2_HEADERSr nullcontext_is_iscsi_rootrNr4rMread_opc_metadatarRrT instance_data_crawled_metadata METADATA_ROOTr'metadata_address vnics_datarIrtbase64 b64decode userdata_raw)rnetwork_contextfetch_primary_nicfetch_secondary_nicsfetched_metadatadatarus r _get_datazDataSourceOracle._get_datas,.  " "'77 ++-+221:2N)'O#..0O $ 3 3 55#{{ & 8 9   0!2!J6J**((     (8(F(FFt% - 4 4$,,!5! ,66"&k!2:":.'     Z(,,[9I$*$4$4Y$?!+/ +;+?+?%,DMM- (?  s 7'F!!F*c@tj|jS)zquickly 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.)r instance_id_matches_system_uuidry)rrUs rcheck_instance_idz"DataSourceOracle.check_instance_ids 66t7G7GHHrc^tj|jjdS)Nrw)r normalize_pubkey_datartr4rs rget_public_ssh_keysz$DataSourceOracle.get_public_ssh_keyss",,T]]->->}-MNNrc6|jjS)z)Return whether we are on a iscsi machine.)rOrrs rrzDataSourceOracle._is_iscsi_roots**88::rc6|jjSN)rO render_configrs r_get_iscsi_configz"DataSourceOracle._get_iscsi_configs**88::rc|jr |jSd}|jr|j|_|jstj dd}|j jdtd}|s|r |j|t|j|jS#t$rtjtdYFwxYw)zNetwork config is read from initramfs provided files Priority for primary network_config selection: - iscsi - imds If none is present, then we fall back to fallback configuration. FzLCould not obtain network configuration from initramfs. Falling back to IMDS.Trz+Failed to parse IMDS network configuration!)r`rBrrr2warningrNr4rM!_add_network_config_from_opc_imds Exceptionr logexcr=)r set_primary set_secondarys rr%zDataSourceOracle.network_configs  # # %'' '    #'#9#9#;D '') KK( K  & 8 9  - 66{C !!5!56###  A sC#C+*C+rc |jtjdy|s'd|jdvrtjdyt}|r |jn|jdd}t |D]\}}|xr|dk(}|dj }||vrtjd|>||}t j|d } |jd dk(rJ|rd d i} nd |dd| jd} |d|t| gd} |jdj| |jd dk(std|id|d} |s|dd| jg| d<| |jd|<y)aGenerate primary and/or secondary NIC config from IMDS and merge it. It will mutate the network config to include the secondary VNICs. :param set_primary: If True set primary interface. :raises: Exceptions are not handled within this function. Likely exceptions are KeyError/IndexError (if the IMDS returns valid JSON with unexpected contents). Nz#NIC data is UNSET but should not benicIndexrz\VNIC metadata indicates this is a bare metal machine; skipping secondary VNIC configuration.r(macAddrz)Interface with MAC %s not found; skippingsubnetCidrBlockr'r+dhcpstatic privateIp/)r+addressr,)r1r+r-mtusubnetsr*r)r0F)rr/dhcp6dhcp4 addressesr.) rIr2rr enumeratelower ipaddress ip_networkrB prefixlenMTUappend) rrinterfaces_by_macrindex vnic_dict is_primaryr-r1networksubnetinterface_configs rrz2DataSourceOracle._add_network_config_from_opc_imdss    # KK= >  d.>.>q.A A KK9  13)4T%%$:J:J12:N )* 5+ K E9$3!J#I.446K"33 ?$[1D**95F+GHG##I.!3$f-F!)(56a8I8I7JKF!&#. &x $ $$X.556FG%%i0A5*K8"' $ "$[12!G4E4E3FG5$[1;K$$[1$7W+ Kr)F)$r r!r"rLryvendordata_purer NetworkConfigSourceCMD_LINE SYSTEM_CFGDS INITRAMFSrAr__annotations__rBdictrzrRrTrHintr\rr` staticmethodrcrrrrrpropertyr%r __classcell__)rYs@rr?r?ss' FKO##,,##..##&&##-- GE'"="=s"BC(*a8OT8LK6   tjd}|tk(S)Nzchassis-asset-tag)rrCHASSIS_ASSET_TAG) asset_tags rrbrbvs!!"56I ) ))rrhc,|jdrdSdS)Nzhttp://169.254.169.254/opc/v2r)r() startswithrhs r _url_versionr{s>?1FQFrc.t|dk(rtSdS)Nr))rrrs r _headers_cbrs%c*a/:9T9rrlrmcftjddtjddg}tj}t|||td\}}|st j dytj|jd }t|}d} |rttj|d g|tj|z z |td\} } | r%tj| jd } nt j d t||| S) aoFetch metadata from the /opc/ routes. :return: A namedtuple containing: The metadata version as an integer The JSON-decoded value of the instance data endpoint on the IMDS The JSON-decoded value of the vnics data endpoint if `fetch_vnics_data` is True, else None or None if fetching metadata failed r)rerfr(r)rnro headers_cb sleep_timezFailed to fetch IMDS metadata!Nzutf-8vnicsz+Failed to fetch IMDS network configuration!) r~rtimerrr2rjsonloadsdecoderr) rmrnrourls start_time instance_urlinstance_responsermetadata_versionr vnics_urlvnics_responses rrrs*  ; ; DJ&2  '#L#  45JJ077@AM#L1J%1  $ $-=G $ L Mz!9:" % ! > N$9$9'$BCJ KKE F ' CCrc6tj|tSr)r list_from_depends datasources)dependss rget_datasource_listrs  $ $Wk ::r__main__z Query Oracle Cloud metadata and emit a JSON object with two keys: `read_opc_metadata` and `_is_platform_viable`. The values of each are the return values of the corresponding functions defined in DataSourceOracle.py.) description)rrb)@r#rrrloggingr collectionsrtypingrrr cloudinitrrr r r cloudinit.distros.networkingr cloudinit.netr rrrcloudinit.url_helperr getLoggerr r2rMrrr~rrrKlibcNetworkConfigSourcerr= DataSourcer?rstrrxrrbrrrrRrTrDEP_FILESYSTEM DEP_NETWORKrrargparserArgumentParserparser parse_argsprint json_dumpsr$rrrs   "((<<6 .g!&8  9,  / (JK  !W%E%E !18]18t18hwKw))wKt*:8C=: *T* GcGcG:S:Xd38n5: #  * *  ( ( 7D7D k 7Dx..01  " "      ; z K %X $ $ =F     %6%8':'<  r