HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/lib/python3.6/site-packages/cloudinit/config/__pycache__/cc_rh_subscription.cpython-36.pyc
3

�xh�C�
@s�UdZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZm
Z
ddlmZeje�Zd	Zd
dded
ddgeed�ed�ed�gdgd�Zee
e�Zee
eedd�dd�ZGdd�de�ZGdd�d�Zddd�ZdS) zDRed Hat Subscription: Register Red Hat Enterprise Linux based system�N)�dedent)�subp�util)�Cloud)�Config)�
MetaSchema�get_meta_doc)�PER_INSTANCEa[Register a Red Hat system either by username and password *or* activation and
org. Following a successful registration, you can:

 - auto-attach subscriptions
 - set the service level
 - add subscriptions based on pool id
 - enable/disable yum repositories based on repo id
 - alter the rhsm_baseurl and server-hostname in ``/etc/rhsm/rhs.conf``.
Zcc_rh_subscriptionzRed Hat Subscriptionz.Register Red Hat Enterprise Linux based systemZfedoraZrhelZ	openeulerz�            rh_subscription:
                username: joe@foo.bar
                ## Quote your password if it has symbols to be safe
                password: '1234abcd'
            zk            rh_subscription:
                activation-key: foobar
                org: "ABC"
            a�            rh_subscription:
                activation-key: foobar
                org: "ABC"
                auto-attach: true
                service-level: self-support
                add-pool:
                  - 1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a
                  - 2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b
                enable-repo:
                  - repo-id-to-enable
                  - other-repo-id-to-enable
                disable-repo:
                  - repo-id-to-disable
                  - other-repo-id-to-disable
                # Alter the baseurl in /etc/rhsm/rhsm.conf
                rhsm-baseurl: http://url
                # Alter the server hostname in /etc/rhsm/rhsm.conf
                server-hostname: foo.bar.com
            �rh_subscription)�id�name�title�descriptionZdistrosZ	frequencyZexamplesZactivate_by_schema_keys)r�cfg�cloud�args�returncCsjt|td�}|j�s$tjd|�dS|j��s\y�|j�\}}|dk	rLt|��|j�}|s`td��|jr�|j	dk	r�|j
�s�td��q�|jjd�n$|jr�|j�s�td��n|jjd�|j
dk	�r�t|j
t�s�d	}t|��|j|j
�}	|	�s�td
j|j
���|j�}	|	�std��|jd�Wn<tk
�rX}
z|jt|
��|jd
�WYdd}
~
XnXn
|jd�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)rrrrZsmZverifyZ
verify_msgZcontZ	pool_failZreturn_stat�e�r*�(/usr/lib/python3.6/cc_rh_subscription.py�handleRsJ


r,c@seZdZdS)rN)�__name__�
__module__�__qualname__r*r*r*r+r�src@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�orgzactivation-key�username�passwordzdisable-repozenable-repozadd-poolzrhsm-baseurlzserver-hostnamezauto-attachz
service-levelNcCs�|dkrt}||_||_|jjdi�|_|jjd�|_|jjd�|_|jjd�|_|jjd�|_|jjd�|_	|jjd�|_
|jjd�|_|jjd	�|_|jjd
�|_
|jjd�|_|jjd�|_dS)
Nr
zrhsm-baseurlzserver-hostnamezadd-poolzactivation-keyr0r1r2zauto-attachzenable-repozdisable-repoz
service-level)rrr�get�rhel_cfg�rhsm_baseurl�server_hostnamer �activation_keyr0�useridr2r�enable_repo�disable_repor)�selfrrr*r*r+�__init__�s zSubscriptionManager.__init__cCs|jj|�dS)z>Simple wrapper for logging info messages. Useful for unittestsN)r�info)r;�msgr*r*r+r&�szSubscriptionManager.log_successcCs|jj|�dS)zASimple wrapper for logging warning messages. Useful for unittestsN)rZwarning)r;r>r*r*r+r'�szSubscriptionManager.log_warncCs�x4|jD]*}||jkrdj|dj|j��}d|fSqW|jdk	rftj|j�pVtj|j�rfd}d|fS|jdk	r�|js�tjt	|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}z, 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: TrueT)TN)
r4�
valid_rh_keysr$�joinrrZis_trueZis_falserr()r;�kZbad_keyZnot_boolZno_autor*r*r+r�s


z SubscriptionManager._verify_keyscCs.dg}yt|�Wntjk
r(dSXdS)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_registeredcCs�|jdk	r�|jdk	r�ddj|j�dj|j�g}|jdk	rJ|jdj|j��|jdk	rf|jdj|j��yt|dd�d	}Wn>tjk
r�}z |j	d
kr�|j
dj|j��dSd}~XnXn�|jdk	o�|j
dk	�r�dd
j|j�dj|j
�g}|jdk	�r
|jdj|j��|jdk	�r(|jdj|j��yt|dd�d	}WnBtjk
�r~}z"|j	d
k�rp|j
dj|j��dSd}~XnXn|j
d�|j
d�dS|jd�dj�}|jjd|�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)r7r0r$r5�appendr6rBrrC�stdoutr'�stderrr8r2�split�rstriprr)r;rD�
return_outr)Zreg_idr*r*r+r�sL




z SubscriptionManager.rhn_registercCs�dddj|j�g}yt|�d}Wnptjk
r�}zR|jj�dkrnx>|jjd�D]}|dkrR|j|�qRWn|jdj|j	j
���dSd}~XnXx&|jd�D]}|dkr�|jj|�q�Wd	S)
N�attachz--autoz--servicelevel={0}rrG�
z*Setting the service level failed with: {0}FT)
r$rrBrrCrJrMrLr'rK�striprr)r;rDrNr)�liner*r*r+r.s$z&SubscriptionManager._set_service_levelcCsxddg}yt|�d}Wn2tjk
rJ}z|jdj|��dSd}~XnXx&|jd�D]}|dkrX|jj|�qXWdS)	NrOz--autorzAuto-attach failed with: {0}FrPrGT)rBrrCr'r$rLrr)r;rDrNr)rRr*r*r+rHsz$SubscriptionManager._set_auto_attachcCsXg}g}dddg}t|�d}|j�jd�}dddg}t|�d}|j�jd�}||fS)zh
        Gets the list pools for the active subscription and returns them
        in list form.
        r"z--availablez--pool-onlyrrPz
--consumed)rBrMrL)r;Z	available�consumedrD�resultsr*r*r+�	_getPoolsTs

zSubscriptionManager._getPoolscCs�ddg}t|�d}g}x2|jd�D]$}d|kr$|j|jd�dj��q$Wddg}t|�d}g}x2|jd�D]$}d|krp|j|jd�dj��qpW||fS)	zl
        Obtains the current list of active yum repositories and returns
        them in list form.
        �reposz--list-enabledrrPzRepo ID:�:rHz--list-disabled)rBrLrIrQ)r;rDrN�active_reposZrepo�inactive_reposr*r*r+�	_getReposhszSubscriptionManager._getReposcCs�t|�dkr|jjd�dS|j�\}}g}dg}x>|D]6}||kr^||kr^|jdj|��q8|jdj|��q8Wt|�dkr�|j|�y(t|�|jjddj	|�j
d	d
��dStjk
r�}z|jdj||��dSd
}~XnXd
S)zl
        Takes a list of subscription pools and "attaches" them to the
        current subscription
        rzNo pools to attachTrOz
--pool={0}zPool {0} is not availablez/Attached the following pools to your system: %sz, z--pool=rGz$Unable to attach pool {0} due to {1}FN)
�lenrrrUrIr$r'�extendrBr@�replacerrC)r;r Zpool_availableZ
pool_consumedZ	pool_listrDZpoolr)r*r*r+r#~s,

zSubscriptionManager.addPoolc
Cs@|j}|j}|dkrg}|dkr$g}t|t�s<|jd�dSt|t�sT|jd�dSt|�dkr|t|�dkr||jjd�dS|j�\}}g}g}x0|D](}||kr�|j	dj
|��q�|j	|�q�Wg}g}	x0|D](}||kr�|j	dj
|��q�|	j	|�q�Wt|�dk�rDx8|D]0}
|
|k�r.|jjd	|
�n|jd
j
|
���qWt|	�dk�rpx|	D]}
|jjd|
��qXWdg}t|�dk�r�|j|�t|�dk�r�|j|�yt|�Wn4t
jk
�r�}z|jd
j
|��dSd}~XnXt|�dk�r|jjddj|�jdd��t|�dk�r<|jjddj|�jdd��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 enabledrVz Unable to alter repos due to {0}zEnabled the following repos: %sz, z	--enable=rGz Disabled the following repos: %sz
--disable=)r9r:r!r"r'r[rrrZrIr$r\rBrrCr@r])
r;ZereposZdreposrXrYZenable_listZenable_list_failZrepoidZdisable_listZdisable_list_failZfailrDr)r*r*r+r%�sr










z SubscriptionManager.update_reposcCst|jr|jp|j�S)N)�boolr8r2r7)r;r*r*r+r�sz!SubscriptionManager.is_configured)N)r-r.r/r?r<r&r'rrrrrrUrZr#r%rr*r*r*r+r�s0
#H"VrFcCstjdg||d�S)z�
    Uses the prefered 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)rDrFr*r*r+rB�srB)F)�__doc__Zlogging�textwraprZ	cloudinitrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarrZcloudinit.settingsr	Z	getLoggerr-rZMODULE_DESCRIPTION�metar(r"r,�	ExceptionrrrBr*r*r*r+�<module>s:
6p