o
    w7e                  
   @   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g d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dede	dededdf
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/
cc_spacewalk	SpacewalkzInstall and configure spacewalk)rhelfedora	openeulerz            spacewalk:
              server: <url>
              proxy: <proxy host>
              activation_key: <key>
            	spacewalk)idnametitledescriptiondistros	frequencyexamplesactivate_by_schema_keysmetaredhatr   z	rhn-setupz'/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERTc               
   C   sV   d} zt j ddgdd d} W | S  t jy* } z|jdkr W Y d }~| S d }~ww )NFzrhn-profile-syncz	--verbosecaptureT   )r   ProcessExecutionError	exit_code)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 |r'|dt|g |r2|dt|g |r=|dt|g tj|d	d
 d S )Nz;Registering using `rhnreg_ks` profile '%s' into server '%s'	rhnreg_ksz--serverUrlzhttps://%s/XMLRPCz--profilenamez--proxyz--sslCACertz--activationkeyFr   )LOGinfoextendstrr   )serverprofile_nameca_cert_pathproxyactivation_keycmdr    r    r!   do_registerB   s   r.   r   cfgcloudargsreturnc                 C   s   d|vrt d|  d S |d }|d}|r8|jt t s6t||jj	ddj
|d|dd d S d S t d	|  d S )
Nr   z=Skipping module named %s, no 'spacewalk' key in configurationr(   T)fqdnr+   r,   )r+   r,   zOSkipping module named %s, 'spacewalk/server' key was not found in configuration)r$   debuggetdistroinstall_packagesrequired_packagesr"   r.   
datasourceget_hostnamehostname)r   r/   r0   r1   spacewalk_serverr    r    r!   handleZ   s,   

r=   )__doc__loggingtextwrapr   	cloudinitr   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   r   cloudinit.settingsr   MODULE_DESCRIPTIONr   __annotations__	getLogger__name__r$   r   r8   def_ca_cert_pathr"   r.   r'   listr=   r    r    r    r!   <module>   s@   


"