
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
\mek              	   @   s   U d Z ddlZddlZddl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dlmZmZ dd	lmZ d
ZdZdZdZdgZdddeeedgedgdZeeeZ ejeZeeefddZeeeeddddZ dS )z6 Mcollective: Install, configure and start mcollective    N)dedent)	ConfigObj)subputil)Cloud)Config)
MetaSchemaget_meta_doc)PER_INSTANCEz&/etc/mcollective/ssl/server-public.pemz'/etc/mcollective/ssl/server-private.pemz/etc/mcollective/server.cfga  This module installs, configures and starts mcollective. If the ``mcollective``
key is present in config, then mcollective will be installed and started.

Configuration for ``mcollective`` can be specified in the ``conf`` key under
``mcollective``. Each config value consists of a key value pair and will be
written to ``/etc/mcollective/server.cfg``. The ``public-cert`` and
``private-cert`` keys, if present in conf may be used to specify the public and
private certificates for mcollective. Their values will be written to
``/etc/mcollective/ssl/server-public.pem`` and
``/etc/mcollective/ssl/server-private.pem``.

.. note::
    The ec2 metadata service is readable by non-root users.
    If security is a concern, use include-once and ssl urls.
allZcc_mcollectiveZMcollectivez(Install, configure and start mcollectivea              # Provide server private and public key and provide the following
            # config settings in /etc/mcollective/server.cfg:
            # loglevel: debug
            # plugin.stomp.host: dbhost

            # WARNING WARNING WARNING
            # The ec2 metadata service is a network service, and thus is
            # readable by non-root users on the system
            # (ie: 'ec2metadata --user-data')
            # If you want security for this, please use include-once + SSL urls
            mcollective:
              conf:
                loglevel: debug
                plugin.stomp.host: dbhost
                public-cert: |
                    -------BEGIN CERTIFICATE--------
                    <cert data>
                    -------END CERTIFICATE--------
                private-cert: |
                    -------BEGIN CERTIFICATE--------
                    <cert data>
                    -------END CERTIFICATE--------
            mcollective)idnametitledescriptiondistrosZexamplesZ	frequencyZactivate_by_schema_keysc          !   C   s  y"t j|ddd}ttj|}W nD tk
rf } z(|jtjkrD ntj	d| t }W Y d d }~X nX x| j
 D ]\}}|dkrt j||dd ||d< d|d	< qr|d
krt j||dd ||d< d|d	< qrt|tr|||< qrt|tr(||jkri ||< x0|j
 D ]\}	}
|
|| |	< qW qrt|||< qrW yt j|d|  W n6 tk
r } z|jtjkrpn W Y d d }~X nX tj }|j| t j||j dd d S )NF)quietdecodez4Did not find file %s (starting with an empty config)zpublic-certi  )modezplugin.ssl_server_publicZsslZsecurityproviderzprivate-certi  zplugin.ssl_server_privatez%s.old)r   Z	load_filer   ioBytesIOIOErrorerrnoENOENTLOGdebugitemsZ
write_file
isinstancestrdictZsectionscopywritegetvalue)configZ
server_cfgZpubcert_fileZpricert_fileZold_contentsZmcollective_configeZcfg_namecfgovcontents r)   $/usr/lib/python3.6/cc_mcollective.py	configure\   sH    




r+   )r   r%   cloudargsreturnc             C   s\   d|krt jd|  d S |d }|jjdg d|krDt|d d tjdddgdd d S )	Nr   z?Skipping module named %s, no 'mcollective' key in configurationZconf)r#   ZserviceZrestartF)Zcapture)r   r   ZdistroZinstall_packagesr+   r   )r   r%   r,   r-   Zmcollective_cfgr)   r)   r*   handle   s    r/   )!__doc__r   r   Zloggingtextwrapr   Z	configobjr   Z	cloudinitr   r   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r	   Zcloudinit.settingsr
   ZPUBCERT_FILEZPRICERT_FILEZ
SERVER_CFGZMODULE_DESCRIPTIONr   metaZ	getLogger__name__r   r+   r   listr/   r)   r)   r)   r*   <module>
   s<   
9