U
    ¯Ad$  ã                	   @   sÜ   U d Z ddlZddlmZ ddlmZ ddlmZmZm	Z	 ddl
mZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZ dZdddeegeedƒgdgdœZeed< eeƒZ G dd„ dƒZeeeeeddœdd„ZdS )z&Salt Minion: Setup and run salt minioné    N)ÚLogger)Údedent)ÚsafeyamlÚsubpÚutil)ÚCloud)ÚConfig)Ú
MetaSchemaÚget_meta_doc)ÚALL_DISTROSÚ	bsd_utils)ÚPER_INSTANCEa.  This module installs, configures and starts salt minion. If the ``salt_minion``
key is present in the config parts, then salt minion will be installed and
started. Configuration for salt minion can be specified in the ``conf`` key
under ``salt_minion``. Any conf values present there will be assigned in
``/etc/salt/minion``. The public and private keys to use for salt minion can be
specified with ``public_key`` and ``private_key`` respectively. Optionally if
you have a custom package name, service name or config directory you can
specify them with ``pkg_name``, ``service_name`` and ``config_dir``.

Salt keys can be manually generated by: ``salt-key --gen-keys=GEN_KEYS``,
where ``GEN_KEYS`` is the name of the keypair, e.g. 'minion'.  The keypair
will be copied to ``/etc/salt/pki`` on the minion instance.
Zcc_salt_minionzSalt MinionzSetup and run salt minionaœ              salt_minion:
                pkg_name: salt-minion
                service_name: salt-minion
                config_dir: /etc/salt
                conf:
                    master: salt.example.com
                grains:
                    role:
                        - web
                public_key: |
                    ------BEGIN PUBLIC KEY-------
                    <key data>
                    ------END PUBLIC KEY-------
                private_key: |
                    ------BEGIN PRIVATE KEY------
                    <key data>
                    ------END PRIVATE KEY-------
                pki_dir: /etc/salt/pki/minion
            Úsalt_minion)ÚidÚnameÚtitleZdescriptionZdistrosZ	frequencyZexamplesZactivate_by_schema_keysÚmetac                   @   s   e Zd ZdZdd„ ZdS )ÚSaltConstantsz>
    defines default distribution specific salt variables
    c                 C   sh   t  ¡ rd| _d| _d| _nd| _d| _d| _t  |d| j¡| _t  |d| j¡| _t  |d| j¡| _d S )	Nzpy-saltr   z/usr/local/etc/saltzsalt-minionz	/etc/saltÚpkg_nameZ
config_dirZservice_name)r   Z
is_FreeBSDr   Úsrv_nameÚconf_dirZget_cfg_option_str)ÚselfÚcfg© r   úA/usr/lib/python3/dist-packages/cloudinit/config/cc_salt_minion.pyÚ__init__N   s$      ÿ  ÿzSaltConstants.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   I   s   r   )r   r   ÚcloudÚlogÚargsÚreturnc              	   C   sˆ  d|kr|  d| ¡ d S |d }t|d}|j |j¡ t |j¡ d|krxtj	 
|jd¡}t | d¡¡}t ||¡ d|kr¬tj	 
|jd¡}	t | d¡¡}
t |	|
¡ d|krTd|krTtj	 
|jd	¡}tj	 |¡sìtj	 
|jd
¡}| d|¡}t d¡L t |¡ tj	 
|d¡}tj	 
|d¡}t ||d ¡ t ||d ¡ W 5 Q R X |jjdkrnt dd¡ tjd|jdgdd d S )Nr   z?Skipping module named %s, no 'salt_minion' key in configuration)r   ÚconfZminionZgrainsZ
public_keyZprivate_keyz
pki/minionZpkiÚpki_diré?   z
minion.pubz
minion.pemZfreebsdZsalt_minion_enableZYESÚserviceZrestartF)Zcapture)Údebugr   ZdistroZinstall_packagesr   r   Z
ensure_dirr   ÚosÚpathÚjoinr   ÚdumpsÚgetZ
write_fileÚisdirÚumaskZosfamilyr   Zset_rc_config_valuer   r   )r   r   r    r!   r"   Zs_cfgZconstZminion_configZminion_dataZgrains_configZgrains_dataZpki_dir_defaultr%   Zpub_nameZpem_namer   r   r   Úhandlee   s@    þ

r0   )r   r)   Zloggingr   Útextwrapr   Z	cloudinitr   r   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar	   r
   Zcloudinit.distrosr   r   Zcloudinit.settingsr   ZMODULE_DESCRIPTIONr   Ú__annotations__r   ÚstrÚlistr0   r   r   r   r   Ú<module>   s>   ÿÿá"    þ