o
    f}                  
   @   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 dd	lmZ d
ZdZddddddiZddgedgdZeed< eeZdededededdf
ddZdd ZdS ) z&install and configure landscape client    N)chain)	ConfigObj)subp
type_utilsutil)Cloud)Config)
MetaSchema)PER_INSTANCEz/etc/landscape/client.confz/etc/default/landscape-clientclientinfoz.https://landscape.canonical.com/message-systemz#http://landscape.canonical.com/pingz/var/lib/landscape/client)	log_levelurlping_url	data_pathcc_landscapeubuntu	landscape)iddistros	frequencyactivate_by_schema_keysmetanamecfgcloudargsreturnc           	   
   C   s   | di }t|tstdjt|d|sdS |jdg t	t
|g}ttdd tt|d  D  }ztjg d	d
gd tddg|  W dS  tjy~ } z"|jdkrctd nd| }tt| t||W Y d}~dS d}~ww )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)_typeNzlandscape-clientc                 S   s&   g | ]\}}d | dd |gqS )z--_-)replace).0kv r%   ?/usr/lib/python3/dist-packages/cloudinit/config/cc_landscape.py
<listcomp>J   s    zhandle.<locals>.<listcomp>r   )landscape-config--silentz--is-registered   )rcsr(   r)   r   z&Client already registered to LandscapezFailure registering client:
)get
isinstancedictRuntimeErrorformatr   obj_namedistroinstall_packagesLSC_BUILTIN_CFGLSC_CLIENT_CFG_FILElistr   sortedmerge_togetheritemsr   ProcessExecutionError	exit_codeLOGwarningr   logexc)	r   r   r   r   ls_cloudcfg
merge_data
cmd_paramsemsgr%   r%   r&   handle-   sH   




rD   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)objsr   objr%   r%   r&   r8   ^   s   
r8   )__doc__logging	itertoolsr   	configobjr   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar	   cloudinit.settingsr
   r5   LS_DEFAULT_FILEr4   r   __annotations__	getLogger__name__r<   strr6   rD   r8   r%   r%   r%   r&   <module>   s4   

1