x[hLTdZddlZddlZddlZddlZddlZddlmZmZm Z m Z m Z m Z ddl mZmZmZmZmZddlmZddlmZmZmZmZddlmZej8eZdd iZd Z d Z!d Z"e!d zZ#e"d zZ$ddiZ%dZ&Gdde Z'GddejPZ)deddfdZ*GddejVZ,Gdde,Z-de.fdZ/de e.fdZ0de1fdZ2d e.de3fd!Z4d e.de ee.e.ffd"Z5d e.de.fd#Z6d e,jne,jpe#gd$d%e1d&e e.de e'fd'Z9e,ejtffe-ejtejvffgZe?eje9e$e#g+e2d,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)AnyDictList NamedTupleOptionalTuple) 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+http://[fd00:c1::a9fe:a9fe]/opc/v{version}/z{path}/ Authorizationz Bearer Oraclei(#cPeZdZUeed<eeefed<eeeefed<eed<y)ReadOpcMetadataResponseversion instance_data vnics_data imds_url_usedN) __name__ __module__ __qualname__int__annotations__rstrrrD/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceOracle.pyrr4s. LS>!c3h((r#rceZdZdZdefdZy)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 r$ is_applicablez,KlibcOracleNetworkConfigSource.is_applicableBsDKK  r#N)rrr__doc__r)r-r"r#r$r&r&;s !t!r#r&network_configr'c<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. rN)z+Ignoring unknown network config version: %sr1configtypephysical mac_addressr2 ethernetsmatch macaddresszset-namename)LOGdebugrgetritems)r/ mac_to_nameccfgmaccur_name_macaddrs r$_ensure_netfailover_saferFGsY &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 DceZdZUdZdZej jej jej jej jfZ e ej dfe d<dZdZdZfdZd ed dffd Zd efd Zed efd ZdZd efdZdZd efdZd efdZedZddefdZ xZ!S)DataSourceOracleOracleN.network_config_sourcesTcZtt| |g|i|d|_t j t j |d|jgitg|_ t|_ gdd|_ |j}|j|_|j |_y)N datasourcer1r3r)superrH__init__ _vnics_datar mergemanydictget_cfg_by_pathdsnameBUILTIN_DS_CONFIGds_cfgr&_network_config_source_network_configget_url_paramsmax_wait_seconds url_max_waittimeout_seconds url_timeout)r,sys_cfgargskwargs url_params __class__s r$rQzDataSourceOracle.__init__s .wHHH(($$W|T[[.I2N!   'E&F#02q%A((* &77%55r#ci_pkl_versionr'ct||t|ds t|ddt|dst|dt t|ds gdd|_yy)NrRrXrYr1rO)rP _unpicklehasattrsetattrr&rY)r,rdrcs r$rfzDataSourceOracle._unpicklesd .)t]+ D- .t56 (.0  t./.0Q#?D 0r#cLt|jjdgS)Nr3)r)rYr=r+s r$_has_network_configz$DataSourceOracle._has_network_configs D((,,Xr:;;r#ctS)z@Check platform environment to report if this datasource may run.)_is_platform_viabler"r#r$ ds_detectzDataSourceOracle.ds_detects #$$r#ct|_tjddtddtjddit jddtddt jddif}|j r9tj}tj|j|dd|}ntj}|j }|jj!d t"d }|5t%|xs||j&|j(t tg }dddsy t+|j, |_|j0x}|_|j4|_|d |dd|d|dd|_d|vrQ|dj!d}|rt;j<||_|dj!d|j8d<y#1swYxYw)Nr2instancerpath)urlheadersrrr1T)distro interfaceipv6ipv4connectivity_urls_datarfetch_vnics_datamax_waittimeoutmetadata_patternsFrr ociAdNameidrhostname displayName)zavailability-zonez instance-idz launch-indexzlocal-hostnamer:metadata user_datassh_authorized_keys public_keys) _read_system_uuid system_uuidIPV4_METADATA_PATTERNformat V2_HEADERSIPV6_METADATA_PATTERNperform_dhcp_setupr find_fallback_nicrEphemeralIPNetworkrtr nullcontext_is_iscsi_rootrWr=rVread_opc_metadatar\r^ _get_versioned_metadata_base_urlrmetadata_addressr_crawled_metadatarrRrbase64 b64decode userdata_raw) r,rxnic_namenetwork_contextfetch_primary_nicfetch_secondary_nicsfetched_metadatadatars r$ _get_datazDataSourceOracle._get_datas6,.-33J4&  ,33J4  -33J4&  ,33J4 %" 2  " ",,.H'::{{"'= O#..0O $ 3 3 55#{{ & 8 9   0!2!J6J**(())#     !A ..! )9(F(FFt%+66"&k!2:":.'     Z(,,[9I$*$4$4Y$?!+/ +;+?+?%,DMM- (M  s 2G66G?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_uuidr)r,r_s r$check_instance_idz"DataSourceOracle.check_instance_id s 66t7G7GHHr#c^tj|jjdS)Nr)r normalize_pubkey_datarr=r+s r$get_public_ssh_keysz$DataSourceOracle.get_public_ssh_keyss",,T]]->->}-MNNr#c6|jjS)z)Return whether we are on a iscsi machine.)rXr-r+s r$rzDataSourceOracle._is_iscsi_roots**88::r#c6|jjSN)rX render_configr+s r$_get_iscsi_configz"DataSourceOracle._get_iscsi_configs**88::r#c|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!)rjrYrrr;warningrWr=rV!_add_network_config_from_opc_imds Exceptionr logexcrF)r, set_primary set_secondarys r$r/zDataSourceOracle.network_configs  # # %'' '    #'#9#9#;D '') KK( K  & 8 9  - 66{C !!5!56###  A sC#C+*C+rcb|jtjdy|s'd|jdvrtjdyt}|r |jn|jdd}t |D].\}}|xr|dk(}|dj }|j dd xr|j d d  }||vrtjd |e||} |rtj|d d} ntj|d } |jddk(r|r|rddig} nyddig} nsg} |j d r&| jd|d d| jd|j d r)| jd|d dd| jd| d|t| d} |jdj| a|jddk(sutd|id} | |jd| <|xr|| d<|xr| | d<|svg| d<|j d r&| dj|d d| j|j d r)| dj|d dd| j| |jd| <1y)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.r1macAddripv6SubnetCidrBlockF privateIpz)Interface with MAC %s not found; skipping ipv6AddressessubnetCidrBlockrr4dhcp6dhcpstatic/)r4addressr5)r:r4r6mtusubnetsr3r2r9)rr8r7dhcp4 addresses) rRr;rr enumeratelowerr= ipaddress ip_networkrYappend prefixlenMTU) r,rinterfaces_by_macrindex vnic_dict is_primaryr6 is_ipv6_onlyr:networkrinterface_configs r$rz2DataSourceOracle._add_network_config_from_opc_imdsHs:    # KK= >  d.>.>q.A A KK9  13)4T%%$:J:J12:N !** 5N K E9$3!J#I.446K$==%u8mmK77 "33 ?$[1D#..o.q1$..y9J/KL##I.!3#$*G#4"5$*F#3"4 G }}[1(0'0'=&>a'.'8'8&9%;!}}_5(0'0'A!'D&EQ'.'8'8&9%;!&#.& $ $$X.556FG%%i0A5*K8$ ;K$$[1$7,6,G< ),6,K|;K )!46$[1 }}[1(5<<(56a8I8I7JK!}}_5(5<<(9!<=Q&0013;K$$[1$7]N Kr#)F)"rrrrUrr NetworkConfigSourceCMD_LINE SYSTEM_CFGDS INITRAMFSrJrr rr\r^rQrrfr)rj staticmethodrmrrrrdictrpropertyr/r __classcell__)rcs@r$rHrH{s FK##,,##..##&&##-- GE'"="=s"BCLK6" @ @ @tjd}|tk(S)Nzchassis-asset-tag)r rCHASSIS_ASSET_TAG) asset_tags r$rlrls!!"56I ) ))r#rrcd|vrdSdS)Nz/opc/v2/r2r1r"r~s r$ _url_versionrsc!1(q(r#c.t|dk(rtSdS)Nr2)rrr~s r$ _headers_cbrs%c*a/:9T9r#c|s|Sd|vr|jdddzSd|vr|jdddzStd|z)zQ Remove everything following the version number in the metadata address. v2rzv2/v1zv1/zInvalid metadata address: )r ValueErrorr~s r$rrs[   s{yyq!E)) yyq!E))5;<?!1J!>?""& % ! > N$9$9'$BCJ IIF  KKE F "  k s!E>c6tj|tSr)r list_from_depends datasources)dependss r$get_datasource_listrGs  $ $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.)r})rrl)Ar.rrrloggingrtypingrrrrrr cloudinitr r r r r cloudinit.distros.networkingr cloudinit.netrrrrcloudinit.url_helperr getLoggerrr;rVrrIPV6_METADATA_ROOTrrrrrKlibcNetworkConfigSourcer&rF DataSourcerHrr!rrr)rlrrrrr\r^rDEP_FILESYSTEM DEP_NETWORKrr descriptionprint json_dumpsr"r#r$rs4   ??<<6 .g!&=B*Y6*Y6 /  j !W%E%E !18]18t18h~Kw))~KB *KCK :8C=: *T* )c)c):S:Xd38n5: =# =# = #  * *  ( ($9#: PP Cy P %& Pj..01  " "      ; z K     %6.0EF& (;'<    r#