403Webshell
Server IP : 23.254.227.96  /  Your IP : 216.73.216.7
Web Server : Apache/2.4.62 (Unix) OpenSSL/1.1.1k
System : Linux hwsrv-1277026.hostwindsdns.com 4.18.0-477.13.1.el8_8.x86_64 #1 SMP Tue May 30 14:53:41 EDT 2023 x86_64
User : viralblo ( 1001)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.6/site-packages/cloudinit/config/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.6/site-packages/cloudinit/config/__pycache__/cc_rh_subscription.cpython-36.pyc
3

��b�?�@shdZddlmZddlmZmZeje�ZddgZ	dd�Z
Gdd	�d	e�ZGd
d�de
�Zdd
d�ZdS)a&
Red Hat Subscription
--------------------
**Summary:** register red hat enterprise linux based system

Register a Red Hat system either by username and password *or* activation and
org. Following a sucessful registration, you can auto-attach subscriptions, set
the service level, add subscriptions based on pool id, enable/disable yum
repositories based on repo id, and alter the rhsm_baseurl and server-hostname
in ``/etc/rhsm/rhs.conf``. For more details, see the ``Register Red Hat
Subscription`` example config.

**Internal name:** ``cc_rh_subscription``

**Module frequency:** per instance

**Supported distros:** rhel, fedora

**Config keys**::

    rh_subscription:
        username: <username>
        password: <password>
        activation-key: <activation key>
        org: <org number>
        auto-attach: <true/false>
        service-level: <service level>
        add-pool: <list of pool ids>
        enable-repo: <list of yum repo ids>
        disable-repo: <list of yum repo ids>
        rhsm-baseurl: <url>
        server-hostname: <hostname>
�)�log)�subp�utilZfedoraZrhelcCsjt||d�}|j�s$|jd|�dS|j��s\y�|j�\}}|dk	rLt|��|j�}|s`td��|jr�|jdk	r�|j	�s�td��q�|j
jd�n$|jr�|j�s�td��n|j
jd�|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)rz%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�
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)�name�cfgZ_cloudrZ_argsZsmZverifyZ
verify_msgZcontZ	pool_failZreturn_stat�e�r�(/usr/lib/python3.6/cc_rh_subscription.py�handle1sJ


rc@seZdZdS)r
N)�__name__�
__module__�__qualname__rrrrr
gsr
c@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)
NZrh_subscriptionzrhsm-baseurlzserver-hostnamezadd-poolzactivation-keyr"r#r$zauto-attachzenable-repozdisable-repoz
service-level)�LOGrr�get�rhel_cfg�rhsm_baseurl�server_hostnamer�activation_keyr"�useridr$r�enable_repo�disable_repor
)�selfrrrrr�__init__zs zSubscriptionManager.__init__cCs|jj|�dS)z>Simple wrapper for logging info messages. Useful for unittestsN)r�info)r.�msgrrrr�szSubscriptionManager.log_successcCs|jj|�dS)zASimple wrapper for logging warning messages. Useful for unittestsN)rZwarning)r.r1rrrr�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)
r'�
valid_rh_keysr�joinrrZis_trueZis_falser
r)r.�kZbad_keyZnot_boolZno_autorrrr	�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.�cmdrrrr�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)r*r"rr(�appendr)r5rr6�stdoutr�stderrr+r$�split�rstriprr)r.r7�
return_outrZreg_idrrrr�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}rr:�
z*Setting the service level failed with: {0}FT)
rr
r5rr6r=r@r?rr>�striprr)r.r7rAr�linerrrr
s$z&SubscriptionManager._set_service_levelcCsxddg}yt|�d}Wn2tjk
rJ}z|jdj|��dSd}~XnXx&|jd�D]}|dkrX|jj|�qXWdS)	NrBz--autorzAuto-attach failed with: {0}FrCr:T)r5rr6rrr?rr)r.r7rArrErrrr'sz$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.
        rz--availablez--pool-onlyrrCz
--consumed)r5r@r?)r.Z	available�consumedr7�resultsrrr�	_getPools3s

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-enabledrrCzRepo ID:�:r;z--list-disabled)r5r?r<rD)r.r7rA�active_reposZrepo�inactive_reposrrr�	_getReposGs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 attachTrBz
--pool={0}zPool {0} is not availablez/Attached the following pools to your system: %sz, z--pool=r:z$Unable to attach pool {0} due to {1}FN)
�lenrrrHr<rr�extendr5r3�replacerr6)r.rZpool_availableZ
pool_consumedZ	pool_listr7Zpoolrrrrr]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 enabledrIz Unable to alter repos due to {0}zEnabled the following repos: %sz, z	--enable=r:z Disabled the following repos: %sz
--disable=)r,r-rrrrNrrrMr<rrOr5rr6r3rP)
r.ZereposZdreposrKrLZenable_listZenable_list_failZrepoidZdisable_listZdisable_list_failZfailr7rrrrrsr










z SubscriptionManager.update_reposcCst|jr|jp|j�S)N)�boolr+r$r*)r.rrrr�sz!SubscriptionManager.is_configured)N)rr r!r2r/rrr	rrrrrHrMrrrrrrrrks0
#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)r7r9rrrr5�sr5N)F)�__doc__Z	cloudinitrZloggingrrZ	getLoggerrr%Zdistrosr�	Exceptionr
�objectrr5rrrr�<module>'s
6p

Youez - 2016 - github.com/yon3zu
LinuXploit