HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /lib/python3/dist-packages/cloudinit/config/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/config/__pycache__/cc_rh_subscription.cpython-311.pyc
�

܍~c0D��n�UdZddlmZddlmZddlmZddlmZmZddl	m
Z
ddlmZddl
mZmZdd	lmZeje��Zd
Zddd
eddgeed��ed��ed��gdgd�Zeed<ee��Zdedede
dededdfd�ZGd�de��ZGd �d!��Zd$d#�ZdS)%zDRed Hat Subscription: Register Red Hat Enterprise Linux based system�)�Logger)�dedent��log)�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``.
�cc_rh_subscriptionzRed Hat Subscriptionz.Register Red Hat Enterprise Linux based system�fedora�rhelz�            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: 12345
            a�            rh_subscription:
                activation-key: foobar
                org: 12345
                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�description�distros�	frequency�examples�activate_by_schema_keys�metar�cfg�cloudr�args�returnNc��t||���}|���s|�d|��dS|����s�	|���\}}|durt|���|���}|std���|jrE|j�>|�	��std���|j
�d��nD|jr=|���std���|j
�d��|j�nt|jt��sd	}	t|	���|�|j��}
|
s'td
�|j�����|���}
|
std���|�d��dS#t
$rB}|�t)|����|�d
��Yd}~dSd}~wwxYw|�d��dS)Nrz%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)rrrrr�sm�verify�
verify_msg�cont�	pool_fail�return_stat�es            �E/usr/lib/python3/dist-packages/cloudinit/config/cc_rh_subscription.py�handler<Sst��
�S�c�	*�	*�	*�B�
�������	�	�.��5�5�5��t�
�����-7�*	P�!#���!2�!2��F�J��T�!�!�'�
�3�3�3��?�?�$�$�D��
�'�C�����~�	
:�"�/�"=��,�,�.�.�M�+�,M�N�N�N��F�L�L�!K�L�L�L�L���
:��*�*�,�,�:�+�,H�I�I�I��F�L�L�!8�9�9�9��x�#�!�"�(�D�1�1�7� D�I�+�I�6�6�6� �j�j���2�2��"��+�4�;�;�B�H�E�E�����/�/�+�+�K��
I�'�(G�H�H�H��N�N�J�K�K�K�K�K�� �	P�	P�	P��K�K��A�������K�K�N�O�O�O�O�O�O�O�O�O�����	P����	���5�6�6�6�6�6s�FG$�$
H0�.7H+�+H0c��eZdZdS)r%N)�__name__�
__module__�__qualname__��r;r%r%�s�������DrBr%c�f�eZdZgd�Zdd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�ZdS)r )�org�activation-key�username�password�disable-repo�enable-repo�add-pool�rhsm-baseurl�server-hostname�auto-attach�
service-levelNc��|�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)
NrrKrLrJrErDrFrGrMrIrHrN)�LOGrr�get�rhel_cfg�rhsm_baseurl�server_hostnamer+�activation_keyrD�useridrGr'�enable_repo�disable_repor()�selfrrs   r;�__init__zSubscriptionManager.__init__�s>���;��C�����������%6��;�;��
� �M�-�-�n�=�=���#�}�0�0�1B�C�C����]�&�&�z�2�2��
�"�m�/�/�0@�A�A����=�$�$�U�+�+����m�'�'�
�3�3����
�)�)�*�5�5��
��=�,�,�]�;�;����=�,�,�]�;�;��� �M�-�-�n�=�=��� �M�-�-�o�>�>����rBc�:�|j�|��dS)z>Simple wrapper for logging info messages. Useful for unittestsN)r�info�rY�msgs  r;r1zSubscriptionManager.log_success�s����
�
�c�����rBc�:�|j�|��dS)zASimple wrapper for logging warning messages. Useful for unittestsN)r�warningr]s  r;r2zSubscriptionManager.log_warn�s�����������rBc��|jD]?}||jvr4d�|d�|j����}d|fcS�@|j�8tj|j��stj|j��sd}d|fS|j�3|jr&tjt|j����rd}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)
rR�
valid_rh_keysr/�joinr'r�is_true�is_falser(r3)rY�k�bad_key�not_bool�no_autos     r;r$z SubscriptionManager._verify_keys�s�����	&�	&�A���*�*�*�� �&��D�I�I�d�.@�$A�$A�B�B��
�g�~�%�%�%�
+�
��(��L��)�*�*�
)�.2�m�D�<L�.M�.M�
)�K�
��(�?�"���)��!�
*�'+�}�S��9I�5J�5J�'K�'K�
*�$�
�
�'�>�!��zrBc�Z�dg}	t|��n#tj$rYdSwxYwdS)zg
        Checks if the system is already registered and returns
        True if so, else False
        �identityFT)�_sub_man_clir�ProcessExecutionError)rY�cmds  r;r#z!SubscriptionManager.is_registered�sM��
