U
    wÚ7e„  ã                	   @   sÜ   U d Z ddlZddl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 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 e e¡ZG dd„ dƒZeee
eddœdd„ZdS )z&Salt Minion: Setup and run salt minioné    N)Údedent)ÚsafeyamlÚsubpÚutil)ÚCloud)ÚConfig)Ú
MetaSchemaÚget_meta_doc)ÚALL_DISTROS)Ú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 minionai              salt_minion:
                pkg_name: salt-minion
                service_name: salt-minion
                config_dir: /etc/salt
                conf:
                    file_client: local
                    fileserver_backend:
                      - gitfs
                    gitfs_remotes:
                      - https://github.com/_user_/_repo_.git
                    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__T   s$      ÿ  ÿzSaltConstants.__init__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   O   s   r   )r   r   ÚcloudÚargsÚreturnc              	   C   sÄ  d|krt  d| ¡ d S |d }t|d}|j |j¡ t |j¡ d }d|kr|t	j
 |jd¡}| d¡}t |t |¡¡ d|kr°t	j
 |jd¡}t | d¡¡}	t ||	¡ d|krXd|krXt	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 t|ol| d¡dkƒ }|j |r‚dnd|j¡ |j |rœdnd|j¡ |sÀtjdd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file_clientZlocalÚenableÚdisableZrestartÚstopz	salt-callz--localzstate.applyF)Zcapture)ÚLOGÚdebugr   ZdistroZinstall_packagesr   r   Z
ensure_dirr   ÚosÚpathÚjoinÚgetZ
write_filer   ÚdumpsÚisdirÚumaskÚboolZmanage_servicer   r   )r   r   r   r   Zs_cfgZconstZminion_dataZminion_configZgrains_configZgrains_dataZpki_dir_defaultr"   Zpub_nameZpem_nameZminion_daemonr   r   r   Úhandlej   sV    þ


ÿ ÿ ÿr1   )r   Zloggingr)   Útextwrapr   Z	cloudinitr   r   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r	   Zcloudinit.distrosr
   Zcloudinit.settingsr   ZMODULE_DESCRIPTIONr   Ú__annotations__Z	getLoggerr   r'   r   ÚstrÚlistr1   r   r   r   r   Ú<module>   s4   ÿÿÜ'
