a '¡DgÉã@s°ddlZddlmZddlmZmZddlmZddlm Z ddl m Z e  e¡ZddiZd Zd Zd ZGd d „d ejƒZGd d„deƒZeejffeejejffgZdd„ZdS)éN)Únet)ÚsourcesÚutil)ÚNoDHCPLeaseError)ÚEphemeralDHCPv4)ÚupcloudÚ metadata_urlz'http://169.254.169.254/metadata/v1.jsonééc@sHeZdZdZdZdd„Zdd„Zdd„Zd d „Zd d „Z e d d„ƒZ dS)ÚDataSourceUpCloudÚUpCloudFcCsŠtj ||||¡||_tƒ|_t t |ddgi¡t g¡|_ |j d|_ |j   dt ¡|_|j   dt¡|_|j   dt¡|_d|_d|_dS)NZ datasourcer rÚretriesÚtimeoutÚ wait_retry)rÚ DataSourceÚ__init__ÚdistroÚdictÚmetadatarZ mergemanydictZget_cfg_by_pathÚBUILTIN_DS_CONFIGZds_cfgÚmetadata_addressÚgetÚ MD_RETRIESr Ú MD_TIMEOUTrÚ MD_WAIT_RETRYrÚ_network_configÚ metadata_full)ÚselfÚsys_cfgrÚpaths©r úG/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceUpCloud.pyr"sþÿ zDataSourceUpCloud.__init__cCst ¡S©N)Ú uc_helperZ read_sysinfo©rr r r!Ú _get_sysinfo3szDataSourceUpCloud._get_sysinfocCstj|j|j|j|jdS)N)rZ sec_betweenr )r#Z read_metadatarrrr r$r r r!Ú_read_metadata6s üz DataSourceUpCloud._read_metadatac Cs”| ¡\}}|sdSt d|¡|jr¼zVt d¡t ¡}t d|¡t|j|ƒ|  ¡}Wdƒn1sp0YWn<t t j fy¸}zt  tt|ƒ¡WYd}~dSd}~00n^zt d¡|  ¡}WnFt j y}z*t  tt|ƒ¡t d|¡WYd}~dSd}~00||_| 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 %sZ instance_idz instance-idÚhostnamezlocal-hostnameÚnetworkZ public_keysz public-keysZregionÚdefaultZavailability_zoneZ vendor_dataZ user_dataT)r%ÚLOGÚinfoÚperform_dhcp_setupÚdebugÚcloudnetZfind_fallback_nicrrr&rrZInvalidMetaDataExceptionrZlogexcÚstrrrrZvendordata_rawZ userdata_raw)rZ is_upcloudZ server_uuidZnicZmdÚer r r!Ú _get_data>sF    *ÿ ýzDataSourceUpCloud._get_datacCst | ¡¡Sr")rZinstance_id_matches_system_uuidZget_instance_id)rrr r r!Úcheck_instance_idksz#DataSourceUpCloud.check_instance_idcCs6|jr |jS|j d¡}|s$tdƒ‚t |¡|_|jS)z® Configure the networking. This needs to be done each boot, since the IP and interface information might have changed due to reconfiguration. r(z/Unable to get network meta-data from server....)rrrÚ RuntimeErrorr#Zconvert_network_config)rZraw_network_configr r r!Únetwork_configns ÿÿz DataSourceUpCloud.network_configN) Ú__name__Ú __module__Ú __qualname__Zdsnamer,rr%r&r1r2Úpropertyr4r 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)r5r6r7Ú__doc__r,r r r r!r9†s r9cCs t |t¡Sr")rZlist_from_dependsÚ datasources)Zdependsr r r!Úget_datasource_list›sr<)ZloggingZ cloudinitrr.rrZcloudinit.net.dhcprZcloudinit.net.ephemeralrZcloudinit.sources.helpersrr#Z getLoggerr5r*rrrrrr r9ZDEP_FILESYSTEMZ DEP_NETWORKr;r<r r r r!Ús      k þ