관리-도구
편집 파일: cc_rh_subscription.cpython-39.pyc
a ����'�Dg�<����������������������@���s����U�d�Z�ddlZddlmZmZ�ddlmZ�ddlmZ�ddl m Z �ddlmZ�e� e�Zdg�d �ed gd�Ze ed<�eeeedd �dd�ZG�dd��de�ZG�dd��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�������������� ���C���sh��t�|td�}|���s$t�d|���d�S�|����sZz�|���\}}|durLt|��|���}|s`td��|jr�|j d�ur�|� ��s�td��q�|j�d��n$|jr�|���s�td��n|j�d��|j d�ur�t|j t�s�d }t|��|�|j �} | s�td �|j ���|���} | �std��|�d��W�n>�t�yV�} �z$|�t| ���|�d ��W�Y�d�} ~ n d�} ~ 0�0�n |�d��d�S�)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���r���r ���r���ZsmZverifyZ verify_msgZcontZ pool_failZreturn_stat�e��r'����G/usr/lib/python3.9/site-packages/cloudinit/config/cc_rh_subscription.py�handle���sN���� � �"r)���c�������������������@���s���e�Zd�ZdS�)r���N)�__name__� __module__�__qualname__r'���r'���r'���r(���r���P���s���r���c�������������������@���s~���e�Zd�Zg�d�Zddd�Zdd��Zdd��Zd d ��Zdd��Zd d��Z dd��Z dd��Zdd��Zdd��Z dd��Zdd��Zdd��ZdS�)r���)�org�activation-key�username�password�disable-repo�enable-repo�add-pool�rhsm-baseurl�server-hostname�auto-attach� service-levelNc�����������������C���s����|d�u�rt�}||�_||�_|�j�di��|�_|�j�d�|�_|�j�d�|�_|�j�d�|�_|�j�d�|�_|�j�d�|�_ |�j�d�|�_ |�j�d�|�_|�j�d �|�_|�j�d �|�_ |�j�d�|�_|�j�d�|�_d�S�) Nr���r4���r5���r3���r.���r-���r/���r0���r6���r2���r1���r7���)r���r���r����get�rhel_cfg�rhsm_baseurl�server_hostnamer����activation_keyr-����useridr0���r����enable_repo�disable_repor���)�selfr���r���r'���r'���r(����__init__c���s ����zSubscriptionManager.__init__c�����������������C���s���|�j��|��dS�)z>Simple wrapper for logging info messages. Useful for unittestsN)r����info�r@����msgr'���r'���r(���r#���u���s����zSubscriptionManager.log_successc�����������������C���s���|�j��|��dS�)zASimple wrapper for logging warning messages. Useful for unittestsN)r���ZwarningrC���r'���r'���r(���r$���y���s����zSubscriptionManager.log_warnc�����������������C���s����|�j�D�].}||�jvrd�|d�|�j��}d|f��S�q|�jdurdt�|�j�sdt�|�j�sdd}d|fS�|�jdur�|�jr�t�t |�j��r�d}d|fS�dS�)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!����joinr���r���Zis_trueZis_falser���r%���)r@����kZbad_keyZnot_boolZno_autor'���r'���r(���r���}���s0���� �� � �� ���z SubscriptionManager._verify_keysc�����������������C���s.���dg}zt�|��W�n�tjy(���Y�dS�0�dS�)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�������������� ���C���s���|�j�dur�|�jdur�dd�|�j��d�|�j�g}|�jdurJ|�d�|�j���|�jdurf|�d�|�j���zt|dd�d �}W�nD�tjy��}�z*|j d kr�|�� d�|j���W�Y�d}~dS�d}~0�0�n�|�jdu�r�|�j du�r�dd �|�j�d�|�j �g}|�jdu�r|�d�|�j���|�jdu�r0|�d�|�j���zt|dd�d �}W�nH�tj�y��}�z,|j d k�rv|�� d�|j���W�Y�d}~dS�d}~0�0�n|�� d��|�� d��dS�|�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;���rJ���r���rK����stdoutr$����stderrr=���r0����split�rstripr���r���)r@���rL���� return_outr&���Zreg_idr'���r'���r(���r�������sX���� � � � ���z SubscriptionManager.rhn_registerc�������������� ���C���s����ddd��|�j�g}zt|�d�}W�nr�tjy��}�zX|j���dkrh|j�d�D�]}|dkrN|��|��qNn|��d��|j � �����W�Y�d�}~dS�d�}~0�0�|�d�D�]}|dkr�|�j�|��q�d S�) N�attach�--autoz--servicelevel={0}r���rO���� z*Setting the service level failed with: {0}FT) r!���r���rJ���r���rK���rR���rU���rT���r$���rS����stripr���r����r@���rL���rV���r&����liner'���r'���r(���r�������s*���� ���z&SubscriptionManager._set_service_levelc�������������� ���C���sz���ddg}zt�|�d�}W�n8�tjyP�}�z|��d�|���W�Y�d�}~dS�d�}~0�0�|�d�D�]}|dkr\|�j�|��q\dS�) NrW���rX���r���zAuto-attach failed with: {0}FrY���rO���T)rJ���r���rK���r$���r!���rT���r���r���r[���r'���r'���r(���r�����s����z$SubscriptionManager._set_auto_attachc�����������������C���sT���g�}g�}g�d�}t�|�d�}|����d�}g�d�}t�|�d�}|����d�}||fS�)zh Gets the list pools for the active subscription and returns them in list form. )r���z--available�--pool-onlyr���rY���)r���z --consumedr]���)rJ���rU���rT���)r@���Z available�consumedrL����resultsr'���r'���r(���� _getPools��s����zSubscriptionManager._getPoolsc�����������������C���s����ddg}t�|�d�}g�}|�d�D�]$}d|v�r"|�|�d�d������q"ddg}t�|�d�}g�}|�d�D�]$}d|v�rj|�|�d�d������qj||fS�) zl Obtains the current list of active yum repositories and returns them in list form. �reposz--list-enabledr���rY���zRepo ID:�:rP���z--list-disabled)rJ���rT���rQ���rZ���)r@���rL���rV����active_reposZrepo�inactive_reposr'���r'���r(���� _getRepos0��s����zSubscriptionManager._getReposc�������������� ���C���s����t�|�dkr|�j�d��dS�|����\}}g�}dg}|D�]6}||vr\||v�r\|�d�|���q6|��d�|���q6t�|�dkr�|�|��z*t|��|�j�dd� |�� d d ���W�dS��tjy��}�z |��d�||���W�Y�d}~d S�d}~0�0�dS�)zl Takes a list of subscription pools and "attaches" them to the current subscription r���zNo pools to attachTrW���z --pool={0}zPool {0} is not availablez/Attached the following pools to your system: %srE���z--pool=rO���z$Unable to attach pool {0} due to {1}NF) �lenr���r���r`���rQ���r!���r$����extendrJ���rG����replacer���rK���)r@���r���Zpool_availableZ pool_consumedZ pool_listrL���Zpoolr&���r'���r'���r(���r ���F��s0���� � �zSubscriptionManager.addPoolc����������� ��� ���C���s6��|�j�}|�j}|du�rg�}|du�r$g�}t|t�s<|��d��dS�t|t�sT|��d��dS�t|�dkr|t|�dkr||�j�d��dS�|����\}}g�}g�}|D�](}||v�r�|� d� |���q�|� |��q�g�}g�} |D�](}||v�r�|� d� |���q�| � |��q�t|�dk�r8|D�]0} | |v��r$|�j�d | ��n|��d � | ����qt| �dk�r`| D�]} |�j�d| ���qJdg}t|�dk�r~|�|��t|�dk�r�|�|��zt|��W�n:�t j�y��}�z|��d � |���W�Y�d}~dS�d}~0�0�t|�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.Fr���z 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 enabledra���z Unable to alter repos due to {0}zEnabled the following repos: %srE���z --enable=rO���z Disabled the following repos: %sz --disable=)r>���r?���r���r���r$���rf���r���r���re���rQ���r!���rg���rJ���r���rK���rG���rh���) r@���ZereposZdreposrc���rd���Zenable_listZenable_list_failZrepoidZdisable_listZdisable_list_failZfailrL���r&���r'���r'���r(���r"���h��sz���� �� ��z SubscriptionManager.update_reposc�����������������C���s���t�|�jr|�jp|�j�S�)N)�boolr=���r0���r<���)r@���r'���r'���r(���r������s����z!SubscriptionManager.is_configured)N)r*���r+���r,���rF���rA���r#���r$���r���r���r���r���r���r`���re���r ���r"���r���r'���r'���r'���r(���r���T���s��� #H"Vr���Fc�����������������C���s���t�j�dg|��|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���)rL���rN���r'���r'���r(���rJ������s����rJ���)F)�__doc__ZloggingZ cloudinitr���r���Zcloudinit.cloudr���Zcloudinit.configr���Zcloudinit.config.schemar���Zcloudinit.settingsr���Z getLoggerr*���r���r ����__annotations__r%���r���r)���� Exceptionr���r���rJ���r'���r'���r'���r(����<module>���s$��� �6��p