�l��	���������)�	�	�	��5�5�	�����ts��(�(c�\�|j��|j��dd�|j��d�|j��g}|j�-|�d�|j����|j�-|�d�|j����	t
|d���d	}�n�#tj$rC}|j	d
kr-|�
d�|j����Yd}~dSd}~wwxYw|j��|j
��dd
�|j��d�|j
��g}|j�-|�d�|j����|j�-|�d�|j����	t
|d���d	}n�#tj$rC}|j	d
kr-|�
d�|j����Yd}~dSd}~wwxYw|�
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)rUrDr/rS�appendrTrmrrn�stdoutr2�stderrrVrG�split�rstriprr")rYro�
return_outr:�reg_ids     r;r&z SubscriptionManager.rhn_register�s���
��+�$�(�2F��%�,�,�T�-@�A�A��"�"�4�8�,�,��C�� �,��
�
�?�1�1�$�2C�D�D�E�E�E��#�/��
�
�,�3�3�D�4H�I�I�J�J�J�
�)�#�T�B�B�B�1�E�
�
���-�
�
�
��8�r�>�>��M�M�9�@�@���J�J�����u�u�u�u�u�����
�����k�%�D�M�,E�� �'�'���4�4� �'�'��
�6�6��C�� �,��
�
�?�1�1�$�2C�D�D�E�E�E��#�/��
�
�,�3�3�D�4H�I�I�J�J�J�
�)�#�T�B�B�B�1�E�
�
���-�
�
�
��8�r�>�>��M�M�9�@�@���J�J�����u�u�u�u�u�����
����
�M�M�J�
�
�
�
�M�M�K�
�
�
��5��!�!�&�)�)�!�,�3�3�5�5������;�V�D�D�D��ts0�/C�D�8D�D�G#�#H5�28H0�0H5c�B�ddd�|j��g}	t|��d}n�#tj$r�}|j���dkr9|j�d��D]}|dkr|�|���n?|�d�|j	�
������Yd}~dSd}~wwxYw|�d��D]"}|dkr|j�|���#d	S)
N�attach�--autoz--servicelevel={0}rrs�
z*Setting the service level failed with: {0}FT)
r/r(rmrrnrvryrxr2rw�striprr"�rYrorzr:�lines     r;r)z&SubscriptionManager._set_service_level1s>���� �'�'��(9�:�:�
��
	�%�c�*�*�1�-�J�J���)�	�	�	��x��� � �B�&�&��H�N�N�4�0�0�,�,�D��r�z�z��
�
�d�+�+�+��,��
�
�@�G�G�����(�(������
�5�5�5�5�5�����	�����$�$�T�*�*�	%�	%�D��r�z�z�����t�$�$�$���ts�5�C$�BC�C$c�6�ddg}	t|��d}nE#tj$r3}|�d�|����Yd}~dSd}~wwxYw|�d��D]"}|dkr|j�|���#dS)	Nr}r~rzAuto-attach failed with: {0}FrrsT)rmrrnr2r/rxrr"r�s     r;r*z$SubscriptionManager._set_auto_attachKs�����"��	�%�c�*�*�1�-�J�J���)�	�	�	��M�M�8�?�?��B�B�C�C�C��5�5�5�5�5�����	�����$�$�T�*�*�	%�	%�D��r�z�z�����t�$�$�$���ts��A�(A�Ac��g}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.
        )r-z--available�--pool-onlyrr)r-z
--consumedr�)rmryrx)rY�	available�consumedro�resultss     r;�	_getPoolszSubscriptionManager._getPoolsWs���
�	���5�4�4���s�#�#�A�&���^�^�%�%�,�,�T�2�2�	�4�3�3���s�#�#�A�&���N�N�$�$�+�+�D�1�1���(�"�"rBc���ddg}t|��d}g}|�d��D]F}d|vr@|�|�d��d������Gddg}t|��d}g}|�d��D]F}d|vr@|�|�d��d������G||fS)	zl
        Obtains the current list of active yum repositories and returns
        them in list form.
        �reposz--list-enabledrrzRepo ID:�:rtz--list-disabled)rmrxrur�)rYrorz�active_repos�repo�inactive_reposs      r;�	_getReposzSubscriptionManager._getReposks���(�)��!�#�&�&�q�)�
����$�$�T�*�*�	B�	B�D��T�!�!��#�#�T�Z�Z��_�_�Q�%7�$>�$>�$@�$@�A�A�A���)�*��!�#�&�&�q�)�
����$�$�T�*�*�	D�	D�D��T�!�!��%�%�t�z�z�#���q�'9�&@�&@�&B�&B�C�C�C���^�+�+rBc���t|��dkr|j�d��dS|���\}}g}dg}|D][}||vr-||vr)|�d�|�����3|�d�|�����\t|��dkr�|�|��	t|��|j�dd�	|���
d	d
����dS#tj$r4}|�d�||����Yd}~d
Sd}~wwxYwdS)zl
        Takes a list of subscription pools and "attaches" them to the
        current subscription
        rzNo pools to attachTr}z
