HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_rh_subscription.cpython-38.pyc
U

Ӈg�<�@s�UdZddlZddlmZmZddlmZddlmZddl	m
Z
ddlmZe�
e�Zdd	d
dgedgd
�Ze
ed<eeeedd�dd�ZGdd�de�ZGdd�d�Zddd�ZdS)zDRed Hat Subscription: Register Red Hat Enterprise Linux based system�N)�subp�util)�Cloud)�Config)�
MetaSchema)�PER_INSTANCEZcc_rh_subscriptionZfedoraZrhelZ	openeuler�rh_subscription)�idZdistrosZ	frequencyZactivate_by_schema_keys�meta)�name�cfg�cloud�args�returnc
Csft|td�}|��s$t�d|�dS|���sXz�|��\}}|dk	rLt|��|��}|s`td��|jr�|j	dk	r�|�
�s�td��q�|j�d�n$|jr�|��s�td��n|j�d�|j
dk	r�t|j
t�s�d	}t|��|�|j
�}	|	s�td
�|j
���|��}	|	�std��|�d�Wn<tk
�rT}
z|�t|
��|�d
�W5d}
~
XYnXn
|�d�dS)N)�logz%s: module not configured.Tz-Registration failed or did not run completelyzSetting of service-level failedz(Completed auto-attach with service levelzSetting auto-attach failedzCompleted auto-attachz"Pools must in the format of a listzUnable to attach pools {0}zUnable to add or remove reposz-rh_subscription plugin completed successfullyz4rh_subscription plugin did not complete successfullyzSystem is already registered)�SubscriptionManager�LOG�
is_configured�debug�
is_registered�_verify_keys�SubscriptionError�rhn_register�auto_attach�servicelevel�_set_service_levelr�_set_auto_attach�pools�
isinstance�list�addPool�format�update_repos�log_success�log_warn�str)rrr
rZsmZverifyZ
verify_msgZcontZ	pool_failZreturn_stat�e�r'�E/usr/lib/python3/dist-packages/cloudinit/config/cc_rh_subscription.py�handlesN
�	



�r)c@seZdZdS)rN)�__name__�
__module__�__qualname__r'r'r'r(rPsrc@s�eZdZddddddddd	d
dgZd'd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd �Z
d!d"�Zd#d$�Zd%d&�ZdS)(r�org�activation-key�username�password�disable-repo�enable-repo�add-pool�rhsm-baseurl�server-hostname�auto-attach�
service-levelNcCs�|dkrt}||_||_|j�di�|_|j�d�|_|j�d�|_|j�d�|_|j�d�|_|j�d�|_	|j�d�|_
|j�d�|_|j�d	�|_|j�d
�|_
|j�d�|_|j�d�|_dS)
Nrr4r5r3r.r-r/r0r6r2r1r7)rrr�get�rhel_cfg�rhsm_baseurl�server_hostnamer�activation_keyr-�useridr0r�enable_repo�disable_repor)�selfrrr'r'r(�__init__cs zSubscriptionManager.__init__cCs|j�|�dS)z>Simple wrapper for logging info messages. Useful for unittestsN)r�info�r@�msgr'r'r(r#uszSubscriptionManager.log_successcCs|j�|�dS)zASimple wrapper for logging warning messages. Useful for unittestsN)rZwarningrCr'r'r(r$yszSubscriptionManager.log_warncCs�|jD].}||jkrd�|d�|j��}d|fSq|jdk	rdt�|j�sdt�|j�sdd}d|fS|jdk	r�|jr�t�t	|j��r�d}d|fSdS)zq
        Checks that the keys in the rh_subscription dict from the user-data
        are what we expect.
        z?{0} is not a valid key for rh_subscription. Valid keys are: {1}�, FNz8The key auto-attach must be a boolean value (True/False zqThe service-level key must be used in conjunction with the auto-attach key.  Please re-run with auto-attach: True)TN)
r9�
valid_rh_keysr!�joinrrZis_trueZis_falserr%)r@�kZbad_keyZnot_boolZno_autor'r'r(r}s2


��

�
��
���z SubscriptionManager._verify_keyscCs0dg}zt|�Wntjk
r*YdSXdS)zg
        Checks if the system is already registered and returns
        True if so, else False
        ZidentityFT)�_sub_man_clir�ProcessExecutionError)r@�cmdr'r'r(r�sz!SubscriptionManager.is_registeredc
Cs�|jdk	r�|jdk	r�dd�|j�d�|j�g}|jdk	rJ|�d�|j��|jdk	rf|�d�|j��zt|dd�d	}WnFtjk
r�}z&|j	d
kr�|�
d�|j��WY�dSd}~XYnXn�|jdk	�r�|j
dk	�r�dd
�|j�d�|j
�g}|jdk	�r|�d�|j��|jdk	�r2|�d�|j��zt|dd�d	}WnJtjk
�r�}z(|j	d
k�rz|�
d�|j��WY�dSd}~XYnXn|�
d�|�
d�dS|�d�d��}|j�d|�dS)z�
        Registers the system by userid and password or activation key
        and org.  Returns True when successful False when not.
        N�registerz--activationkey={0}z	--org={0}z
--baseurl={0}z--serverurl={0}T)�
logstring_valr�zRegistration failed due to: {0}Fz--username={0}z--password={0}z8Unable to register system due to incomplete information.z9Use either activationkey and org *or* userid and passwordzID: �z"Registered successfully with ID %s)r<r-r!r:�appendr;rIrrJ�stdoutr$�stderrr=r0�split�rstriprr)r@rK�
return_outr&Zreg_idr'r'r(r�sX

�	



�

�	
���z SubscriptionManager.rhn_registerc
Cs�ddd�|j�g}zt|�d}Wnttjk
r�}zT|j��dkrj|j�d�D]}|dkrP|�|�qPn|�d�|j	�
���WY�dSd}~XYnX|�d�D]}|dkr�|j�|�q�d	S)
N�attach�--autoz--servicelevel={0}rrN�
z*Setting the service level failed with: {0}FT)
r!rrIrrJrQrTrSr$rR�striprr�r@rKrUr&�liner'r'r(r�s*
���z&SubscriptionManager._set_service_levelc
Cs|ddg}zt|�d}Wn:tjk
rR}z|�d�|��WY�dSd}~XYnX|�d�D]}|dkr^|j�|�q^dS)	NrVrWrzAuto-attach failed with: {0}FrXrNT)rIrrJr$r!rSrrrZr'r'r(rsz$SubscriptionManager._set_auto_attachcCsXg}g}dddg}t|�d}|���d�}dddg}t|�d}|���d�}||fS)zh
        Gets the list pools for the active subscription and returns them
        in list form.
        rz--availablez--pool-onlyrrXz
--consumed)rIrTrS)r@Z	available�consumedrKZresultsr'r'r(�	_getPoolss

zSubscriptionManager._getPoolscCs�ddg}t|�d}g}|�d�D]$}d|kr"|�|�d�d���q"ddg}t|�d}g}|�d�D]$}d|krj|�|�d�d���qj||fS)	zl
        Obtains the current list of active yum repositories and returns
        them in list form.
        �reposz--list-enabledrrXzRepo ID:�:rOz--list-disabled)rIrSrPrY)r@rKrU�active_reposZrepo�inactive_reposr'r'r(�	_getRepos0szSubscriptionManager._getReposc
Cs�t|�dkr|j�d�dS|��\}}g}dg}|D]6}||kr\||kr\|�d�|��q6|�d�|��q6t|�dkr�|�|�z*t|�|j�dd�	|��
d	d
��WdStjk
r�}z|�d�||��WY�dSd
}~XYnXd
S)zl
        Takes a list of subscription pools and "attaches" them to the
        current subscription
        rzNo pools to attachTrVz
--pool={0}zPool {0} is not availablez/Attached the following pools to your system: %srEz--pool=rNz$Unable to attach pool {0} due to {1}FN)
�lenrrr]rPr!r$�extendrIrG�replacerrJ)r@rZpool_availableZ
pool_consumedZ	pool_listrKZpoolr&r'r'r(r Fs0
�
�zSubscriptionManager.addPoolc

Cs8|j}|j}|dkrg}|dkr$g}t|t�s<|�d�dSt|t�sT|�d�dSt|�dkr|t|�dkr||j�d�dS|��\}}g}g}|D](}||kr�|�	d�
|��q�|�	|�q�g}g}	|D](}||kr�|�	d�
|��q�|	�	|�q�t|�dk�r8|D]0}
|
|k�r$|j�d	|
�n|�d
�
|
���qt|	�dk�r`|	D]}
|j�d|
��qJdg}t|�dk�r~|�|�t|�dk�r�|�|�zt|�Wn<t
jk
�r�}z|�d
�
|��WY�dSd}~XYnXt|�dk�r
|j�dd�|��dd��t|�dk�r4|j�dd�|��dd��dS)z�
        Takes a list of yum repo ids that need to be disabled or enabled; then
        it verifies if they are already enabled or disabled and finally
        executes the action to disable or enable
        Nz&Repo IDs must in the format of a list.Frz No repo IDs to enable or disableTz--enable={0}z
