3 \�me� � @ s� U d Z ddlZddlmZ ddlmZ ddlmZ ddlm Z ddl mZmZ ddl mZ d Zd dded ddgeed�gdgd�Zeee�Z eje�ZddgZdgZdZdd� Zeddfdd�Zee eedd�dd�ZdS )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/ Zcc_spacewalkZ SpacewalkzInstall and configure spacewalkZrhelZfedoraZ openeulerz� spacewalk: server: <url> proxy: <proxy host> activation_key: <key> � spacewalk)�id�name�title�description�distrosZ frequencyZexamplesZactivate_by_schema_keysZredhatz rhn-setupz'/usr/share/rhn/RHN-ORG-TRUSTED-SSL-CERTc C sT d} yt j ddgdd� d} W n0 t jk rN } z|jdkr>� W Y d d }~X nX | S )NFzrhn-profile-syncz --verbose)�captureT� )r ZProcessExecutionErrorZ exit_code)Zalready_registered�e� r �"/usr/lib/python3.6/cc_spacewalk.py� is_registered4 s r c C s� t jd|| � dg}|jdd| g� |jdt|�g� |rN|jdt|�g� |rd|jdt|�g� |rz|jdt|�g� tj|d d � d S )Nz;Registering using `rhnreg_ks` profile '%s' into server '%s'Z rhnreg_ksz--serverUrlzhttps://%s/XMLRPCz --profilenamez--proxyz--sslCACertz--activationkeyF)r )�LOG�info�extend�strr )�serverZprofile_nameZca_cert_path�proxy�activation_key�cmdr r r �do_registerB s r )r �cfg�cloud�args�returnc C sz d|krt jd| � d S |d }|jd�}|rj|jjt� t� svt||jj dd�j |jd�|jd�d� nt jd | � d S ) Nr z=Skipping module named %s, no 'spacewalk' key in configurationr T)Zfqdnr r )r r zOSkipping module named %s, 'spacewalk/server' key was not found in configuration)r �debug�getZdistroZinstall_packages�required_packagesr r Z datasourceZget_hostnameZhostname)r r r r Zspacewalk_serverr r r �handleZ s$ r% )�__doc__Zlogging�textwrapr Z cloudinitr Zcloudinit.cloudr Zcloudinit.configr Zcloudinit.config.schemar r Zcloudinit.settingsr ZMODULE_DESCRIPTION�metaZ getLogger�__name__r r r$ Zdef_ca_cert_pathr r r �listr% r r r r �<module> s6