U
    Adp                  	   @   s  U d Z ddlZddlmZ ddlm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 dZdZddddddiZdZdgZdddeeededgedgdZeed< eeZ eeeeedddd Z d!d" Z!dS )#z&install and configure landscape client    N)BytesIO)Logger)dedent)	ConfigObj)subp
type_utilsutil)Cloud)Config)
MetaSchemaget_meta_doc)PER_INSTANCEz/etc/landscape/client.confz/etc/default/landscape-clientZclientinfoz.https://landscape.canonical.com/message-systemz#http://landscape.canonical.com/pingz/var/lib/landscape/client)Z	log_levelZurlZping_urlZ	data_patha  This module installs and configures ``landscape-client``. The landscape client
will only be installed if the key ``landscape`` is present in config. Landscape
client configuration is given under the ``client`` key under the main
``landscape`` config key. The config parameters are not interpreted by
cloud-init, but rather are converted into a ConfigObj formatted file and
written out to the `[client]` section in ``/etc/landscape/client.conf``.

The following default client config is provided, but can be overridden::

    landscape:
        client:
            log_level: "info"
            url: "https://landscape.canonical.com/message-system"
            ping_url: "http://landscape.canoncial.com/ping"
            data_path: "/var/lib/landscape/client"

.. note::
    see landscape documentation for client config keys

.. note::
    if ``tags`` is defined, its contents should be a string delimited with
    ``,`` rather than a list
ZubuntuZcc_landscapeZ	Landscapez&Install and configure landscape clienta              # To discover additional supported client keys, run
            # man landscape-config.
            landscape:
                client:
                    url: "https://landscape.canonical.com/message-system"
                    ping_url: "http://landscape.canonical.com/ping"
                    data_path: "/var/lib/landscape/client"
                    http_proxy: "http://my.proxy.com/foobar"
                    https_proxy: "https://my.proxy.com/foobar"
                    tags: "server,cloud"
                    computer_title: "footitle"
                    registration_key: "fookey"
                    account_name: "fooaccount"
            z            # Any keys below `client` are optional and the default values will
            # be used.
            landscape:
                client: {}
            	landscape)idnametitleZdescriptiondistrosZexamplesZ	frequencyZactivate_by_schema_keysmeta)r   cfgcloudlogargsreturnc           	      C   s   | di }t|ts,tdjt|d|s4dS |jd t	t
|g}t|}t }|| ttjt
 tt
|  |dt
 ttd tdd	d
g dS )z
    Basically turn a top level 'landscape' entry with a 'client' dict
    and render it to ConfigObj format under '[client]' section in
    /etc/landscape/client.conf
    r   zR'landscape' key existed in config, but not a dictionary type, is a {_type} instead)Z_typeN)landscape-clientz!Wrote landscape config file to %szRUN=1
servicer   Zrestart)get
isinstancedictRuntimeErrorformatr   Zobj_nameZdistroZinstall_packagesLSC_BUILTIN_CFGLSC_CLIENT_CFG_FILEmerge_togetherr   writer   Z
ensure_dirospathdirnameZ
write_filegetvaluedebugLS_DEFAULT_FILEr   )	r   r   r   r   r   Zls_cloudcfgZ
merge_dataZmergedcontents r,   ?/usr/lib/python3/dist-packages/cloudinit/config/cc_landscape.pyhandleg   s,    	

r.   c                 C   s@   t i }| D ].}|sqt|t r,|| q|t | q|S )zu
    merge together ConfigObj objects or things that ConfigObj() will take in
    later entries override earlier
    )r   r   merge)Zobjsr   objr,   r,   r-   r#      s    
r#   )"__doc__r%   ior   Zloggingr   textwrapr   Z	configobjr   Z	cloudinitr   r   r   Zcloudinit.cloudr	   Zcloudinit.configr
   Zcloudinit.config.schemar   r   Zcloudinit.settingsr   r"   r*   r!   ZMODULE_DESCRIPTIONr   r   __annotations__strlistr.   r#   r,   r,   r,   r-   <module>	   sZ   	%    )