--disable={0}zRepo %s is already enabledz!Repo {0} does not appear to existz.Repo %s not disabled because it is not enabledr^z Unable to alter repos due to {0}zEnabled the following repos: %srEz	--enable=rNz Disabled the following repos: %sz
--disable=)r>r?rrr$rcrrrbrPr!rdrIrrJrGre)
r@ZereposZdreposr`raZenable_listZenable_list_failZrepoidZdisable_listZdisable_list_failZfailrKr&r'r'r(r"hs|




��

��z SubscriptionManager.update_reposcCst|jr|jp|j�S)N)�boolr=r0r<)r@r'r'r(r�sz!SubscriptionManager.is_configured)N)r*r+r,rFrAr#r$rrrrrr]rbr r"rr'r'r'r(rTs2�
#H"VrFcCstjdg||d�S)z�
    Uses the preferred cloud-init subprocess def of subp.subp
    and runs subscription-manager.  Breaking this to a
    separate function for later use in mocking and unittests
    zsubscription-manager)Z	logstring)r)rKrMr'r'r(rI�srI)F)�__doc__ZloggingZ	cloudinitrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarZcloudinit.settingsrZ	getLoggerr*rr
�__annotations__r%rr)�	ExceptionrrrIr'r'r'r(�<module>s$
�6p