
    Ii                         S SK Jr  S SKrS SKrS SKrSSKJr  SSK7  SSKJ	r	  SSK
7  SSKJr  SSK7  SSKJr  \" 5       rS	 rS
 r\S4S jr " S S5      rg)    )absolute_importN   )util)*)cur_context)kind_matches)selectorc                    [        U [        5      (       a#  [        U R                  R	                  5       5      $ [        U [
        5      (       a  [        U R	                  5       5      $ [        U [        5      (       a'  / nU  H  nUR                  [        U5      5        M     U$ [        U [        5      (       a  U $ [        SR                  [        U 5      5      5      e)a1  
Converts objects into their python primitive form. e.g.
  - APIObject or Model -> dict
  - list<APIObject|Model> -> list<dict>
  If the object is already a primitive, it will be returned without error.
:param obj: The object to transform into its primitive form
:return: The primitive form of the object
z&Unknown how to transform into dict: {})
isinstance	APIObject_obj_to_primitivemodel
_primitiveModellistappenddict
ValueErrorformattype)objles      @/venv/lib/python3.13/site-packages/openshift_client/apiobject.pyr   r      s     #y!! !5!5!788#u !122#tAHH&q)* #t

=DDT#YO
PP    c                     [        U [        [        45      (       a  U $ [        U [        5      (       a  [        U 5      $ [        U 5      $ )z
:param obj: The object to return as a Model
:return: Return the object as a Model. If object is already a Model, just returns it.
)r   r   	ListModelr   )r   s    r   	_as_modelr   /   s>    
 #y)**
#t~ :r   Fc                 ~    U [         L d  U S:X  a  U[        L a  [        U5      eU$ U(       a  U R                  5       n U $ )N )Missing_DEFAULT
ModelErrorlower)valerr_msg
if_missing	lowercases       r   _access_fieldr)   >   s=     g~!W%%	iikJr   c                      \ rS rSrS3S jrS rS4S jrS\4S jrS\4S jr	S\4S	 jr
S
S\4S jrS r\4S jr\4S jr\4S jr\4S jr\4S jrS rS rS5S jrS r\\4S jrS6S jrS6S jrS6S jrS7S jr  S8S jr\R:                  S
S
SSSSS4S jrS9S jrS6S jr S:S  jr!S! r"S;S" jr#S6S# jr$S<S$ jr%S6S% jr&S<S& jr'S=S' jr(S6S( jr)S>S) jr*S* r+S+ r,S, r-S- r.S. r/S?S/ jr0S0 r1S1 r2S2r3g)@r   M   Nc                    Ubr  UR                  5       nUS:X  a  SS0 / S.nOTUR                  S5      (       a  [        R                  U5      nO(SU;   a  [        R
                  " U5      nO[        S5      e[        U5      U l        [        R                  " U(       a  UO	[        5       5      U l        U R                  U R                  R                  5      U R                  l        g )Nr    v1List)
apiVersionkindmetadataitems{
z1Unable to detect markup format (not yaml or json))strip
startswithjsonloadsyaml	safe_loadr   r   r   copyr   context	namespaceproject_name)selfdict_to_modelstring_to_modelr<   s       r   __init__APIObject.__init__O   s    &-335O"$ #'" "	! !++C00 $

? ;( $ ? !TUU =)
 yyGG$(NN4<<3L3L$M!r   c                 6    U R                   R                  5       $ )z
:return: Returns a python dict representation of the APIObject. Changes are not communicated
 back to this APIObject's model.
)r   r   r?   s    r   as_dictAPIObject.as_dictm   s    
 zz$$&&r   c                 v    [         R                  U R                  R                  5       US9R	                  5       $ )z8
:return: Returns a JSON presentation of the APIObject.
indent)r7   dumpsr   r   r5   )r?   rJ   s     r   as_jsonAPIObject.as_jsont   s-     zz$**//1&zAGGIIr   Tc                 @    [        U R                  R                  SX!S9$ )ad  
Return the API object's kind if it possesses one (if you want group information included, use qkind).
If it does not, returns if_missing. When if_missing not specified, throws a ModelError.
:param if_missing: Value to return if kind is not present in Model.
:param lowercase: Whether kind should be returned in lowercase.
:return: The kind or if_missing.
z#Object model does not contain .kindr'   r(   )r)   r   r0   r?   r(   r'   s      r   r0   APIObject.kindz   s"     TZZ__Bzp 	pr   c           	      Z    SR                  U R                  X!S9U R                  SSUS9S9$ )aB  
Return the API object's qualified kind (e.g. kind[.group]). If kind is not defined, returns if_missing.
When if_missing not specified, throws a ModelError.
:param if_missing: Value to return if kind is not present in Model.
:param lowercase: Whether kind should be returned in lowercase.
:return: The kind or if_missing.
z{kind}{group}rO   Tr    )
prefix_dotr'   r(   )r0   group)r   r0   rT   rP   s      r   qkindAPIObject.qkind   s?     %%499
9+`,0JJ$SUajJ,k & m 	mr   c                 @    [        U R                  R                  SX!S9$ )a;  
Return the API object's apiVersion if it possesses one.
If it does not, returns if_missing. When if_missing not specified, throws a ModelError.
:param if_missing: Value to return if apiVesion is not present in Model.
:param lowercase: Whether kind should be returned in lowercase.
:return: The kind or if_missing.
z)Object model does not contain .apiVersionrO   r)   r   r/   rP   s      r   r/   APIObject.apiVersion   s%     TZZ22HU_v 	vr   Fc                     U R                  USS9nUc  U[        L a  [        S5      eU$ SU;  a  gUR                  S5      S   nU(       a  SR	                  U5      $ U$ )a=  
Return the API object's group if it possesses an apiVersion field.
If it does not contain apiVersion field, returns if_missing. When if_missing not specified, throws a ModelError.
If apiVersion is a non-group version, an empty string is returned.
:param prefix_dot: Returns '.[group]' for resources with groups, but '' for those without. Convenience
 for appending to grouped/ungrouped resource names.
:param if_missing: Value to return if apiVesion is not present in Model.
:param lowercase: Whether kind should be returned in lowercase.
:return: The kind or if_missing.
N)r(   r'   z#Unable to find apiVersion in object/r    r   z.{})r/   r"   r#   splitr   )r?   rS   r(   r'   r/   rT   s         r   rT   APIObject.group   so     __yT_J
X% !FGG!! j   %a(<<&&r   c                 6    [        U R                  5       U5      $ )z
apiobj.is_kind('pod')  or  apiobj.is_kind(['pod', 'ds'])
:param test_kind_or_kind_list: A str or list of strings to match
:return: Returns whether this apiobj represents the specified kind or list of kings.
)r   r0   )r?   test_kind_or_kind_lists     r   is_kindAPIObject.is_kind   s     DIIK)?@@r   c                 V    [        U R                  R                  R                  SUSS9$ )z
Return the API object's .metadata.uid if it possesses one.
If it does not, returns if_missing. When if_missing not specified, throws a ModelError.
:param if_missing: Value to return if uid is not present in Model.
:return: The name or if_missing.
z+Object model does not contain .metadata.uidFrO   )r)   r   r1   uidr?   r'   s     r   rc   APIObject.uid   s,     TZZ0044JWa',. 	.r   c                 V    [        U R                  R                  R                  SUSS9$ )a  
Return the API object's .metadata.resourceVersion if it possesses one.
If it does not, returns if_missing. When if_missing not specified, throws a ModelError.
:param if_missing: Value to return if resourceVersion is not present in Model.
:return: The name or if_missing.
z7Object model does not contain .metadata.resourceVersionFrO   )r)   r   r1   resourceVersionrd   s     r   resource_versionAPIObject.resource_version   s,     TZZ00@@Vcm',. 	.r   c                 B    [        U R                  R                  SUSS9$ )z
Return the API object's apiVersion if it possesses one.
If it does not, returns if_missing. When if_missing not specified, throws a ModelError.
:param if_missing: Value to return if apiVersion is not present in Model.
:return: The name or if_missing.
z(Object model does not contain apiVersionFrO   rX   rd   s     r   api_versionAPIObject.api_version   s&     TZZ22GT^',. 	.r   c                 V    [        U R                  R                  R                  SUSS9$ )z
Return the API object's .metadata.name if it possesses one.
If it does not, returns if_missing. When if_missing not specified, throws a ModelError.
:param if_missing: Value to return if name is not present in Model.
:return: The name or if_missing.
z,Object model does not contain .metadata.nameFrO   )r)   r   r1   namerd   s     r   rn   APIObject.name   s,     TZZ0055KXb',. 	.r   c                 V    [        U R                  R                  R                  SUSS9$ )z
Return the API object's namespace if it possesses one.
If it does not, returns if_missing. When if_missing not specified, throws a ModelError.
:param if_missing: Value to return if namespace is not present in Model.
:return: The namespace or if_missing.
z1Object model does not contain .metadata.namespaceTrO   )r)   r   r1   r=   rd   s     r   r=   APIObject.namespace   s,     TZZ00::P]g'+- 	-r   c                     SR                  U R                  SS9U R                  SS9U R                  5       U R	                  5       S9$ )z
This name is not useful programmaticaly against the openshift API. It is useful
only to determine if two apiObjects appear to represent the same resource.
:return: Returns the fully qualified name of the object (ns:apiVersion.kind/name).
z{ns}:{kind}{group}/{name}r    r'   T)rS   )nsrT   r0   rn   )r   r=   rT   r0   rn   rE   s    r   fqnameAPIObject.fqname   sI     +11T^^r^5R8<

d
8S7;yy{7;yy{ 2 4 	4r   c                 J    U R                  5       S-   U R                  5       -   $ )zH
:return: Returns the qualified name of the object (kind[.group]/name).
r[   )rU   rn   rE   s    r   qnameAPIObject.qname  s      zz|c!DIIK//r   c                 *   U R                  5       n[        5       nUR                  / SQ5        [        U5      nUR	                  [        U R                  XU/X@R                  SS9S95        U(       a   UR                  SR                  U5      5        U$ )z
:param verb: The verb to execute
:param auto_raise: If True, any failed action will cause an exception to be raised automatically.
:param cmd_args: An optional list of additional arguments to pass on the command line
:return: The Result
:rtype: Result
)-o=name-f-Nrs   )cmd_args	stdin_objr=   zError during object {})
rF   r   extendResult
add_action	oc_actionr<   r=   fail_ifr   )r?   verb
auto_raiser~   content	base_argsresults          r   _object_def_actionAPIObject._object_def_action  s     ,,.F	/0)DLL$XAV.5[_A`b 	c NN3::4@Ar   c                 F    [        U R                  5       U R                  S9$ )z>
:return: Returns a selector that selects this exact receiver
static_context)r	   rx   r<   rE   s    r   self_selectorAPIObject.self_selector  s     

T\\BBr   c                     U R                  5       R                  5       S:H  nSnU(       a  U[        La  U" U 5      nX44$ U[        La  U" U 5      nX44$ )a  
Returns whether the specified object exists according to the API server.
If a function is supplied, it will be executed if the object exists.
:param on_exists_func: The function to execute if the object exists
:param on_absent_func: The function to execute if the object does not exist
:return: Boolean indicated whether the object exists, followed by return value of function, if present
r   N)r   count_existingr"   )r?   on_exists_funcon_absent_func
does_existrets        r   existsAPIObject.exists$  s`     '')88:a?
X-$T*  8+ &Cr   c                 "    U R                  SUS9$ )z
Creates the modeled object if possible.
:param cmd_args: An optional list of additional arguments to pass on the command line
:return: A Result object
:rtype: Result
creater~   r   r?   r~   s     r   r   APIObject.create7  s     &&x(&CCr   c                 "    U R                  SUS9$ )z
Replaces the modeled object if possible.
:param cmd_args: An optional list of additional arguments to pass on the command line
:return: A Result object
:rtype: Result
replacer   r   r   s     r   r   APIObject.replace@  s     &&y8&DDr   c                 B   ^ ^ T R                  UU 4S jUU 4S jS9u  p#U$ )z
Replaces the modeled object if it exists; creates otherwise.
:param cmd_args: An optional list of additional arguments to pass on the command line
:return: A Result object
:rtype: Result
c                  "   > TR                  T S9$ Nr   )r   r~   r?   s   r   <lambda>-APIObject.create_or_replace.<locals>.<lambda>P  s    t||X|7Vr   c                  "   > TR                  T S9$ r   )r   r   s   r   r   r   Q  s    t{{H{7Ur   )r   r   )r   )r?   r~   _actions   ``  r   create_or_replaceAPIObject.create_or_replaceI  s(     KK/V/U   W	 r   c                 .   [        S5      nUR                  [        U R                  SU R	                  5       /U R                  SS9S95        U(       a  UR                  S5        UR                  5       S-   UR                  5       -   R                  5       $ )z
:param auto_raise: If True, returns empty string instead of throwing an exception
if describe results in an error.
:return: Returns a string with the oc describe output of an object.
describeNrs   r~   r=   zError describing objectr4   )
r   r   r   r<   rx   r=   r   outerrr5   )r?   r   rs      r   r   APIObject.describeU  sy     :	Yt||Z4::<.)-4)HJ 	K II/0$(//11r   c                    0 nS n	[        5       n
U(       a  U
R                  S5        U(       a   U
R                  SR                  U5      5        U(       a   U
R                  SR                  U5      5        U(       a  U
R                  S5        U
R                  SR                  U5      5        / n[        U R	                  5       S5      (       a  UR                  U 5        GO&[        U R	                  5       SS	/5      (       a"  UR                  U R                  S5      5        GO[        U R	                  5       S
5      (       a:  U R                  S5       H#  nUR                  UR                  S5      5        M%     GO[        U R	                  5       S5      (       a:  U R                  S5       H#  nUR                  UR                  S5      5        M%     GO1[        U R	                  5       SS/5      (       a!  UR                  U R                  S5      5        O[        U R	                  5       SS/5      (       aK  [        U R                  SXU R                  5       /U R                  SS9S9nU	" XR                  5       U5        OU(       a|  UR                  U R                  S5      5        U(       dK  [        U R                  SXU R                  5       /U R                  SS9S9nU	" XR                  5       U5        O
[        5       $ U H  nUR                  R                  R                   H  n[        U R                  SXUR                  5       SUR                   SR                  UR                  5       5      /SS9nSR                  U R                  5       UR                  5       UR                   5      nU	" UUU5        M     M     U$ )a  
Attempts to collect logs from running pods associated with this resource. Supports
daemonset, statefulset, deploymentconfig, deployment, replicationcontroller, replicationset,
buildconfig, build, pod.

If a resource is associated with many pods, all pods owned by that resource will be individually
scraped for logs. For example, if a daemonset is specified, an invocation of `oc logs ...` will be
made for each pod associated with that daemonset -- this is different from the output of
`oc logs ds/name`.

If try_longshots==True, logs can also be collected to for any object which directly
owns pods or responds successfully with "oc logs kind/name".

Since pods can be pending or otherwise unable to deliver logs, if an error is encountered during
an 'oc logs' invocation, the stderr will be considered the 'logs' of the object. In other words, oc
returning an error will not terminate this function.

:param cmd_args: An optional list of additional arguments to pass on the command line

:param try_longshots: If True, an attempt we will be made to collect logs from resources which the library does
not natively understand to possess logs. If False and the object is not recognized, an empty dict will be
returned.

:return: Returns a dict of {<fully-qualified-name> -> <log output>}. The fully qualified name will be
a human readable, unique identifier containing namespace, object, and container-name (when applicable).
c                     UR                   nUR                  S:w  a)  USR                  UR                  UR                  5      -  nUR	                  5       R                  SS5      nX0U'   g )Nr   z.
>>>>Error during log collection rc={}<<<<
{}
z
r4   )r   statusr   r   r5   r   )
collection	entry_keyr   entrys       r   	add_entry!APIObject.logs.<locals>.add_entry  s]    JJE}}!MTTU[UbUbdjdndnooKKM))&$7E$)y!r   -pz
--since={}z--limit-bytes={}z--timestampsz	--tail={}poddsstatefulset
deploymentrsdcrcbcbuildlogsNrs   r   z-cz--namespace={}T)r~   no_namespacez
{}->{}({}))r   r   r   r   r0   r   	get_ownedr   r<   rx   r=   ru   r   r   spec
containersrn   )r?   
timestampsprevioussincelimit_bytestailr~   try_longshotslog_aggregationr   r   pod_listr   r   r   r   	containerkeys                     r   r   APIObject.logsd  s   8 	* F	T"\0078/66{CD^,++D12		U++OOD!$))+m'<==OODNN512$))+|44nnT*U 34 + $))+t,,nnT*U 34 + $))+d|44OODNN512$))+g77t||VyTXT^T^T`>a)-4)HJFo{{}f= u 56&t||Vy\`\f\f\hFi1541PRFo{{}fE  6MC YY^^66	"4<<-6#))+tU^UcUc-=-D-DS]]_-U-W04% #))$++-innU/37 7  r   c	                 R    [         R                  " UU R                  X#XEXhUS95        g)a  
Pretty prints logs from selected objects to an output stream (see logs() method).
:param stream: Output stream to send pretty printed report (defaults to sys.stderr)..
:param cmd_args: An optional list of additional arguments to pass on the command line
:return: n/a
)r   r   r   r   r   r   r~   N)r   
print_logsr   )	r?   streamr   r   r   r   r   r~   r   s	            r   r   APIObject.print_logs  s0     			ZRW'+S[ " ]	^r   c           
         [        S5      nSn[        [        [        US-   5      5      5       H  nU" U 40 UD6nUSL a    XV4$ [	        U R
                  SSSU/U R                  SS9U R                  5       US:H  S	9n	UR                  U	5        U	R                  S:X  a  S
n  XV4$ US:w  d  M}  U R                  5         M     XV4$ )a)  
Calls the modifier_func with self. The function should modify the model of the apiobj argument
and return True if it wants this method to try to apply the change via the API. For robust
implementations, a non-zero number of retries is recommended.

:param modifier_func: Called before each attempt with a self. The associated model will be refreshed before
    each call if necessary. If the function finds changes it wants to make to the model, it should
    make them directly and return True. If it does not want to make changes, it should return False.
:param cmd_args: An optional list of additional arguments to pass on the command line
:param retries: The number of times to retry. A value of 0 means only one attempt will be made.
:param kwargs: keyword arguments passed directly into modifier_func
:return: A Result object containing a record of all attempts AND a boolean. The boolean indicates
True if a change was applied to a resource (i.e. it will be False if modifier_func suggested no
change was necessary by returning False).
:rtype: Result, bool
applyFr   r|   r}   Nrs   r   )r~   r=   r   last_attemptT)r   reversedr   ranger   r<   r=   rF   r   r   refresh)
r?   modifier_funcretriesr~   kwargsr   applied_changeattemptdo_applyapply_actions
             r   modify_and_applyAPIObject.modify_and_apply  s    " 7OU7Q;%7 89G$T4V4H 5      %T\\7dCQYEZ/3~~~/NZ^ZfZfZh3:a<BL LL&""a'!%   	 !|) :,   r   c                 .    U R                  S SUS9u  p#U$ )ar  
Applies any changes which have been made to the underlying model to the API.
You should use modify_and_apply for robust code if the targeted API object may have been updated
between the time this APIObject was created and when you call apply.
:param cmd_args: An optional list of additional arguments to pass on the command line
:return: A Result object
:rtype: Result
c                     g)NT )r   s    r   r   !APIObject.apply.<locals>.<lambda>  s    tr   r   )r   r~   )r   )r?   r~   r   r   s       r   r   APIObject.apply  s"     $$^Q$Rr   c                     [        S5      nS/nUSL a  UR                  S5        UR                  [        U R                  SU R                  5       XB/U R                  SS9S95        UR                  S5        U$ )	z
:param ignore_not_found: If true, no error will be raised if the object cannot be found.
:param cmd_args: An optional list of additional arguments to pass on the command line
:return:
deleter{   T--ignore-not-foundNrs   r   zError deleting object)r   r   r   r   r<   rx   r=   r   )r?   ignore_not_foundr~   r   r   s        r   r   APIObject.delete  sy     8K	t#12	Yt||X)-y(K)-4)HJ 	K 	
		)*r   c           
         [        S5      nS/n[        [        [        S5      5      5       H  n[	        U R
                  SU R                  5       U/U R                  SS9US:H  S9nUR                  U5        UR                  S:X  a/  [        [        R                  UR                  5      5      U l          O[        R!                  S	5        M     UR#                  S
5        U $ )z]
Refreshes this APIObject's cache of the object it represents from the server.
:return: self
r   -o=json	   getNrs   r   r~   r=   r   r   zError refreshing object content)r   r   r   r   r   r<   rx   r=   r   r   r   r7   r8   r   r   timesleepr   )r?   r   r   r   r_actions        r   r   APIObject.refresh"  s    
 9K	U1X/G u+/::<*C+/>>T>+J/6!|>H
 LL"!#"4::hll#;<
JJqM 0 	
		34r   c           
      |   [        S5      nSS/n[        [        [        S5      5      5       H  n[	        U R
                  SU R                  5       U/U R                  SS9US:H  S	9nUR                  U5        UR                  S:X  at  [        UR                  S
9nUR                  S5      (       aG  UR                  5       (       d2  U(       a    g[        SR                  U R!                  5       5      U5      eUs  $ ["        R%                  S5        M     [        SR                  U R!                  5       5      U5      e)a  
Uses the receiver's fully qualified name to query the server for an up-to-date copy of the object.
:return: A new copy of APIObject with up-to-date content. If not found, ignore_not_found will
cause None to be returned; otherwise, an exception will be thrown.
currentr   r   r   r   Nrs   r   r   rA   r   z7Unable to retrieve current copy of {}; resource missingr   z1Unable to retrieve current copy of {}; api errors)r   r   r   r   r   r<   rx   r=   r   r   r   r   r`   elementsOpenShiftPythonExceptionr   ru   r   r   )r?   r   r   r   r   r   
new_apiobjs          r   r   APIObject.current:  s"    9 45	U1X/G u+/::<*C+/>>T>+J/6!|>H
 LL"!#&x||D
