%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/sos/collector/clusters/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/sos/collector/clusters/__pycache__/juju.cpython-312.pyc

�

i��d� ��L�ddlZddlZddlZddlmZdd�Zd�ZGd�de�Zy)�N)�Clusterc�n�|sgS|jd�D�cgc]}|j���c}Scc}w)zParse comma separated string.�,)�split�strip)�strings�strings  �=/usr/lib/python3/dist-packages/sos/collector/clusters/juju.py�_parse_option_stringrs-����	�)0���s�);�<�v�F�L�L�N�<�<��<s�2c�&�Gd�d�}||�S)aRHelper function to get Index.

    The reason why we need Index defined in function is because currently
    the collector.__init__ will load all the classes in this module
    and also Index. This will cause bug because it think Index is
    Cluster type. Also We don't want to provide a customized
    filter to remove Index class.
    c�(�eZdZdZd�Zd�Zd�Zd�Zy)�_get_index.<locals>.Indexz�Index structure to help parse juju status output.

        Attributes apps, units and machines are dict which key
        is the app/unit/machine name
        and the value is list of targets which format are
        {model_name}:{machine_id}.
        c�p�||_i|_i|_i|_t	j
d�|_y)N�sos)�
model_name�apps�units�machines�logging�	getLogger�ui_log)�selfrs  r
�__init__z"_get_index.<locals>.Index.__init__,s0��#-�D�O��D�I��D�J��D�M�!�+�+�E�2�D�K�c�>�|dj�D]�\}}g}|jdi�}|j�D]L\}}|d}|j�d|��}	|	g|j|<|	g|j|<|j|	��N||j|<��y)zAdds principal units to index.�applicationsr�machine�:N)�items�getrrr�appendr)
r�juju_status�app�app_info�nodesr�unit�	unit_infor�nodes
          r
�add_principalsz(_get_index.<locals>.Index.add_principals3s���!,�^�!<�!B�!B�!D�

'�
��X��� ���W�b�1��',�{�{�}�'�O�D�)�'�	�2�G�"�o�o�.�a��y�9�D�(,�v�D�J�J�t�$�.2�V�D�M�M�'�*��L�L��&�'�"'��	�	�#��

'rc��|dj�D�]5\}}|jdg�}|D�]}|jj|�s |jj	d|�d���?|j|j|j|�d|d|vr |jj	d|�d����|d|d}|j�D]f\}}|j�d|d��}	|jd	i�j�D]*\}
}|
j|d
z�s�|	g|j|
<�,�h����8y)z�Add subordinates to index.

            Since subordinates does not have units they need to be
            manually added.
            rzsubordinate-tozPrincipal charm z is missingrz is missing unitsrr�subordinates�/N)	rr rr�warning�extendr�
startswithr)rr"r#r$�subordinate_to�parentrr&r'r(�sub_key�	sub_values            r
�add_subordinatesz*_get_index.<locals>.Index.add_subordinatesAsd��"-�^�!<�!B�!B�!D�
=�
��X�!)���.>��!C��,�=�F��9�9�=�=��0����+�+�.�v�h�k�B��!��I�I�c�N�)�)�$�)�)�F�*;�<��k�.�&A�&�&I�I����+�+�.�v�h�6G�H��!�'��7��?��H�E�+0�;�;�=�=���i�"&�/�/�!2�!�I�i�4H�3I�J��2;�-�-�*�B�3��%�'�=�.�G�Y� '�1�1�#��)�<�7;�f��
�
�7� 3�	=�=�#=�
=rc�v�|dj�D]#}|j�d|��}|g|j|<�%y)z�Add machines to index.

            If model does not have any applications it needs to be
            manually added.
            rrN)�keysrr)rr"rr(s    r
