a ì)g¾%ã@s–ddlmZmZmZeZddlmZmZddl m Z ddl m Z ddlmZddlmZmZddlmZddlmZeƒZdd d „ZGd d„dƒZdS)é)Úabsolute_importÚdivisionÚprint_function)ÚMappingÚMutableMapping)Úchain)Ú constants)Ú AnsibleError)Ú to_nativeÚto_text)ÚDisplay)Ú combine_varsÚ_FcCsœd}|rŠtj |¡}|rŠdtt|ƒƒt|ƒf}tjdvs>|rntj ||¡}|sŠtjdksŠt d|¡d}ntjdkrŠt d|¡d }|r˜t  |¡|S) NÚz,invalid character(s) "%s" in group name (%s))ÚneverÚignoreZsilentlyz Replacing zaInvalid characters were found in group names and automatically replaced, use -vvvv to see detailsrzNot replacing %szWInvalid characters were found in group names but not replaced, use -vvvv to see details) ÚCZINVALID_VARIABLE_NAMESÚfindallr ÚsetZTRANSFORM_INVALID_GROUP_CHARSÚsubÚdisplayZvvvvZwarning)ÚnameZreplacerÚforceZsilentÚwarnZ invalid_charsÚmsg©rú;/usr/lib/python3.9/site-packages/ansible/inventory/group.pyÚto_safe_group_name s    rc@sÈeZdZdZd0dd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z d1dd„Z dd„Z dd„Z edd„ƒZdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„ZdS)2ÚGroupz a group of ansible hosts NcCs>d|_t|ƒ|_g|_d|_i|_g|_g|_d|_d|_ dS)Nré) ÚdepthrrÚhostsÚ_hostsÚvarsÚ child_groupsÚ parent_groupsÚ _hosts_cacheÚpriority)ÚselfrrrrÚ__init__=s zGroup.__init__cCs| ¡S©N©Úget_name©r(rrrÚ__repr__IszGroup.__repr__cCs| ¡Sr*r+r-rrrÚ__str__Lsz Group.__str__cCs| ¡Sr*)Ú serializer-rrrÚ __getstate__OszGroup.__getstate__cCs | |¡Sr*)Ú deserialize)r(ÚdatarrrÚ __setstate__RszGroup.__setstate__cCsFg}|jD]}| | ¡¡q d|_t|j|j ¡||j|j d}|S)N)rr#r%r r!) r%Úappendr0r"Údictrr#Úcopyr r!)r(r%ÚparentÚresultrrrr0Us ûzGroup.serializecCs|| ¡| d¡|_| dtƒ¡|_| dd¡|_| dg¡|_d|_| dg¡}|D] }tƒ}|  |¡|j   |¡qVdS)Nrr#r rr!r%) r)Úgetrr6r#r r!r"rr2r%r5)r(r3r%Z parent_dataÚgrrrr2fs   zGroup.deserializeFc s¶tgƒ}tt|ˆƒƒ}|r$| |¡|rF|r2|gng}| t|ˆƒ¡|rª| |¡tgƒ}t ‡fdd„|Dƒ¡D]$}| |¡|rt||vrt| |¡qt| |¡|}qF|r²|S|S)a‚ Given `rel` that is an iterable property of Group, consitituting a directed acyclic graph among all groups, Returns a set of all groups in full tree A B C | / | / | / | / D -> E | / vertical connections | / are directed upward F Called on F, returns set of (A, B, C, D, E) c3s|]}t|ˆƒVqdSr*)Úgetattr©Ú.0r;©ÚrelrrÚ Žóz+Group._walk_relationship..) rr<ÚaddÚextendÚupdaterÚ from_iterabler5Údifference_update) r(r@Ú include_selfÚpreserve_orderingÚseenÚ unprocessedZorderedZnew_unprocessedZnew_itemrr?rÚ_walk_relationshipts(     zGroup._walk_relationshipcCs | d¡S)Nr%©rLr-rrrÚ get_ancestors›szGroup.get_ancestorscKs|jdi|¤ŽS)Nr$)r$rM)r(ÚkwargsrrrÚget_descendantsžszGroup.get_descendantscCs|jdurt|jƒ|_|jSr*)r"rr!r-rrrÚ host_names¡s  zGroup.host_namescCs|jSr*©rr-rrrr,§szGroup.get_namecCsÜd}||krtdƒ‚||jvrØ| ¡}| ¡}||vrRtdt|jƒt|jƒfƒ‚| |¡| |¡d}|j |¡t |j d|j gƒ|_ |  ¡|jdd„|j DƒvrÐ|j  |¡|  ¡D]}|j|dq¾| ¡|S) NFzcan't add group to itselfzGAdding group '%s' as child to '%s' creates a recursive dependency loop.TrcSsg|] }|j‘qSrrRr=rrrÚ ÅrBz)Group.add_child_group..)Z additions)Ú Exceptionr$rNr r rrCrGr5Úmaxr Ú_check_children_depthr%Ú get_hostsZpopulate_ancestorsÚclear_hosts_cache)r(ÚgroupÚaddedZstart_ancestorsZ new_ancestorsÚhrrrÚadd_child_groupªs(      zGroup.add_child_groupcCs’|j}|j}tgƒ}t|jƒ}|rŽ| |¡|d7}| ¡}tgƒ}|D] }|j|krH||_| |j¡qH||t|ƒkrtdt|jƒƒ‚qdS)Nrz5The group named '%s' has a recursive dependency loop.) r rr$rEr7Úlenr r r)r(r Z start_depthrJrKZ to_processr;rrrrVÍs   zGroup._check_children_depthcCsDd}|j|jvr@|j |¡|j |j¡| |¡| ¡d}|S©NFT)rrQr!r5r"rCÚ add_grouprX)r(ÚhostrZrrrÚadd_hostàs   zGroup.add_hostcCsDd}|j|jvr@|j |¡|j |j¡| |¡| ¡d}|Sr^)rrQr!Úremover"Z remove_grouprX)r(r`ZremovedrrrÚ remove_hostês   zGroup.remove_hostcCs^|dkr| t|ƒ¡nB||jvrPt|j|tƒrPt|tƒrPt|j||iƒ|_n ||j|<dS)NZansible_group_priority)Ú set_priorityÚintr#Ú isinstancerrr )r(ÚkeyÚvaluerrrÚ set_variableôs $zGroup.set_variablecCsd|_| ¡D] }d|_qdSr*)r&rN)r(r;rrrrXþs zGroup.clear_hosts_cachecCs|jdur| ¡|_|jSr*)r&Ú _get_hostsr-rrrrWs  zGroup.get_hostscCs\g}i}|jdddD]@}|j}|D]0}||vr$d||<|jdkrJ|jrJq$| |¡q$q|S)NT)rHrIrÚall)rPr!rZimplicitr5)r(r!rJZkidZ kid_hostsZkkrrrrj szGroup._get_hostscCs |j ¡Sr*)r#r7r-rrrÚget_varsszGroup.get_varscCs&zt|ƒ|_Wnty Yn0dSr*)rer'Ú TypeError)r(r'rrrrds zGroup.set_priority)N)FF)Ú__name__Ú __module__Ú __qualname__Ú__doc__r)r.r/r1r4r0r2rLrNrPÚpropertyrQr,r\rVrarcrirXrWrjrlrdrrrrr8s0  ' #   rN)rFF)Z __future__rrrÚtypeZ __metaclass__Úcollections.abcrrÚ itertoolsrZansiblerrZansible.errorsr Zansible.module_utils._textr r Zansible.utils.displayr Zansible.utils.varsr rrrrrrrÚs