3 \�me� � @ s� U d Z ddlZddlmZ ddlmZmZmZ ddlm Z ddl mZ ddlm Z mZ ddlmZ dd lmZ eZd ddd dddgZdZdddeegeed�ed�gdgd�Ze ee�Z eje�Zeee edd�dd�ZdS )zPhone Home: Post data to url� N)�dedent)� templater� url_helper�util)�Cloud)�Config)� MetaSchema�get_meta_doc)�ALL_DISTROS)�PER_INSTANCE�pub_key_dsa�pub_key_rsa� pub_key_ecdsa�pub_key_ed25519�instance_id�hostname�fqdnaj This module can be used to post data to a remote host after boot is complete. If the post url contains the string ``$INSTANCE_ID`` it will be replaced with the id of the current instance. Either all data can be posted or a list of keys to post. Available keys are: - ``pub_key_dsa`` - ``pub_key_rsa`` - ``pub_key_ecdsa`` - ``pub_key_ed25519`` - ``instance_id`` - ``hostname`` - ``fdqn`` Data is sent as ``x-www-form-urlencoded`` arguments. **Example HTTP POST**: .. code-block:: http POST / HTTP/1.1 Content-Length: 1337 User-Agent: Cloud-Init/21.4 Accept-Encoding: gzip, deflate Accept: */* Content-Type: application/x-www-form-urlencoded pub_key_dsa=dsa_contents&pub_key_rsa=rsa_contents&pub_key_ecdsa=ecdsa_contents&pub_key_ed25519=ed25519_contents&instance_id=i-87018aed&hostname=myhost&fqdn=myhost.internal Z cc_phone_homez Phone HomezPost data to urlzt phone_home: url: http://example.com/$INSTANCE_ID/ post: all as phone_home: url: http://example.com/$INSTANCE_ID/ post: - pub_key_dsa - pub_key_rsa - pub_key_ecdsa - pub_key_ed25519 - instance_id - hostname - fqdn tries: 5 � phone_home)�id�name�title�descriptionZdistros� frequencyZexamplesZactivate_by_schema_keys)r �cfg�cloud�args�returnc C s t |�dkrtj|d �}n d|kr4tjd| � d S |d }d|krTtjd| � d S |d }|jdd�}|jd�}yt|�}W n* tt fk r� d }tj td |� Y nX |dkr�t}|j� |j � j|j dd�jd �}ddddd�} xL| j� D ]@\} }ytj|�|| <