o
    w7e                  
   @   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dedede
deddf
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.
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titledescriptiondistros	frequencyexamples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_name
config_dirservice_name)r   
is_FreeBSDr   srv_nameconf_dir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|vrt d|  d S |d }t|d}|j|j t|j d }d|v r>t	j
|jd}|d}t|t| d|v rXt	j
|jd}t|d}	t||	 d|v rd|v rt	j
|jd	}
t	j
|
svt	j
|jd
}
|d|
}td+ t| t	j
|d}t	j
|d}t||d  t||d  W d    n1 sw   Y  t|o|ddk }|j|rdnd|j |j|rdnd|j |stjg ddd d S d S )Nr   z?Skipping module named %s, no 'salt_minion' key in configuration)r    confminiongrains
public_keyprivate_keyz
pki/minionpkipki_dir?   z
minion.pubz
minion.pemfile_clientlocalenabledisablerestartstop)z	salt-callz--localzstate.applyF)capture)LOGdebugr   distroinstall_packagesr   r   
ensure_dirr   ospathjoinget
write_filer   dumpsisdirumaskboolmanage_servicer   r   )r   r    r(   r)   s_cfgconstminion_dataminion_configgrains_configgrains_datapki_dir_defaultr1   pub_namepem_nameminion_daemonr!   r!   r"   handlej   sV   


rS   )r'   loggingr?   textwrapr   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r	   cloudinit.distrosr
   cloudinit.settingsr   MODULE_DESCRIPTIONr   __annotations__	getLoggerr$   r:   r   strlistrS   r!   r!   r!   r"   <module>   s6   '
"