U
    Ld                  	   @   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 ddlmZ d	Zd
ddedddgeedgdgdZeed< eeZ eeZddgZdgZdZdd ZeddfddZee	eeddddZdS )z*Spacewalk: Install and configure spacewalk    N)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	openeulerz            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_registered4   s    
r   c                 C   s   t d||  dg}|dd|  g |dt|g |rN|dt|g |rd|dt|g |rz|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   )LOGinfoextendstrr   )serverZprofile_nameZca_cert_pathproxyactivation_keycmdr   r   r   do_registerB   s    r   )r   cfgcloudargsreturnc                 C   sz   d|krt d|  d S |d }|d}|rj|jt t svt||jj	ddj
|d|dd nt d	|  d S )
Nr	   z=Skipping module named %s, no 'spacewalk' key in configurationr   T)Zfqdnr   r   )r   r   zOSkipping module named %s, 'spacewalk/server' key was not found in configuration)r   debuggetZdistroZinstall_packagesrequired_packagesr   r   Z
datasourceZget_hostnameZhostname)r   r   r   r    Zspacewalk_serverr   r   r   handleZ   s*    
r%   )__doc__Zloggingtextwrapr   Z	cloudinitr   Zcloudinit.cloudr   Zcloudinit.configr   Zcloudinit.config.schemar   r   Zcloudinit.settingsr   ZMODULE_DESCRIPTIONr   __annotations__Z	getLogger__name__r   r   r$   Zdef_ca_cert_pathr   r   r   listr%   r   r   r   r   <module>   s>   


