
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\met                 @   s   d dl Z d dlZd dlmZ d dlmZmZ d dlmZ d dl	m
Z
mZ e jeZG dd dejZeZeejffgZdd	 ZdS )
    N)	b64decode)dmisources)DataSourceHostname)SERIAL_PORTCepkoc               @   sR   e Zd ZdZdZdd Zedd Zdd Zd	d
 Z	dddZ
dd Zdd ZdS )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
CloudSigmac             C   s$   t  | _d| _tjj| ||| d S )N )r   cepkossh_public_keyr   
DataSource__init__)selfZsys_cfgZdistropaths r   */usr/lib/python3.6/DataSourceCloudSigma.pyr      s    zDataSourceCloudSigma.__init__c              C   s>   t jd tjd} | s&t jd dS t jd|  d| j kS )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 datazsystem-product-namez-system-product-name not available in dmi dataFzdetected hypervisor as %sZ
cloudsigma)LOGdebugr   Zread_dmi_datalower)Zsys_product_namer   r   r   	ds_detect!   s    


zDataSourceCloudSigma.ds_detectc             C   s   d}y| j j j}|d }W n tk
r:   tjd dS X | j|jdg| _|t	j
kr^dS |jddjd}|jd	d| _d	|krt| j| _d
|jdi kr|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 portFzcloudinit-dsmodebase64_fieldsr	   ,zcloudinit-user-data	cloudinitZvendor_datar   T)r
   allresult	Exceptionr   r   Z_determine_dsmodegetdsmoder   ZDSMODE_DISABLEDsplitZuserdata_rawr   Zvendordata_rawmetadatar   )r   r   Zserver_contextZserver_metar   r   r   r   	_get_data0   s(    


zDataSourceCloudSigma._get_datac             C   s   dt  S )z/Return the subplatform metadata source details.z
cepko (%s))r   )r   r   r   r   _get_subplatformR   s    z%DataSourceCloudSigma._get_subplatformFc             C   sD   t jd| jd r&| jd dd }n| jd j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-r   F)rematchr    r   r   )r   ZfqdnZ
resolve_ipZmetadata_onlyretr   r   r   get_hostnameV   s    z!DataSourceCloudSigma.get_hostnamec             C   s   | j gS )N)r   )r   r   r   r   get_public_ssh_keysa   s    z(DataSourceCloudSigma.get_public_ssh_keysc             C   s
   | j d S )Nr%   )r    )r   r   r   r   get_instance_idd   s    z$DataSourceCloudSigma.get_instance_idN)FFF)__name__
__module____qualname____doc__Zdsnamer   staticmethodr   r!   r"   r*   r+   r,   r   r   r   r   r      s   "
r   c             C   s   t j| tS )zK
    Return a list of data sources that match this set of dependencies
    )r   Zlist_from_dependsdatasources)Zdependsr   r   r   get_datasource_listr   s    r3   )Zloggingr'   base64r   r   r   r   Zcloudinit.sourcesr   Z$cloudinit.sources.helpers.cloudsigmar   r   Z	getLoggerr-   r   r   r   ZDataSourceCloudSigmaNetZDEP_FILESYSTEMr2   r3   r   r   r   r   <module>   s   
W