3 \¼metã@s‚ddlZddlZddlmZddlmZmZddlmZddl m Z m Z ej 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|_tjj||||ƒdS)NÚ)rÚcepkoÚssh_public_keyrÚ DataSourceÚ__init__)ÚselfZsys_cfgZdistroÚpaths©rú*/usr/lib/python3.6/DataSourceCloudSigma.pyr szDataSourceCloudSigma.__init__cCs>tjdƒtjdƒ}|s&tjdƒdStjd|ƒd|jƒkS)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_detectc CsÄd}y|jjƒj}|d}Wntk r:tjdƒdSX|j|jdƒgƒ|_|t j kr^dS|jddƒj dƒ}|jd dƒ|_ d |kr’t |j ƒ|_ d |jd iƒkr°|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_subplatformFcCsDtjd|jdƒr&|jddd…}n|jdjdƒ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 )rrrrÚget_public_ssh_keysasz(DataSourceCloudSigma.get_public_ssh_keyscCs |jdS)Nr%)r )rrrrÚget_instance_iddsz$DataSourceCloudSigma.get_instance_idN)FFF) Ú__name__Ú __module__Ú __qualname__Ú__doc__Zdsnamer Ú staticmethodrr!r"r*r+r,rrrrrs " rcCs tj|tƒS)zK Return a list of data sources that match this set of dependencies )rZlist_from_dependsÚ datasources)ZdependsrrrÚget_datasource_listrsr3)Zloggingr'Úbase64rrrrZcloudinit.sourcesrZ$cloudinit.sources.helpers.cloudsigmarrZ getLoggerr-rr rZDataSourceCloudSigmaNetZDEP_FILESYSTEMr2r3rrrrÚs   W