
    }ft                         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ej                        ZeZeej$                  ffgZd Zy)	    N)	b64decode)dmisources)DataSourceHostname)SERIAL_PORTCepkoc                   J    e Zd ZdZdZd Zed        Zd Zd Z	ddZ
d Zd	 Zy
)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
    
CloudSigmac                 t    t               | _        d| _        t        j                  j                  | |||       y )N )r   cepkossh_public_keyr   
DataSource__init__)selfsys_cfgdistropathss       H/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceCloudSigma.pyr   zDataSourceCloudSigma.__init__   s-    W
 ##D'65A    c                      t         j                  d       t        j                  d      } | st         j                  d       yt         j                  d|        d| j	                         v 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 %s
cloudsigma)LOGdebugr   read_dmi_datalower)sys_product_names    r   	ds_detectzDataSourceCloudSigma.ds_detect!   s[     			DE,,-BCIIEF		-/?@/55777r   c                 (   d}	 | j                   j                         j                  }|d   }| j                  |j                  d      g      | _        |t        j                  k(  ry|j                  dd      j                  d      }|j                  d	d      | _        d	|v rt        | j                        | _        d
|j                  di       v r|d   d
   | _        || _        |d   | _        y# t        $ r t        j                  d       Y yw xY w)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	cloudinitvendor_datar   T)r   allresult	Exceptionr   r   _determine_dsmodegetdsmoder   DSMODE_DISABLEDsplituserdata_rawr   vendordata_rawmetadatar   )r   r+   server_contextserver_metar"   s        r   	_get_datazDataSourceCloudSigma._get_data0   s   
 	!ZZ^^-44N(0K ,,__/01
 W,,,#<BB3G'OO,A2F M1 )$*;*; <D.,,]B??"0"?"LD&)*:;-  	 IICD		s   )C0 0DDc                     dt         z  S )z/Return the subplatform metadata source details.z
cepko (%s))r   r   s    r   _get_subplatformz%DataSourceCloudSigma._get_subplatformR   s    k))r   c                     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matchr0   r-   r   )r   fqdn
resolve_ipmetadata_onlyrets        r   get_hostnamez!DataSourceCloudSigma.get_hostnameV   s\    
 88*DMM&,AB--',C--'--c215C!#u--r   c                     | j                   gS )N)r   r5   s    r   get_public_ssh_keysz(DataSourceCloudSigma.get_public_ssh_keysa   s    ##$$r   c                      | j                   d   S )Nr:   )r0   r5   s    r   get_instance_idz$DataSourceCloudSigma.get_instance_idd   s    }}V$$r   N)FFF)__name__
__module____qualname____doc__dsnamer   staticmethodr   r3   r6   rB   rD   rF    r   r   r
   r
      sB     FB
 8 8 D*	.%%r   r
   c                 6    t        j                  | t              S )zK
    Return a list of data sources that match this set of dependencies
    )r   list_from_dependsdatasources)dependss    r   get_datasource_listrR   r   s     $$Wk::r   )loggingr<   base64r   r$   r   r   cloudinit.sourcesr   $cloudinit.sources.helpers.cloudsigmar   r   	getLoggerrG   r   r   r
   DataSourceCloudSigmaNetDEP_FILESYSTEMrP   rR   rM   r   r   <module>rZ      sg     	  " 0 Cg!S%7-- S%n / 
 G2245
;r   