403Webshell
Server IP : 172.24.0.40  /  Your IP : 216.73.216.10
Web Server : Apache
System : Linux dbweb26.ust.edu.ph 4.18.0-513.5.1.el8_9.x86_64 #1 SMP Fri Sep 29 05:21:10 EDT 2023 x86_64
User : apache ( 48)
PHP Version : 8.2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.6/site-packages/sos/collector/clusters/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.6/site-packages/sos/collector/clusters/__pycache__/juju.cpython-36.pyc
3

3��d� �@sJddlZddlZddlZddlmZd	dd�Zdd�ZGdd�de�ZdS)
�N)�ClustercCs|sgSdd�|jd�D�S)zParse comma separated string.cSsg|]}|j��qS�)�strip)�.0�stringrr�/usr/lib/python3.6/juju.py�
<listcomp>sz(_parse_option_string.<locals>.<listcomp>�,)�split)Zstringsrrr�_parse_option_stringsrcCsGdd�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@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)z_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}.
        cSs(||_i|_i|_i|_tjd�|_dS)NZsos)�
model_name�apps�units�machines�loggingZ	getLogger�ui_log)�selfrrrr�__init__,s
z"_get_index.<locals>.Index.__init__c
Ss�x�|dj�D]r\}}g}|jdi�}xN|j�D]B\}}|d}|j�d|��}	|	g|j|<|	g|j|<|j|	�q0W||j|<qWdS)zAdds principal units to index.�applicationsr�machine�:N)�items�getrrr�appendr
)
r�juju_status�app�app_info�nodesr�unit�	unit_infor�noderrr�add_principals3sz(_get_index.<locals>.Index.add_principalscSs
�x|dj�D]�\}}|jdg�}x�|D]�}|jj|�sP|jjd|�d��q*|j|j|j|�d|d|kr�|jjd|�d��q*|d|d}x`|j�D]T\}}|j�d|d��}	x6|jd	i�j�D]"\}
}|
j|d
�r�|	g|j|
<q�Wq�Wq*WqWdS)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 unitsrrZsubordinates�/N)	rrr
rZwarning�extendr�
startswithr)rrrrZsubordinate_to�parentrrrr Zsub_keyZ	sub_valuerrr�add_subordinatesAs&
z*_get_index.<locals>.Index.add_subordinatescSs6x0|dj�D] }|j�d|��}|g|j|<qWdS)z�Add machines to index.

            If model does not have any applications it needs to be
            manually added.
            rrN)�keysrr)rrrr rrr�add_machinesbsz&_get_index.<locals>.Index.add_machinesN)�__name__�
__module__�__qualname__�__doc__rr!r&r(rrrr�Index#s
!r-r)rr-rrr�
_get_indexs
Ir.c@s\eZdZdZdZdZddddgZdd
�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�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 Cloudsr
��1Filter node list by apps (comma separated regex).r�3Filter node list by units (comma separated string).�models�4Filter node list by models (comma separated string).r�6Filter node list by machines (comma separated string).cCstjdd|dtj�S)z#Remove leading characters before {.z(^[^{]*)(.*)z\2r)�re�sub�	MULTILINE)r�outputrrr�_cleanup_juju_output�szjuju._cleanup_juju_outputcCs6|j|�}t|d�}|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!r&r()rrr�indexrrr�_get_model_info�s




zjuju._get_model_infocCs�|rd|��nd}d}|j�d|�d|��}|j|�}|ddksZtd|�d	|d����|j|d
�}d}ytj|�}Wn$tjk
r�td|����YnX|S)Nz-m r0z
--format jsonz status � Zstatusr�'z' returned error: r9z-Juju output is not valid json format.Output: )�cmdZexec_primary_cmd�	Exceptionr:�json�loadsZJSONDecodeError)rrZmodel_optionZ
format_optionZ
status_cmd�resZjuju_json_outputrrrrr;�s
zjuju._execute_juju_statuscCsNt�}xB|D]:}x4t||�j�D]"\}}tj||�r |j|p>g�q WqW|S)zFilter with regex match.)�set�getattrrr6�match�update)r�key�patterns�
model_infor�pattern�param�valuerrr�_filter_by_pattern�s
zjuju._filter_by_patterncCsJt�}x>|D]6}x0t||�j�D]\}}||kr |j|p:g�q WqW|S)zFilter with fixed match.)rErFrrH)rrIrJrKrrLrMrNrrr�_filter_by_fixed�s
zjuju._filter_by_fixedcCsdS)z'Dynamically change transport to 'juju'.r/r)rrrr�set_transport_type�szjuju.set_transport_typecCs�t|jd��}t|jd��}t|jd��}t|jd��}|||d�}t|j��r\|r\gS|sfdg}t�}x\|D]T}|j|�}xD|j�D]8\}	}
|	dkr�|j|	|
|�}n|j|	|
|�}|j	|�q�WqrWt
|�S)z+Get the machine numbers from `juju status`.r3r
rr)r
rrr0)rZ
get_option�any�valuesrEr=rrOrPrH�list)rr3r
rr�filtersrZmodelrKrIZresourceZ_nodesrrr�	get_nodes�s$

zjuju.get_nodesN)r
r0r1)rr0r2)r3r0r4)rr0r5)r)r*r+r,r@Zcluster_nameZoption_listr:r=r;rOrPrQrVrrrrr/os 		r/)N)rrBr6Zsos.collector.clustersrrr.r/rrrr�<module>s
V

Youez - 2016 - github.com/yon3zu
LinuXploit