o x[h@sddlZddlmZddlmZmZddlmZddlm Z ddl m Z e eZddiZd Zd Zd ZGd d d ejZGd ddeZeejffeejejffgZddZdS)N)net)sourcesutil)NoDHCPLeaseError)EphemeralDHCPv4)upcloud metadata_urlz'http://169.254.169.254/metadata/v1.jsonc@sHeZdZdZdZddZddZddZd d Zd d Z e d dZ dS)DataSourceUpCloudUpCloudFcCstj||||||_t|_tt|ddgit g|_ |j d|_ |j dt |_|j dt|_|j dt|_d|_d|_dS)N datasourcer rretriestimeout wait_retry)r DataSource__init__distrodictmetadatar mergemanydictget_cfg_by_pathBUILTIN_DS_CONFIGds_cfgmetadata_addressget MD_RETRIESr MD_TIMEOUTr MD_WAIT_RETRYr_network_config metadata_full)selfsys_cfgrpathsr$E/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceUpCloud.pyr"s  zDataSourceUpCloud.__init__cCstSN) uc_helper read_sysinfor!r$r$r% _get_sysinfo3szDataSourceUpCloud._get_sysinfocCstj|j|j|j|jdS)N)r sec_betweenr)r' read_metadatarrrrr)r$r$r%_read_metadata6s z DataSourceUpCloud._read_metadatac Cs|\}}|s dStd||jr]z+tdt}td|t|j| | }Wdn1s8wYWnLt t j fy\}zt tt|WYd}~dSd}~wwz td| }Wn"t j y}zt tt|td|WYd}~dSd}~ww||_|d||jd<|d |jd <|d |jd <|d |jd <|dd|jd<|dd|_|dd|_dS)NFz"Running on UpCloud. server_uuid=%szFinding a fallback NICz*Discovering metadata via DHCP interface %sz7Discovering metadata without DHCP-configured networkingzENo DHCP-enabled interfaces available, unable to fetch metadata for %s instance_idz instance-idhostnamezlocal-hostnamenetwork public_keysz public-keysregiondefaultavailability_zone vendor_data user_dataT)r*LOGinfoperform_dhcp_setupdebugcloudnetfind_fallback_nicrrr-rrInvalidMetaDataExceptionrlogexcstrr rrvendordata_raw userdata_raw)r! is_upcloud server_uuidnicmder$r$r% _get_data>sR       zDataSourceUpCloud._get_datacCst|Sr&)rinstance_id_matches_system_uuidget_instance_id)r!r"r$r$r%check_instance_idksz#DataSourceUpCloud.check_instance_idcCs6|jr|jS|jd}|stdt||_|jS)z Configure the networking. This needs to be done each boot, since the IP and interface information might have changed due to reconfiguration. r0z/Unable to get network meta-data from server....)rrr RuntimeErrorr'convert_network_config)r!raw_network_configr$r$r%network_configns z DataSourceUpCloud.network_configN) __name__ __module__ __qualname__dsnamer9rr*r-rGrJpropertyrNr$r$r$r%r s-r c@seZdZdZdZdS)DataSourceUpCloudLocalaz Run in init-local using a DHCP discovery prior to metadata crawl. In init-local, no network is available. This subclass sets up minimal networking with dhclient on a viable nic so that it can talk to the metadata service. If the metadata service provides network configuration then render the network configuration for that instance based on metadata. TN)rOrPrQ__doc__r9r$r$r$r%rTs rTcCs t|tSr&)rlist_from_depends datasources)dependsr$r$r%get_datasource_lists rY)logging cloudinitrr;rrcloudinit.net.dhcprcloudinit.net.ephemeralrcloudinit.sources.helpersrr' getLoggerrOr7rrrrrr rTDEP_FILESYSTEM DEP_NETWORKrWrYr$r$r$r%s"     k