a '¡Dgtã@s‚ddlZddlZddlmZddlmZmZddlmZddl m Z m Z e  e ¡ZGdd„dejƒZeZeejffgZdd „ZdS) éN)Ú b64decode)ÚdmiÚsources)ÚDataSourceHostname)Ú SERIAL_PORTÚCepkoc@sReZdZdZdZdd„Zedd„ƒZdd„Zd d „Z dd d „Z dd„Z dd„Z dS)ÚDataSourceCloudSigmazÍ Uses cepko in order to gather the server context from the VM. For more information about CloudSigma's Server Context: http://cloudsigma-docs.readthedocs.org/en/latest/server_context.html Z CloudSigmacCs$tƒ|_d|_tj ||||¡dS)NÚ)rÚcepkoÚssh_public_keyrÚ DataSourceÚ__init__)ÚselfZsys_cfgZdistroÚpaths©rúJ/usr/lib/python3.9/site-packages/cloudinit/sources/DataSourceCloudSigma.pyr szDataSourceCloudSigma.__init__cCs>t d¡t d¡}|s&t d¡dSt d|¡d| ¡vS)z Uses dmi data to detect if this instance of cloud-init is running in the CloudSigma's infrastructure. z0determining hypervisor product name via dmi datazsystem-product-namez-system-product-name not available in dmi dataFzdetected hypervisor as %sZ cloudsigma)ÚLOGÚdebugrZ read_dmi_dataÚlower)Zsys_product_namerrrÚ ds_detect!s    zDataSourceCloudSigma.ds_detectcCsÄd}z|j ¡j}|d}Wnty:t d¡YdS0| | d¡g¡|_|t j kr^dS| dd¡  d¡}| d d¡|_ d |vr’t |j ƒ|_ d | d i¡vr°|d d |_||_|d |_d S)zj Metadata is the whole server context and /meta/cloud-config is used as userdata. NÚmetaz+CloudSigma: Unable to read from serial portFzcloudinit-dsmodeÚ base64_fieldsr ú,zcloudinit-user-dataÚ cloudinitZ vendor_datar T)r ÚallÚresultÚ ExceptionrrZ_determine_dsmodeÚgetÚdsmoderZDSMODE_DISABLEDÚsplitZ userdata_rawrZvendordata_rawÚmetadatar )rrZserver_contextZ server_metarrrrÚ _get_data0s*     ÿ   zDataSourceCloudSigma._get_datacCsdtS)z/Return the subplatform metadata source details.z cepko (%s))r©rrrrÚ_get_subplatformRsz%DataSourceCloudSigma._get_subplatformFcCsDt d|jd¡r&|jddd…}n|jd d¡d}t|dƒS) z† Cleans up and uses the server's name if the latter is set. Otherwise the first part from uuid is being used. z^[A-Za-z0-9 -_\.]+$ÚnameNé=Úuuidú-rF)ÚreÚmatchr rr)rZfqdnZ resolve_ipZ metadata_onlyÚretrrrÚ get_hostnameVsz!DataSourceCloudSigma.get_hostnamecCs|jgS)N)r r"rrrÚget_public_ssh_keysasz(DataSourceCloudSigma.get_public_ssh_keyscCs |jdS)Nr&)r r"rrrÚget_instance_iddsz$DataSourceCloudSigma.get_instance_idN)FFF) Ú__name__Ú __module__Ú __qualname__Ú__doc__Zdsnamer Ú staticmethodrr!r#r+r,r-rrrrrs " rcCs t |t¡S)zK Return a list of data sources that match this set of dependencies )rZlist_from_dependsÚ datasources)ZdependsrrrÚget_datasource_listrsr4)Zloggingr(Úbase64rrrrZcloudinit.sourcesrZ$cloudinit.sources.helpers.cloudsigmarrZ getLoggerr.rr rZDataSourceCloudSigmaNetZDEP_FILESYSTEMr3r4rrrrÚs   W ÿ