+
    i!  c                   sh    ^ RI t ^ RIt^ RIt^ RIHt ^ RIHt ^ RIHt R	R ltR t	 ! R R]4      t
R# )
i    N)Cluster)sos_parse_versionsos_get_command_outputc                s|    V '       g   . # V P                  R4       Uu. uF  qP                  4       NK  	  up# u upi )zParse comma separated string.Z,)ZsplitZstrip)ZstringsZstring   & @/usr/lib/python3.14/site-packages/sos/collector/clusters/juju.py_parse_option_stringr      s1    	)0s);<);vLLN);<<<s   9c                s&     ! R R4      pV! V 4      # )a:  Helper 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                   s<   a  ] tR t^%t o RtR tR tR tR tRt	V t
R# )_get_index.<locals>.IndexzIndex 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                sr    Wn         / V n        / V n        / V n        \        P
                  ! R 4      V n        R# )ZsosN)
model_nameappsunitsmachinesloggingZ	getLoggerui_log)selfr      &&r   __init__Z"_get_index.<locals>.Index.__init__.   s.    #-ODIDJDM!++E2DK    c                sR   VR,          P                  4        F  w  r#. pVP                  R/ 4      pVP                  4        FP  w  rgVR,          pV P                   RV 2p	V	.V P                  V&   V	.V P                  V&   VP                  V	4       KR  	  W@P                  V&   K  	  R# )zAdds principal units to index.applicationsr
   machine:N)itemsgetr   r
   r   Zappendr	   )
r   juju_statusappapp_infonodesr
   Zunit	unit_infor   nodes
   &&        r   add_principalsZ(_get_index.<locals>.Index.add_principals5   s    !,^!<!B!B!D Wb1',{{}OD'	2G"oo.ay9D(,vDJJt$.2VDMM'*LL& (5 "'		# "Er   c                s   VR,          P                  4        EFo  w  r#VP                  R. 4      pV EFP  pV P                  P                  V4      '       g"   V P                  P	                  RV R24       KF  V P                  V,          P                  V P                  V,          4       RVR,          V,          9  d"   V P                  P	                  RV R24       K  VR,          V,          R,          pVP                  4        Fv  w  rxV P                   RVR,           2p	VP                  R	/ 4      P                  4        F5  w  rV
P                  VR
,           4      '       g   K%  V	.V P                  V
&   K7  	  Kx  	  EKS  	  EKr  	  R# )zcAdd subordinates to index.

Since subordinates does not have units they need to be
manually added.
r   zsubordinate-tozPrincipal charm z is missingr
   z is missing unitsr   r   ZsubordinatesZ/N)	r   r   r	   r   ZwarningZextendr   Z
startswithr
   )r   r   r   r   Zsubordinate_toZparentr
   Z_r   r   Zsub_keys   &&         r   add_subordinatesZ*_get_index.<locals>.Index.add_subordinatesC   sU    "-^!<!B!B!D!).>!C,F99==00++.vhkB !IIcN))$))F*;< k.&A&&II++.vh6GH !'7?HE(-"&//!2!Ii4H3IJ*3--*B+%'+"JG  '11#)<<7;f

7 3	+" )6# - "Er   c                s    VR,          P                  4        F$  pV P                   RV 2pV.V P                  V&   K&  	  R# )z_Add machines to index.

If model does not have any applications it needs to be
manually added.
r   r   N)Zkeysr   r   )r   r   r   r      &&  r   add_machinesZ&_get_index.<locals>.Index.add_machinesd   sA     'z2779//*!G95*.g& :r   )r	   r   r   r   r
   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r    __static_attributes____classdictcell__Z__classdict__   @r   Indexr   %   s$     		3	'	=B	0 	0r   r*    )r   r*   r   r   
_get_indexr,      s    G0 G0R r   c                   sd   a  ] tR t^qt o RtR tRt. ROtR tR t	R t
R tR tR tR	 tR
 tRtV tR# )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"

