o x[htã@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 Ú CloudSigmacCs$tƒ|_d|_tj ||||¡dS)NÚ)rÚcepkoÚssh_public_keyrÚ DataSourceÚ__init__)ÚselfÚsys_cfgÚdistroÚpaths©rúH/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudSigma.pyrszDataSourceCloudSigma.__init__cCs>t d¡t d¡}|st 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 %sÚ cloudsigma)ÚLOGÚdebugrÚ read_dmi_dataÚlower)Úsys_product_namerrrÚ ds_detect!s     zDataSourceCloudSigma.ds_detectcCsÄd}z |j ¡j}|d}Wntyt d¡YdSw| | d¡g¡|_|t j kr/dS| dd¡  d¡}| d d¡|_ d |vrIt |j ƒ|_ d | d i¡vrX|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Ú cloudinitÚ vendor_datar T)r ÚallÚresultÚ ExceptionrrÚ_determine_dsmodeÚgetÚdsmoderÚDSMODE_DISABLEDÚsplitÚ userdata_rawrÚvendordata_rawÚmetadatar )rr&Úserver_contextÚ 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+r(r)rÚfqdnÚ resolve_ipÚ metadata_onlyÚretrrrÚ get_hostnameVs z!DataSourceCloudSigma.get_hostnamecCs|jgS)N)r r/rrrÚget_public_ssh_keysasz(DataSourceCloudSigma.get_public_ssh_keyscCs |jdS)Nr3)r+r/rrrÚget_instance_idds z$DataSourceCloudSigma.get_instance_idN)FFF) Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚdsnamerÚ staticmethodrr.r0r;r<r=rrrrrs "  rcCs t |t¡S)zK Return a list of data sources that match this set of dependencies )rÚlist_from_dependsÚ datasources)ÚdependsrrrÚget_datasource_listrs rG)Úloggingr5Úbase64rrrrÚcloudinit.sourcesrÚ$cloudinit.sources.helpers.cloudsigmarrÚ getLoggerr>rr rÚDataSourceCloudSigmaNetÚDEP_FILESYSTEMrErGrrrrÚs   W ÿ