--pool={0}zPool {0} is not availablez/Attached the following pools to your system: %srbz--pool=rsz$Unable to attach pool {0} due to {1}NF)
�lenrr"r�rur/r2�extendrmrd�replacerrn)rYr+�pool_available�
pool_consumed�	pool_listro�poolr:s        r;r.zSubscriptionManager.addPool�s����u�:�:��?�?��H�N�N�/�0�0�0��4�(,���(8�(8�%��
��	��j���	H�	H�D��M�)�)���0F�0F�� � ��!4�!4�T�!:�!:�;�;�;�;��
�
�9�@�@��F�F�G�G�G�G��y�>�>�A����J�J�y�!�!�!�
��S�!�!�!�����E��Y�Y�y�)�)�2�2�9�b�A�A�����t���-�
�
�
��
�
�:�A�A�$��J�J�����u�u�u�u�u�����	
�����s�AD&�&E)�5)E$�$E)c��|j}|j}|�g}|�g}t|t��s|�d��dSt|t��s|�d��dSt|��dkr/t|��dkr|j�d��dS|���\}}g}g}|D]D}||vr)|�	d�
|�����/|�	|���Eg}g}	|D]D}||vr)|�	d�
|�����/|	�	|���Et|��dkrM|D]J}
|
|vr|j�d	|
���"|�d
�
|
�����Kt|	��dkr |	D]}
|j�d|
���dg}t|��dkr|�|��t|��dkr|�|��	t|��nE#tj$r3}|�d
�
|����Yd}~dSd}~wwxYwt|��dkrB|j�dd�|���dd����t|��dkrB|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: %srbz	--enable=rsz Disabled the following repos: %sz
--disable=)rWrXr,r-r2r�rr"r�rur/r�rmrrnrdr�)
rY�erepos�dreposr�r��enable_list�enable_list_fail�repoid�disable_list�disable_list_fail�failror:s
             r;r0z SubscriptionManager.update_repos�s����!���"���>��F��>��F��&�$�'�'�	��M�M�B�C�C�C��5��&�$�'�'�	��M�M�B�C�C�C��5�
��K�K�1���3�v�;�;�!�#3�#3��H�N�N�=�>�>�>��4�'+�~�~�'7�'7�$��n������	0�	0�F���'�'��"�"�>�#8�#8��#@�#@�A�A�A�A� �'�'��/�/�/�/������	1�	1�F���%�%��#�#�O�$:�$:�6�$B�$B�C�C�C�C�!�(�(��0�0�0�0��� � �1�$�$�(�
�
���<�'�'��H�N�N�#?��F�F�F�F��M�M�;�B�B�4�H�H������ �!�!�A�%�%�)�
�
������D�d������i���|���q� � ��J�J�|�$�$�$��{���a����J�J�{�#�#�#�	���������)�	�	�	��M�M�<�C�C�A�F�F�G�G�G��5�5�5�5�5�����	�����{���a����H�N�N�1����;�'�'�0�0��b�A�A�
�
�
��|���q� � ��H�N�N�2����<�(�(�1�1�,��C�C�
�
�
��ts�I�J�$(J�Jc�F�t|jr|jp|j��S�N)�boolrVrGrU)rYs r;r!z!SubscriptionManager.is_configured�s!���T�[�2�T�]�J�t�7J�K�K�KrBr�)r>r?r@rcrZr1r2r$r#r&r)r*r�r�r.r0r!rArBr;r r �s����������M�?�?�?�?�$������!�!�!�F���F�F�F�P���4
�
�
�#�#�#�(,�,�,�, � � �DT�T�T�lL�L�L�L�LrBr Fc�6�tjdg|z|���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)�	logstring)r)rorrs  r;rmrm�s"���9�,�-��3�}�M�M�M�MrB)F)�__doc__�loggingr�textwrapr�	cloudinitrrr�cloudinit.cloudr	�cloudinit.configr
�cloudinit.config.schemarr�cloudinit.settingsr
�	getLoggerr>rP�MODULE_DESCRIPTIONr�__annotations__r3r-r<�	Exceptionr%r rmrArBr;�<module>r�s*��K�J�J�������������$�$�$�$�$�$� � � � � � � � �!�!�!�!�!�!�#�#�#�#�#�#�<�<�<�<�<�<�<�<�+�+�+�+�+�+��g���!�!��	���"�
=�%��&�!����
�	
�	
�	��
�	
�	
�	��
�	
�	
�!&�N!2�2�]/�/��j�/�/�/�b�,�t�
�
��57�

�57��57�#(�57�/5�57�=A�57�	�57�57�57�57�p	�	�	�	�	�	�	�	�	�kL�kL�kL�kL�kL�kL�kL�kL�\N�N�N�N�N�NrB