zJuju Managed Cloudsc                sT    \         P                  ! RRV^ \         P                  R7      # )z#Remove leading characters before {.z(^[^{]*)(.*)z\2)ZcountZflags)reZsubZ	MULTILINE)r   outputr   r   _cleanup_juju_outputZjuju._cleanup_juju_output   s"    vvUF!2<<
 	
r   c                s    V P                  V4      p\        VR7      pVP                  V4       VP                  V4       VP	                  V4       V# )zParse 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    )r   r   r   Zindexr   r   _get_model_infoZjuju._get_model_info   sM     //
;j1[){+;'r   c                s*    \        R4      pVR,          # )zGrab the version of jujuzjuju versionr/   r   )r   resr   r   _get_juju_versionZjuju._get_juju_version   s    $^48}r   c                s   V'       d   R V 2MRpRpV P                  4       p\        V4      \        R4      8  d
   VR,          pV P                   RV RV 2pV P                  V4      pVR,          ^ 8X  g   \	        RV R	VR,           24      hV P                  VR
,          4      pRp\        P                  ! V4      pV# )z-m  z--format jsonZ3z --no-colorz status Z ZstatusZ'z' returned error: r/   N)r4   r   cmdZexec_primary_cmdZ	Exceptionr0   jsonZloads)	r   r   Zmodel_optionZformat_optionZjuju_versionZ
status_cmdr3   Zjuju_json_outputr   s	   &&       r   r1   Zjuju._execute_juju_status   s    -7ZL)R'--/\*->s-CC]*Mz,qH
##J/8}!a
|+=c(m_MNN44c(mEjj!12r   c                s    \        4       pV F^  p\        W14      P                  4        F>  w  rg\        P                  ! WV4      '       g   K#  TP                  T;'       g    . 4       K@  	  K`  	  V# )zFilter with regex match.)setgetattrr   r.   Zmatchupdater   keyZpatterns
model_infor   ZpatternZparamZvalue   &&&&    r   _filter_by_patternZjuju._filter_by_pattern   sV    G '
 8 > > @88G++LL"- !A   r   c                s    \        4       pV FH  p\        W14      P                  4        F(  w  rgWV8X  g   K  TP                  T;'       g    . 4       K*  	  KJ  	  V# )zFilter with fixed match.)r8   r9   r   r:   r;   r>   r   _filter_by_fixedZjuju._filter_by_fixed   sM    G '
 8 > > @#LL"- !A   r   c                s    R# )z'Dynamically change transport to 'juju'.r-   r+   )r   s   &r   set_transport_typeZjuju.set_transport_type   s    r   c                sT   \        V P                  R4      4      p\        V P                  R4      4      p\        V P                  R4      4      p\        V P                  R4      4      pRVRVRV/p\        VP                  4       4      '       g   V'       g   . # V'       g   R.p\	        4       pV Fj  pV P                  V4      pVP                  4        FB  w  rV	R8X  d   V P                  WV4      pMV P                  WV4      pVP                  V4       KD  	  Kl  	  \        V4      # )z+Get the machine numbers from `juju status`.modelsr	   r
   r   r5   )r   Z
get_optionZanyZvaluesr8   r2   r   r?   r@   r:   Zlist)r   rB   r	   r
   r   Zfiltersr   Zmodelr=   r<   ZresourceZ_nodess   &           r   	get_nodesZjuju.get_nodes   s    %dooh&?@#DOOF$;<$T__W%=>'
(CD4%XF 7>>#$$VITFE--e4J!(&=!44SJOF!223*MFV$ "1  E{r   r+   N))r	   r5   z1Filter node list by apps (comma separated regex).)r
   r5   z3Filter node list by units (comma separated string).)rB   r5   z4Filter node list by models (comma separated string).)r   r5   z6Filter node list by machines (comma separated string).)r!   r"   r#   r$   r%   r6   Zcluster_nameZoption_listr0   r2   r4   r1   r?   r@   rA   rC   r&   r'   r(   r)   r   r-   r-   q   sJ      C(L	K

  r   r-   )N)r   r7   r.   Zsos.collector.clustersr    Zsos.utilitiesr   r   r   r,   r-   r+   r   r   <module>rD      s3      	 * + 0=Slx7 xr   