%%f--j6I6I6K6K'#23l3s3stxtt  uB  4C  EF  G  G!!JJqM! 0$ ''Z'a'abfbmbmbo'p'(* 	*r   c                 b    U R                   R                  R                  U   nU[        La  U$ U$ )z
:param name: The name of the label
:param if_missing: Value to return if the label is not present (defaults to None).
:return: Returns the value of the specified label or the specified default if not present.
)r   r1   labelsr!   r?   rn   r'   vs       r   	get_labelAPIObject.get_labelX  s1     JJ&&t,GHr   c                 p    U R                  5       R                  XUS9nU(       a  U R                  5         U$ )a  "
Sends a request to the server to label this API object.
:param labels: A dictionary of labels to apply to the object. If value is None, label will be removed.
:param overwrite: Whether to pass the --overwrite argument.
:param cmd_args: An optional list of additional arguments to pass on the command line
:param refresh_model: Whether to refresh apiobject model after label is applied.
:return: Result
r   )r   labelr   )r?   r  	overwriter~   refresh_modelr   s         r   r  APIObject.labeld  s3     ##%++F+QLLNr   c                 b    U R                   R                  R                  U   nU[        La  U$ U$ )z
:param name: The name of the annotation
:param if_missing: Value to return if the annotation is not present (defaults to None).
:return: Returns the value of the specified annotation or the specified default if not present.
)r   r1   annotationsr!   r  s       r   get_annotationAPIObject.get_annotations  s1     JJ++D1GHr   c                 p    U R                  5       R                  XUS9nU(       a  U R                  5         U$ )a  "
Sends a request to the server to annotate this API object
:param annotations: A dictionary of annotations to apply to the object. If value is None, annotation will be removed.
:param overwrite: Whether to pass the --overwrite argument.
:param cmd_args: An optional list of additional arguments to pass on the command line
:param refresh_model: Whether to refresh apiobject model after label is applied.
:return: Result
)r  r  r~   )r   annotater   )r?   r  r  r~   r  r   s         r   r  APIObject.annotate  s4     ##%..;fn.oLLNr   c                 n   [        S5      n[        5       nUR                  SU-   5        UR                  U R                  5       5        [        R                  US S9nUR                  SU-   5        UR                  [        U R                  SXS/U R                  S S9S95        UR                  S5        U$ )Npatchz--type=rI   z--patch=rs   r   zError running patch on objects)r   r   r   rx   r7   rK   r   r   r<   r=   r   )r?   
patch_dictstrategyr~   r   r   	patch_defs          r   r  APIObject.patch  s    7OF	X-.&JJz$J7	i/0	Yt||W	?T)-4)HJ 	K 	
		23r   c                    U R                  SS9nUR                  S5      (       a  USS nOU /$ / nU R                  S    HF  nUR                  5       nU(       a  X6S'   Ub	  U" U5      nO[	        U5      nUR                  U5        MH     U$ )a  
:param cls A custom subclass of APIObject to return in place of APIObjects
:return: Returns a python list of APIObjects. If receiver is an OpenShift 'List', each element will be
added to the returned list. If the receiver is not of kind List, the [self] will be returned.
F)r(   r.   Nr2   r0   )r0   endswithr   r   r   r   )r?   cls	self_kind	item_kindr   r   dr   s           r   r   APIObject.elements  s     III.	f%%!I 6MG$AA
 %&	!flHHSM %  r   c           
         Uc  0 nU R                   R                  5       n[        5       nUR                  S5        UR	                  5        H-  u  pVUR                  S5        UR                  US-   U-   5        M/     [        S5      nUR                  [        U R                  SSSXB/US95        UR                  S5        [        UR                  5       S	9R                  5       $ )
a3  
Assumes this APIObject is a template and runs oc process against it.
:param parameters: An optional dict of parameters to supply the process command
:param cmd_args: An optional list of additional arguments to pass on the command line
:return: A list of apiobjects resulting from processing this template.
r   r   =processr|   r}   )r~   r   zError processing templater   )r   r   r   r   r2   r   r   r   r<   r   r   r   r   )r?   
parametersr~   templater   kr  r   s           r   r&  APIObject.process  s     J::((*F	#$$&DAT"QWq[) '
 9	Yt||Y$YAamuvw			-.1::<<r   c                 :   UR                   R                  R                  [        L a  g UR                   R                  R                   HN  n[	        U R                  5       UR
                  5      (       d  M.  U R                  5       UR                  :X  d  MN    g   gNFT)r   r1   ownerReferencesr!   r   r0   rn   r?   apiobjrefs      r   do_i_ownAPIObject.do_i_own  sp     <<  00G;		 <<((88CDIIK22tyy{chh7N 9 r   c                    UR                   R                  nU[        L a  g [        U R	                  5       UR                  5      (       a=  U R                  5       UR
                  :X  a  U R                  5       UR                  :X  a  ggr,  )r   involvedObjectr!   r   r0   rn   r=   r.  s      r   am_i_involvedAPIObject.am_i_involved  sg     ll))'>	 		SXX..499;#((3Jt~~O_cfcpcpOpr   c                 b   ^ ^ / mUU 4S jn[        UT R                  S9R                  U5        T$ )z
Returns a list of apiobjects which are declare an object of this kind/name
as their owner.
:param find_kind: The kind to check for ownerReferences
:return: A (potentially empty) list of APIObjects owned by this object
c                 V   > TR                  U 5      (       a  TR                  U 5        g g N)r1  r   )r/  ownedr?   s    r   check_owned_by_me.APIObject.get_owned.<locals>.check_owned_by_me  s#    }}V$$V$ %r   r   )r	   r<   for_each)r?   	find_kindr;  r:  s   `  @r   r   APIObject.get_owned
  s0     	% 	4<<8AABSTr   c                    ^ ^ [        T R                  5       SS/5      (       a  [        S5      R                  5       $ / mUU 4S jn[        ST R                  S9R                  U5        T$ )z
Returns a list of apiobjects events which indicate this object as
their involvedObject. This can be an expensive if there are a large
number of events to search.
:return: A (potentially empty) list of event APIObjects
projectr=   eventsc                 V   > TR                  U 5      (       a  TR                  U 5        g g r9  )r5  r   )r/  involvedr?   s    r   check_if_involved/APIObject.get_events.<locals>.check_if_involved+  s%    !!&))' *r   r   )r   r0   r	   objectsr<   r=  )r?   rE  rD  s   ` @r   
get_eventsAPIObject.get_events  s\     		i%=>>H%--//	( 	$,,7@@ARSr   c                 `   0 nU R                  5       nU R                  5       n[        US5      (       a,  [        US5      (       a  [        SSSU R                  5       0S9$ UR	                  S5      (       a  XBS'   OUR	                  S5      (       a  XBS'   OUR	                  S5      (       a  XBS'   OkUR	                  S	5      (       a  XBS
'   OPUR	                  S5      (       a  XBS'   O5UR	                  S5      (       a  XBS'   O[        SR                  X5      5      e[        XU R                  S9$ )a  
Returns a dynamic selector which all of a the specified kind of object which is related to this
object.
For example:
- if this object is a node, and find_kind=='pod', it will find all pods associated with the node.
- if this object is a template and find_kind=='buildconfig', it will select buildconfigs created by
this template.
- if this object is a buildconfig and find_kind='builds', builds created by this buildconfig will be selected.

:return: A selector which selects objects of kind find_kind which are related to this object.
noder   Tzspec.nodeName)all_namespacesfield_selectorsr(  deploymentconfigr   buildconfigzopenshift.io/build-config.namer   z"statefulset.kubernetes.io/pod-namejobzjob-namez7Unknown how to find {} resources to related to kind: {})r  r   )r0   rn   r   r	   r6   r  r   r<   )r?   r>  r  	this_kindrn   s        r   relatedAPIObject.related3  s)    IIK	yy{ 	6**|Iu/M/ME+/-<diik,JL L 
++!%:!!"455)-%&!!,//#'< !!-007;34!!-00;?78!!%((!%:*IPPQZfh h 	NNr   c                    Uc  / n/ nU(       a  UR                  S5        U(       a   UR                  SR                  U5      5        [        S5      nUR                  [	        U R
                  SXPR                  5       SU/X R                  SS9S95        U(       aP  UR                  SR                  U R                  5       US	   UR                  5       UR                  5       5      5        U$ )
a  
Performs an oc exec operation on a pod object - passing all of the arguments.
:param cmd_to_exec: An array containing all elements of the command to execute.
:param stdin: Any input that should be streamed into the executed process.
:param container_name: If the pod has more than one container, specifies the container in which to exec.
:param auto_raise: Raise an exception if the command returns a non-zero status.
:return: A result object
Nz-iz--container={}execz--rs   )r~   	stdin_strr=   z'Error running {} exec on {} [rc={}]: {}r   )r   r   r   r   r   r<   rx   r=   r   r   r   )r?   cmd_to_execstdincontainer_namer   oc_argsr   s          r   executeAPIObject.execute]  s     KNN4 NN+22>BC6N	dllFgzz|TS^5_ %41PR	S II9@@{[\~_`_g_g_iklkpkpkrsur   c                     U R                   R                  R                  U R                   R                  U R                  S.$ )z
Custom serializer for pickle module.
The pickle module implements binary protocols for serializing and de-serializing a Python object structure.
More info here: https://docs.python.org/3/library/pickle.html#object.__getstate__
)rn   r0   r<   )r   r1   rn   r0   r<   rE   s    r   __getstate__APIObject.__getstate__{  s3     JJ'',,JJOO||
 	
r   c                     US      [        US    SUS    35      R                  5       nU R                  US9  SSS5        g! , (       d  f       g= f)z
Custom de-serializing for pickle module.
The pickle module implements binary protocols for serializing and de-serializing a Python object structure.
More info here: https://docs.python.org/3/library/pickle.html#object.__setstate__
r<   r0   r[   rn   r   N)r	   object_jsonrB   )r?   stater   s      r   __setstate__APIObject.__setstate__  sL     9vqv@AMMOFMM&M1 s   4A
A)r<   r   )NNN)   )TNr9  )T)FFNNr   NT)   N)FN)F)TNT)	strategicN)NN)NNNT)4__name__
__module____qualname____firstlineno__rB   rF   rL   r"   r0   rU   r/   rT   r`   rc   rh   rk   rn   r=   ru   rx   r   r   r   r   r   r   r   r   sysstderrr   r   r   r   r   r   r  r  r  r  r  r   r&  r1  r5  r   rH  rR  r[  r^  rc  __static_attributes__r   r   r   r   r   M   sQ   N<'J "h 	p #x 	m $(H 	v  % 8A & 	. +3 	. &. 	. ' 	. $, 	-
40,C %-X &DE
2 fjeN !$

uuTXfjqs 
^*!X
&0*<

  @=4.4&,(OT<

2r   r   )
__future__r   r;   rl  r9   r    r   r   r<   r   r   namingr   r   r	   objectr"   r   r   r)   r   r   r   r   <module>rr     sP    &  
          8Q8 ,4u B2 B2r   