U
    Ad                  	   @   s   U d 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
 ddlmZmZ ddlmZ d	Zd
ddeddgeedgdgdZeed< eeZ ddgZdgZdZdd ZedddfddZee
eeeddddZdS )z*Spacewalk: Install and configure spacewalk    )Logger)dedent)subp)Cloud)Config)
MetaSchemaget_meta_doc)PER_INSTANCEa  This module installs spacewalk and applies basic configuration. If the
``spacewalk`` config key is present spacewalk will be installed. The server to
connect to after installation must be provided in the ``server`` in spacewalk
configuration. A proxy to connect through and a activation key may optionally
be specified.

For more information about spacewalk see: https://fedorahosted.org/spacewalk/
Zcc_spacewalkZ	SpacewalkzInstall and configure spacewalkZrhelZfedoraz            spacewalk:
              server: <url>
              proxy: <proxy host>
              activation_key: <key>
            	spacewalk)idnametitleZdescriptiondistrosZ	frequencyZexamplesZactivate_by_schema_keysmetaZredhatz	rhn-setupz'/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERTc               
   C   sT   d} zt j ddgdd d} W n0 t jk
rN } z|jdkr> W 5 d }~X Y nX | S )NFzrhn-profile-syncz	--verboseZcaptureT   )r   ZProcessExecutionErrorZ	exit_code)Zalready_registerede r   ?/usr/lib/python3/dist-packages/cloudinit/config/cc_spacewalk.pyis_registered3   s    
r   Nc                 C   s   |d k	r| d||  dg}|dd|  g |dt|g |rV|dt|g |rl|dt|g |r|dt|g tj|d	d
 d S )Nz;Registering using `rhnreg_ks` profile '%s' into server '%s'Z	rhnreg_ksz--serverUrlzhttps://%s/XMLRPCz--profilenamez--proxyz--sslCACertz--activationkeyFr   )infoextendstrr   )serverZprofile_nameZca_cert_pathproxylogactivation_keycmdr   r   r   do_registerA   s     r   )r   cfgcloudr   argsreturnc                 C   s|   d|kr| d|  d S |d }|d}|rl|jt t sxt||jjddj	|d||dd n| d	|  d S )
Nr
   z=Skipping module named %s, no 'spacewalk' key in configurationr   T)Zfqdnr   r   )r   r   r   zOSkipping module named %s, 'spacewalk/server' key was not found in configuration)
debuggetZdistroZinstall_packagesrequired_packagesr   r   Z
datasourceZget_hostnameZhostname)r   r   r    r   r!   Zspacewalk_serverr   r   r   handle[   s,    
r&   )__doc__Zloggingr   textwrapr   Z	cloudinitr   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr	   ZMODULE_DESCRIPTIONr   __annotations__r   r%   Zdef_ca_cert_pathr   r   r   listr&   r   r   r   r   <module>   sJ   

    