�add_machinesz&_get_index.<locals>.Index.add_machinesbsF��'�z�2�7�7�9�
0���/�/�*�!�G�9�5��*.���
�
�g�&�
0rN)�__name__�
__module__�__qualname__�__doc__rr)r4r7�rr
�Indexr#s��	�	3�	'�	=�B	0rr=r<)rr=s  r
�
_get_indexr>s��G0�G0�R���rc�J�eZdZdZdZdZgd�Zd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
y)�jujua!
    The juju cluster profile is intended to be used on juju managed clouds.
    It"s assumed that `juju` is installed on the machine where `sos` is called,
    and that the juju user has superuser privilege to the current controller.

    By default, the sos reports will be collected from all the applications in
    the current model. If necessary, you can filter the nodes by models /
    applications / units / machines with cluster options.

    Example:

    sos collect --cluster-type juju -c "juju.models=sos" -c "juju.apps=a,b,c"

    zJuju Managed Clouds))r�z1Filter node list by apps (comma separated regex).)rrAz3Filter node list by units (comma separated string).)�modelsrAz4Filter node list by models (comma separated string).)rrAz6Filter node list by machines (comma separated string).c�P�tjdd|dtj�S)z#Remove leading characters before {.z(^[^{]*)(.*)z\2r)�re�sub�	MULTILINE)r�outputs  r
�_cleanup_juju_outputzjuju._cleanup_juju_output�s���v�v�o�u�f�a����F�Frc��|j|�}t|��}|j|�|j|�|j	|�|S)z�Parse juju status output and return target dict.

        Here are couple helper functions to parse the juju principals units,
        subordinate units and machines.
        )r)�_execute_juju_statusr>r)r4r7)rrr"�indexs    r
�_get_model_infozjuju._get_model_info�sM���/�/�
�;���j�1��
���[�)�
���{�+�
���;�'��rc�@�|rd|��nd}d}|j�d|�d|��}|j|�}|ddk(std|�d	|d����|j|d
�}d}	t	j
|�}|S#tj$rtd|����wxYw)Nz-m rAz
--format jsonz status � �statusr�'z' returned error: rGz-Juju output is not valid json format.Output: )�cmd�exec_primary_cmd�	ExceptionrH�json�loads�JSONDecodeError)rr�model_option�
format_option�
status_cmd�res�juju_json_outputr"s        r
rJzjuju._execute_juju_status�s���-7��Z�L�)�R��'�
����z��,��q���H�
��#�#�J�/���8�}��!��a�
�|�+=�c�(�m�_�M�N�N��4�4�c�(�m�E����	��*�*�%5�6�K�����#�#�	���+�,�.��
�	�s�$A;�;"Bc���t�}|D]P}t||�j�D]1\}}tj||�s�|j|xsg��3�R|S)zFilter with regex match.)�set�getattrrrD�match�update�r�key�patterns�
model_infor%�pattern�param�values        r
�_filter_by_patternzjuju._filter_by_pattern�s`������	.�G� '�
�C� 8� >� >� @�
.���u��8�8�G�U�+��L�L���"�-�
.�	.��rc��t�}|D]?}t||�j�D] \}}||k(s�|j|xsg��"�A|S)zFilter with fixed match.)r]r^rr`ras        r
�_filter_by_fixedzjuju._filter_by_fixed�sZ������	.�G� '�
�C� 8� >� >� @�
.���u��e�#��L�L���"�-�
.�	.��rc��y)z'Dynamically change transport to 'juju'.r@r<)rs r
�set_transport_typezjuju.set_transport_type�s��rc�&�t|jd��}t|jd��}t|jd��}t|jd��}|||d�}t|j��s|sgS|sdg}t	�}|D]h}|j|�}|j
�D]B\}	}
|	dk(r|j|	|
|�}n|j|	|
|�}|j|��D�jt|�S)z+Get the machine numbers from `juju status`.rBrrr)rrrrA)r�
get_option�any�valuesr]rLrrhrjr`�list)rrBrrr�filtersr%�modelrdrb�resource�_nodess            r
�	get_nodeszjuju.get_nodes�s��%�d�o�o�h�&?�@��#�D�O�O�F�$;�<��$�T�_�_�W�%=�>��'����
�(C�D���%�X�F���7�>�>�#�$�V��I���T�F�����	%�E��-�-�e�4�J�!(����
%�
��X��&�=�!�4�4�S�(�J�O�F�!�2�2�3��*�M�F����V�$�

%�	%��E�{�rN)r8r9r:r;rQ�cluster_name�option_listrHrLrJrhrjrlrvr<rr
r@r@os>��
��C�(�L�	�K�G�
��&���rr@)N)rrTrD�sos.collector.clustersrrr>r@r<rr
�<module>rzs-����	�*�=�S�lt�7�tr

Zerion Mini Shell 1.0