%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3.9/site-packages/cloudinit/config/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3.9/site-packages/cloudinit/config/__pycache__/cc_rh_subscription.cpython-39.pyc

a

'�Dg�<�@s�UdZddlZddlmZmZddlmZddlmZddl	m
Z
ddlmZe�
e�Zdgd	�e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_subscription)ZfedoraZrhelZ	openeuler�rh_subscription)�idZdistrosZ	frequencyZactivate_by_schema_keys�meta)�name�cfg�cloud�args�returnc
Csht|td�}|��s$t�d|�dS|���sZz�|��\}}|durLt|��|��}|s`td��|jr�|j	dur�|�
�s�td��q�|j�d�n$|jr�|��s�td��n|j�d�|j
dur�t|j
t�s�d	}t|��|�|j
�}	|	s�td
�|j
���|��}	|	�std��|�d�Wn>t�yV}
z$|�t|
��|�d
�WYd}
~
n
d}
~
00n
|�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'�G/usr/lib/python3.9/site-packages/cloudinit/config/cc_rh_subscription.py�handlesN
�	



�"r)c@seZdZdS)rN)�__name__�
__module__�__qualname__r'r'r'r(rPsrc@s~eZdZgd�Zddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)r)�org�activation-key�username�password�disable-repo�enable-repo�add-pool�rhsm-baseurl�server-hostname�auto-attach�
service-levelNcCs�|dur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].}||jvrd�|d�|j��}d|fSq|jdurdt�|j�sdt�|j�sdd}d|fS|jdur�|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}s0

��

�
��
���z SubscriptionManager._verify_keyscCs.dg}zt|�Wntjy(YdS0dS)zg
        Checks if the system is already registered and returns
        True if so, else False
        �identityFT)�_sub_man_clir�ProcessExecutionError)r@�cmdr'r'r(r�sz!SubscriptionManager.is_registeredc
Cs�|jdur�|jdur�dd�|j�d�|j�g}|jdurJ|�d�|j��|jdurf|�d�|j��zt|dd�d	}WnDtjy�}z*|j	d
kr�|�
d�|j��WYd}~dSd}~00n�|jdu�r�|j
du�r�dd
�|j�d�|j
�g}|jdu�r|�d�|j��|jdu�r0|�d�|j��zt|dd�d	}WnHtj�y�}z,|j	d
k�rv|�
d�|j��WYd}~dSd}~00n|�
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;rJrrK�stdoutr$�stderrr=r0�split�rstriprr)r@rL�
return_outr&Zreg_idr'r'r(r�sX

�	



�

�	
���z SubscriptionManager.rhn_registerc
Cs�ddd�|j�g}zt|�d}Wnrtjy�}zX|j��dkrh|j�d�D]}|dkrN|�|�qNn|�d�|j	�
���WYd}~dSd}~00|�d�D]}|dkr�|j�|�q�d	S)
N�attach�--autoz--servicelevel={0}rrO�
z*Setting the service level failed with: {0}FT)
r!rrJrrKrRrUrTr$rS�striprr�r@rLrVr&�liner'r'r(r�s*
���z&SubscriptionManager._set_service_levelc
Cszddg}zt|�d}Wn8tjyP}z|�d�|��WYd}~dSd}~00|�d�D]}|dkr\|j�|�q\dS)	NrWrXrzAuto-attach failed with: {0}FrYrOT)rJrrKr$r!rTrrr[r'r'r(rsz$SubscriptionManager._set_auto_attachcCsTg}g}gd�}t|�d}|���d�}gd�}t|�d}|���d�}||fS)zh
        Gets the list pools for the active subscription and returns them
        in list form.
        )rz--available�--pool-onlyrrY)rz
--consumedr])rJrUrT)r@Z	available�consumedrL�resultsr'r'r(�	_getPoolsszSubscriptionManager._getPoolscCs�ddg}t|�d}g}|�d�D]$}d|vr"|�|�d�d���q"ddg}t|�d}g}|�d�D]$}d|vrj|�|�d�d���qj||fS)	zl
        Obtains the current list of active yum repositories and returns
        them in list form.
        �reposz--list-enabledrrYzRepo ID:�:rPz--list-disabled)rJrTrQrZ)r@rLrV�active_reposZrepo�inactive_reposr'r'r(�	_getRepos0szSubscriptionManager._getReposc
Cs�t|�dkr|j�d�dS|��\}}g}dg}|D]6}||vr\||vr\|�d�|��q6|�d�|��q6t|�dkr�|�|�z*t|�|j�dd�	|��
d	d
��WdStjy�}z |�d�||��WYd}~d
Sd}~00dS)zl
        Takes a list of subscription pools and "attaches" them to the
        current subscription
        rzNo pools to attachTrWz
--pool={0}zPool {0} is not availablez/Attached the following pools to your system: %srEz--pool=rOz$Unable to attach pool {0} due to {1}NF)
�lenrrr`rQr!r$�extendrJrG�replacerrK)r@rZpool_availableZ
pool_consumedZ	pool_listrLZpoolr&r'r'r(r Fs0
�
�zSubscriptionManager.addPoolc

Cs6|j}|j}|durg}|dur$g}t|t�s<|�d�dSt|t�sT|�d�dSt|�dkr|t|�dkr||j�d�dS|��\}}g}g}|D](}||vr�|�	d�
|��q�|�	|�q�g}g}	|D](}||vr�|�	d�
|��q�|	�	|�q�t|�dk�r8|D]0}
|
|v�r$|j�d	|
�n|�d
�
|
���qt|	�dk�r`|	D]}
|j�d|
��qJdg}t|�dk�r~|�|�t|�dk�r�|�|�zt|�Wn:t
j�y�}z|�d
�
|��WYd}~dSd}~00t|�dk�r|j�dd�|��dd��t|�dk�r2|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 enabledraz Unable to alter repos due to {0}zEnabled the following repos: %srEz	--enable=rOz Disabled the following repos: %sz
--disable=)r>r?rrr$rfrrrerQr!rgrJrrKrGrh)
r@ZereposZdreposrcrdZenable_listZenable_list_failZrepoidZdisable_listZdisable_list_failZfailrLr&r'r'r(r"hsz




��

��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`rer r"rr'r'r'r(rTs
#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)rLrNr'r'r(rJ�srJ)F)�__doc__ZloggingZ	cloudinitrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarZcloudinit.settingsrZ	getLoggerr*rr
�__annotations__r%rr)�	ExceptionrrrJr'r'r'r(�<module>s$
�6p

Zerion Mini Shell 1.0