grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a d�tdŠØã@s`dZddlZddlmZddlmZddlmZddlZddl m Z ddl m Z m Z dd l mZmZmZmZdd l mZmZmZmZdd l mZmZdd lmZddlZd ZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZGdd„de ƒZ Gdd„de ƒZ!Gdd„de"ƒZ#dd„Z$Gdd„de#ƒZ%Gd d!„d!e#ƒZ&d"d#„Z'e(d$k�r\e'ƒdS)%a¯ Implements the RTS generic Target fabric classes. This file is part of RTSLib. Copyright (c) 2011-2013 by Datera, Inc. Copyright (c) 2011-2014 by Red Hat, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. éN)Úiglob)Úpartial)Úrangeé)ÚCFSNode)ÚRTSLibBrokenLinkÚ RTSLibError)ÚfreadÚfwriteÚ normalize_wwnÚ generate_wwn)Ú dict_removeÚset_attributesÚset_parametersÚignored)Ú_get_auth_attrÚ_set_auth_attr)Útcm)ÚuseridÚpasswordÚ mutual_useridÚmutual_passwordcsjeZdZdZdd„Zd‡fdd„ Zdd „Zd d „Z‡fd d „Ze edd�Z e dd„ƒZ ‡fdd„Z ‡ZS)ÚTargetz� This is an interface to Targets in configFS. A Target is identified by its wwn. To a Target is attached a list of TPG objects. cCsd|jj|jfS)Nz)Ú fabric_moduleÚnameÚwwn©Úself©rú1/usr/lib/python3.9/site-packages/rtslib/target.pyÚ__repr__/szTarget.__repr__NÚanycsªtt|ƒ ¡||_| ¡|durR| d¡r>d|dd…}| |¡\|_|_n,|j svt |j dƒ|_|j d|_nt dƒ‚|  |j¡}d|jj|f|_| |¡dS)au @param fabric_module: The target's fabric module. @type fabric_module: FabricModule @param wwn: The optional Target's wwn. If no wwn is specified, one will be generated. @type wwn: string @param mode:An optionnal string containing the object creation mode: - I{'any'} means the configFS object will be either looked up or created. - I{'lookup'} means the object MUST already exist configFS. - I{'create'} means the object must NOT already exist in configFS. @type mode:string @return: A Target object. Nznaa.6znaa.5érz/Fabric cannot generate WWN but it was not givenú%s/%s)ÚsuperrÚ__init__rÚ _check_selfÚ startswithÚto_normalized_wwnrÚwwn_typeÚwwnsr Ú wwn_typesrÚ to_fabric_wwnÚpathÚ_pathÚ_create_in_cfs_ine)rrrÚmodeZ fabric_wwn©Ú __class__rrr%2s  zTarget.__init__ccsL| ¡td|jƒD]0}tj |¡ d¡d}t|ƒ}t||dƒVqdS)Nz%s/tpgt*Ú_rÚlookup)r&Úglobr-ÚosÚbasenameÚsplitÚintÚTPG)rZtpg_dirÚtagrrrÚ _list_tpgsWs zTarget._list_tpgscCs |j |¡S)zC Whether or not this Target has a certain feature. )rÚ has_feature©rZfeaturerrrr=`szTarget.has_featurecs.| ¡|jD] }| ¡qtt|ƒ ¡dS)z„ Recursively deletes a Target object. This will delete all attached TPG objects and then the Target itself. N)r&ÚtpgsÚdeleter$r)rÚtpgr1rrr@fs  z Target.deletez#Get the list of TPG for the Target.©Údocc Cs~d|vr|dƒdSzt||dƒ}Wn2tyX}z|d|ƒWYd}~dSd}~00| dg¡D]}t |||¡qfdS)z¶ Set up target objects based upon t dict, from saved config. Guard against missing or bad dict items, but keep going. Call 'err_func' for each error. rz'wwn' not defined for TargetNz"Could not create Target object: %sr?)rrÚgetr:Úsetup)ÚclsZfm_objÚtÚerr_funcÚt_objÚerArrrrErs z Target.setupcs<tt|ƒ ¡}|j|d<|jj|d<dd„|jDƒ|d<|S)NrZfabriccSsg|] }| ¡‘qSr©Údump©Ú.0rArrrÚ ‹ózTarget.dump..r?)r$rrLrrrr?©rÚdr1rrrL‡s   z Target.dump)Nr!)Ú__name__Ú __module__Ú __qualname__Ú__doc__r r%r<r=r@Úpropertyr?Ú classmethodrErLÚ __classcell__rrr1rr&s%   rcsÎeZdZdZdd„Zd@‡fdd„ Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dAdd„Z dd„Z dd„Zdd„Zdd„Zdd„Z‡fd d!„ZdBd"d#„ZdCd$d%„ZdDd&d'„Zeed(d)�Zeed*d)�Zee e d+d)�Zeed,d)�Zee d-d)�Zeed.d)�Zeed/d)�Zee e d0d)�Zeee d1d2d3�ee!d1d2d3�d4d)�Z"eee d5d2d3�ee!d5d2d3�d6d)�Z#eee d7d2d3�ee!d7d2d3�d4d)�Z$eee d8d2d3�ee!d8d2d3�d6d)�Z%d9d:„Z&ee&d;d)�Z'e(dd?„Z*‡Z+S)Er:aH This is a an interface to Target Portal Groups in configFS. A TPG is identified by its parent Target object and its TPG Tag. To a TPG object is attached a list of NetworkPortals. Targets without the 'tpgts' feature cannot have more than a single TPG, so attempts to create more will raise an exception. cCs d|jS)Nz©r;rrrrr šsz TPG.__repr__Nr!cs>tt|ƒ ¡|dur^dd„|jDƒ}tdƒD]}||vr.|dkr.|}qLq.|durvtdƒ‚nt|ƒ}|dkrvtdƒ‚||_t|t ƒrŽ||_ ntdƒ‚d |j j |j f|_|j j }| d ¡�stj  |j¡�st |¡D]8}| d ¡rØtj  d ||f¡rØ|d |j krØtdƒ‚qØ| |¡| d¡�r:| ¡�s:| ¡dS)a9 @param parent_target: The parent Target object of the TPG. @type parent_target: Target @param tag: The TPG Tag (TPGT). @type tag: positive int @param mode:An optionnal string containing the object creation mode: - I{'any'} means the configFS object will be either looked up or created. - I{'lookup'} means the object MUST already exist configFS. - I{'create'} means the object must NOT already exist in configFS. @type mode:string @return: A TPG object. NcSsg|] }|j‘qSrrZrMrrrrO¯rPz TPG.__init__..irz Cannot find an available TPG TagzThe TPG Tag must be >=0zInvalid parent Targetz %s/tpgt_%dZtpgtsZtpgt_r#ztpgt_%dz Target cannot have multiple TPGsÚnexus)r$r:r%r?rrr9Ú_tagÚ isinstancerÚ_parent_targetÚ parent_targetr-r;r.r=r6ÚisdirÚlistdirr'r/Ú _get_nexusÚ _set_nexus)rr_r;r0ÚtagsÚindexZ target_pathÚfilenamer1rrr%�s:    ÿ þ  z TPG.__init__cCs|jS©N)r\rrrrÚ_get_tagÏsz TPG._get_tagcCs|jSrg)r^rrrrÚ_get_parent_targetÒszTPG._get_parent_targetccs`| ¡| d¡sdSt d|j¡D]4}tj |¡ dd¡\}}t|ƒ}t|||dƒVq&dS)NZnpsz%s/npú:rr4) r&r=r6rar-r7Úrsplitr9Ú NetworkPortal)rZnetwork_portal_dirÚ ip_addressÚportrrrÚ_list_network_portalsÕs ÿzTPG._list_network_portalscCs6| ¡d|j}tj |¡r.ttt|ƒƒƒSdSdS)Nú %s/enableT)r&r-r6ÚisfileÚboolr9r ©rr-rrrÚ _get_enableàs   zTPG._get_enablec Csv| ¡d|j}tj |¡rr|| ¡krrzt|tt|ƒƒƒWn0typ}zt d|ƒ‚WYd}~n d}~00dS)zs Enables or disables the TPG. If the TPG doesn't support the enable attribute, do nothing. rpzCannot change enable state: %sN) r&r-r6rqrtr Ústrr9ÚIOErrorr)rÚbooleanr-rJrrrÚ _set_enableês zTPG._set_enablecCsH| ¡| d¡r@ztd|jƒ}Wnty:d}Yn0|SdSdS)zU Gets the nexus initiator WWN, or None if the TPG does not have one. r[ú%s/nexusÚN)r&r=r r-rv)rÚ nexus_wwnrrrrb÷s   zTPG._get_nexuscCsl| ¡| d¡stdƒ‚| ¡r*tdƒ‚|jj}|rF| |¡d}n t|jjƒ}t d|j |  |¡ƒdS)z‹ Sets the nexus initiator WWN. Raises an exception if the nexus is already set or if the TPG does not use a nexus. r[zThe TPG does not use a nexusz,The TPG's nexus initiator WWN is already setrryN) r&r=rrbr_rr(r r)r r-r,)rr{Úfmrrrrcs  zTPG._set_nexusccsZ| ¡| d¡sdSdd„t d|j¡Dƒ}|D] }|jj}t|| |¡dƒVq4dS)NÚaclscSsg|]}tj |¡‘qSr©r6r-r7©rNr-rrrrO sÿz'TPG._list_node_acls..z%s/aclsr4) r&r=r6rar-r_rÚNodeACLZfrom_fabric_wwn)rZ node_acl_dirsZ node_acl_dirr|rrrÚ_list_node_aclss ÿzTPG._list_node_aclscsPˆ ¡ˆ d¡sdStgƒ}ˆjD]}|j}|r$| |¡q$‡fdd„|DƒS)Nr}c3s|]}tˆ|ƒVqdSrg)Ú NodeACLGroup)rNÚnrrrÚ 2rPz,TPG._list_node_acl_groups..)r&r=ÚsetÚ node_aclsr;Úadd)rÚnamesÚnar;rrrÚ_list_node_acl_groups&s   zTPG._list_node_acl_groupsccsR| ¡dd„t d|j¡Dƒ}|D]&}| d¡d}t|ƒ}t||ƒVq&dS)NcSsg|]}tj |¡‘qSrr~rrrrrO6sÿz"TPG._list_luns..z%s/lunr3r)r&r6rar-r8r9ÚLUN)rZlun_dirsZlun_dirÚlunrrrÚ _list_luns4sÿzTPG._list_lunscCs(| ¡d|j}t|dt|ƒƒdS)Nz %s/controlz%s )r&r-r ru)rZcommandr-rrrÚ_control=s z TPG._controlcCs |j |¡S)z@ Whether or not this TPG has a certain feature. )r_r=r>rrrr=DszTPG.has_featurecs\| ¡d|_|jD] }| ¡q|jD] }| ¡q(|jD] }| ¡qGet the list of NodeACL objects currently attached to the TPG.z=Get the list of NodeACL groups currently attached to the TPG.z:Get the list of LUN objects currently attached to the TPG.z*Get or set (once) the TPG's Nexus is used.ú auth/useridT)Ú attributeÚignoreú*Set or get the initiator CHAP auth userid.ú auth/passwordú,Set or get the initiator CHAP auth password.úauth/userid_mutualúauth/password_mutualcCs8| ¡d|j}zttt|ƒƒƒWSYdS0dS©Nz%s/auth/authenticate_target©r&r-rrr9r rsrrrÚ_get_authenticate_target™s  zTPG._get_authenticate_targetú)Get the boolean authenticate target flag.c Cs||| dd¡d�}t|| di¡|ƒt|| di¡|ƒ| dg¡D]}t |||¡qH| dg¡D]}t |||¡qh| dg¡D]}t |||¡qˆ| dd ¡|_t|d ƒt   |¡D]<\}} | r¾zt ||| ƒWq¾|d |j |fƒYq¾0q¾dS) Nr;rZÚ attributesÚ parametersr�Úportalsr†r�T)r�r§r†r;r¥r¦r�z#Could not set tpg %s attribute '%s') rDrrr‹rErlr€r�r ÚsixÚ iteritemsÚsetattrr;) rFrIrArHÚtpg_objrŒÚpr’rÚvaluerrrrE¤s& ÿz TPG.setupcs–tt|ƒ ¡}|j|d<|j|d<dd„|jDƒ|d<dd„|jDƒ|d<dd„|jDƒ|d <| d ¡r’t D]$}t |d |dƒ}|rl||d |<ql|S) Nr;r�cSsg|] }| ¡‘qSrrK©rNrŒrrrrOÂrPzTPG.dump..r�cSsg|] }| ¡‘qSrrK)rNr“rrrrOÃrPr§cSsg|] }| ¡‘qSrrK)rNr’rrrrOÄrPr†ÚauthÚchap_) r$r:rLr;r�r�r‘r†r=Ú auth_paramsÚgetattr©rrRÚattrÚvalr1rrrL¾s   zTPG.dump)Nr!)N)r!)r!)NN),rSrTrUrVr r%rhrirortrxrbrcr�rŠr�rŽr=r@r•r–rŒrWr;r_r�r‘r†Znode_acl_groupsr�r[rrrÚ chap_useridÚ chap_passwordÚchap_mutual_useridÚchap_mutual_passwordr£Úauthenticate_targetrXrErLrYrrr1rr:�s„ 2          ÿÿÿÿÿÿÿÿ þ þ þ þÿ r:csÜeZdZdZdZdd„Zd%‡fdd„ Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Z‡fdd„Zee dd�Zee dd�Zee dd�Zeedd�Zee dd�Zee ed d�Zed!d"„ƒZ‡fd#d$„Z‡ZS)&r‹zw This is an interface to RTS Target LUNs in configFS. A LUN is identified by its parent TPG and LUN index. iÿÿcCsd|j|jj|jjfS)Nz)rŒr—Úpluginrrrrrr ×s ÿz LUN.__repr__Ncs$tt|ƒ ¡t|tƒr ||_ntdƒ‚|dur~dd„|jjDƒ}t |j dƒD]}||vrP|}qfqP|dur¦td|j ƒ‚n(t |ƒ}|dks˜||j kr¦td|j ƒ‚||_ d |jj |jf|_|durØ|durØtd ƒ‚|du�r| d ¡z| ||¡Wn| ¡‚Yn0n | d ¡dS) a9 A LUN object can be instanciated in two ways: - B{Creation mode}: If I{storage_object} is specified, the underlying configFS object will be created with that parameter. No LUN with the same I{lun} index can pre-exist in the parent TPG in that mode, or instanciation will fail. - B{Lookup mode}: If I{storage_object} is not set, then the LUN will be bound to the existing configFS LUN object of the parent TPG having the specified I{lun} index. The underlying configFS object must already exist in that mode. @param parent_tpg: The parent TPG object. @type parent_tpg: TPG @param lun: The LUN index. @type lun: 0-65535 @param storage_object: The storage object to be exported as a LUN. @type storage_object: StorageObject subclass @param alias: An optional parameter to manually specify the LUN alias. You probably do not need this. @type alias: string @return: A LUN object. úInvalid parent TPGNcSsg|] }|j‘qSr)rŒ)rNÚlrrrrOúrPz LUN.__init__..rzAll LUNs 0-%d in userzLUN must be 0 to %dz %s/lun/lun_%dzGThe alias parameter has no meaning without the storage_object parameterÚcreater4)r$r‹r%r]r:Ú _parent_tpgrÚ parent_tpgr�rÚMAX_TARGET_LUNr9Ú_lunr-rŒr.r/Ú _configurer@)rrÀrŒr—r˜r�rer1rrr%Ûs6    z LUN.__init__cCsx| ¡|dur&tt ¡ƒdd…}nt|ƒ ¡}d|vrDtd|ƒ‚d|j|f}|jr`|j}ntdƒ‚t  ||¡dS)Néöÿÿÿú/zInvalid alias: %sr#z)storage_object does not exist in configFS) r&ruÚuuidÚuuid4Ústriprr-Úexistsr6Úsymlink)rr—r˜Z destinationÚsourcerrrrÃs  zLUN._configurecCsL| ¡t |j¡D]*}tj d|j|f¡rtj |¡Sqtdƒ‚dS©Nr#z)Broken LUN in configFS, no storage object©r&r6rar-Úislinkr7rrsrrrÚ _get_alias*s zLUN._get_aliascCs,| ¡tj d|j|jf¡}tj |¡S)Nr#)r&r6r-Úrealpathr˜rÚ StorageObjectZ so_from_path)rZ alias_pathrrrÚ_get_storage_object2szLUN._get_storage_objectcCs|jSrg©r¿rrrrÚ_get_parent_tpg7szLUN._get_parent_tpgcCs|jSrg)rÂrrrrÚ_get_lun:sz LUN._get_lunccs\| ¡|j}| d¡sdS|jD]4}|jD](}tj d|j|jf¡|jkr,|Vq,q"dS)Nr}r#) r&rÀr=r†Ú mapped_lunsr6r-rÐr˜)rrAr‰ÚmlunrrrÚ_list_mapped_luns=s   zLUN._list_mapped_lunsc Cs†| ¡| ¡}|jdurdSd|j}z2t|ƒ}|s)rmrnrrrrr ÈszNetworkPortal.__repr__é¼ r!c s´tt|ƒ ¡t|ƒ|_zt|ƒ|_Wnty@tdƒ‚Yn0t |t ƒrT||_ ntdƒ‚d|j j |j|jf|_z| |¡Wn,ty®}zt|ƒ‚WYd}~n d}~00dS)aï @param parent_tpg: The parent TPG object. @type parent_tpg: TPG @param ip_address: The ipv4/v6 IP address of the NetworkPortal. ipv6 addresses should be surrounded by '[]'. @type ip_address: string @param port: The optional (defaults to 3260) NetworkPortal TCP/IP port. @type port: int @param mode: An optionnal string containing the object creation mode: - I{'any'} means the configFS object will be either looked up or created. - I{'lookup'} means the object MUST already exist configFS. - I{'create'} means the object must NOT already exist in configFS. @type mode:string @return: A NetworkPortal object. z Invalid portr¼z %s/np/%s:%dN)r$rlr%ruÚ _ip_addressr9Ú_portÚ ValueErrorrr]r:r¿rÀr-rmrnr.r/ÚOSError)rrÀrmrnr0Úmsgr1rrr%Ës    ÿzNetworkPortal.__init__cCs|jSrg)rçrrrrÚ_get_ip_addressòszNetworkPortal._get_ip_addresscCs|jSrg)rèrrrrÚ _get_portõszNetworkPortal._get_portcCs|jSrgrÓrrrrrÔøszNetworkPortal._get_parent_tpgcCs2ztttd|jƒƒƒWSty,YdS0dS)Nú%s/iserF©rrr9r r-rvrrrrÚ _get_iserûs zNetworkPortal._get_isercCsLd|j}zt|tt|ƒƒƒWn&tyFtj |¡rBtdƒ‚Yn0dS)NrîzCannot change iser©r-r rur9rvr6rqr©rrwr-rrrÚ _set_isers    zNetworkPortal._set_isercCs2ztttd|jƒƒƒWSty,YdS0dS)Nú %s/cxgbitFrïrrrrÚ _get_offload s zNetworkPortal._get_offloadcCsLd|j}zt|tt|ƒƒƒWn&tyFtj |¡rBtdƒ‚Yn0dS)NrôzCannot change offloadrñròrrrÚ _set_offloads    zNetworkPortal._set_offloadcsd|_d|_tt|ƒ ¡dS)NF)ÚiserÚoffloadr$rlr@rr1rrr@szNetworkPortal.deleterárBz+Get the NetworkPortal's TCP port as an int.z/Get the NetworkPortal's IP address as a string.zLGet or set a boolean value representing if this NetworkPortal supports iSER.zOGet or set a boolean value representing if this NetworkPortal supports offload.c Cs°d|vr|d|jƒdSd|vr4|d|jƒdSz4|||d|dƒ}| dd¡|_| dd¡|_WnBttfyª}z&|d|d|d|fƒWYd}~n d}~00dS) Nrmz2'ip_address' field missing from a portal in TPG %drnz,'port' field missing from a portal in TPG %dr÷Frøz.Creating NetworkPortal object %s:%s failed: %s)r;rDr÷rørrå)rFr«r¬rHZnprJrrrrE.sÿzNetworkPortal.setupcs:tt|ƒ ¡}|j|d<|j|d<|j|d<|j|d<|S)Nrnrmr÷rø)r$rlrLrnrmr÷rørQr1rrrL?s     zNetworkPortal.dump)rær!)rSrTrUrVr r%rìrírÔrðrórõrör@rWrÀrnrmr÷rørXrErLrYrrr1rrl½s: '  ÿÿÿÿÿ rlcsxeZdZdZdd„Zd3‡fdd„ Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„Z‡fdd„Zd4dd„Zeee dd�Zee e d d�Zeed!d�Zeed"d�Zee d#d�Zee d$d�Zeeed%d&�eed%d&�d'd�Zeeed(d&�eed(d&�d)d�Zeeed*d&�eed*d&�d'd�Zeeed+d&�eed+d&�d)d�Zd,d-„Zeed.d�Z e!d/d0„ƒZ"‡fd1d2„Z#‡Z$S)5r€z~ This is an interface to node ACLs in configFS. A NodeACL is identified by the initiator node wwn and parent TPG. cCs d|jS)Nz ©r”rrrrr PszNodeACL.__repr__r!csntt|ƒ ¡t|tƒr ||_ntdƒ‚|jjj }t |j |ƒ\|_ |_ d|jj| |j¡f|_| |¡dS)aX @param parent_tpg: The parent TPG object. @type parent_tpg: TPG @param node_wwn: The wwn of the initiator node for which the ACL is created. @type node_wwn: string @param mode:An optionnal string containing the object creation mode: - I{'any'} means the configFS object will be either looked up or created. - I{'lookup'} means the object MUST already exist configFS. - I{'create'} means the object must NOT already exist in configFS. @type mode:string @return: A NodeACL object. r¼z %s/acls/%sN)r$r€r%r]r:r¿rrÀr_rr r+Ú _node_wwnr)r-r,r”r.r/)rrÀr”r0r|r1rrr%Ss  zNodeACL.__init__cCs|jSrg)rúrrrrÚ _get_node_wwnoszNodeACL._get_node_wwncCs|jSrgrÓrrrrrÔrszNodeACL._get_parent_tpgcCs| ¡d|j}t|ƒS)Nú%s/cmdsn_depth)r&r-r rsrrrÚ_get_tcq_depthus zNodeACL._get_tcq_depthc Csf| ¡d|j}zt|d|ƒWn<ty`}z$|d}tdt|ƒƒ‚WYd}~n d}~00dS)Nrüz%srzCannot set tcq_depth: %s)r&r-r rvrru)rÚdepthr-rërrrÚ_set_tcq_depthzs zNodeACL._set_tcq_depthcCs@| ¡ztd|jƒ}|r"|WSWdSty:YdS0dS)Nú%s/tag)r&r r-rv)rr;rrrrhƒs zNodeACL._get_tagcCsVttƒ�:|dur$td|jdƒntd|j|ƒWdƒn1sH0YdS)NrZNULL)rrvr r-)rZtag_strrrrÚ_set_tag�s zNodeACL._set_tagccsF| ¡td|jƒD]*}ttj |¡ d¡dƒ}t||ƒVqdS)Nz%s/lun_*r3r)r&r5r-r9r6r7r8Ú MappedLUN)rZmapped_lun_dirÚ mapped_lunrrrrØ”szNodeACL._list_mapped_lunscCs†ztd|jƒ ¡}Wnty*YdS0|d d¡r>dSi}|D�]8}| d¡rh||d<g|d<qF| d¡rŠ| d¡d  ¡|d <qF| d ¡rÒt| d¡d  ¡dƒ|d <| d ¡d  ¡d ¡|d<qFd|vrö| d¡d  ¡d|d<qFd|v�rHt| d¡d  ¡dƒ}| d¡d  ¡d}|d t ||d�¡qFd|vrF| ¡d |ddd<| ¡d|ddd<qF|S)Nz%s/inforz No activezInitiatorName:Úparent_nodeaclZ connectionszInitiatorAlias:rjrr˜zLIO Session ID:Úidz SessionType:ÚtypeZTARG_SESS_STATE_Z_STATE_ÚstateZTARG_CONN_STATE_)ÚcidÚcstateZAddressrÝZaddressrâZ transport) r r-rÚrvr'r8rÈr9ÚappendÚdict)rÚlinesÚsessionÚlinerr rrrÚ _get_sessionšs4        zNodeACL._get_sessioncCs |j |¡S©zD Whether or not this NodeACL has a certain feature. )rÀr=r>rrrr=»szNodeACL.has_featurecs.| ¡|jD] }| ¡qtt|ƒ ¡dS)z¢ Delete the NodeACL, including all MappedLUN objects. If the underlying configFS object does not exist, this method does nothing. N)r&rÖr@r$r€)rrr1rrr@Ás  zNodeACL.deleteNcCs| ¡t||||d�S)zO Same as MappedLUN() but without the parent_nodeacl parameter. ©rÚtpg_lunÚ write_protect)r&r©rrrrrrrrÌsÿzNodeACL.mapped_lunzJSet or get the TCQ depth for the initiator sessions matching this NodeACL.rBz9Set or get the NodeACL tag. If not supported, return NonerázGet the node wwn.z6Get the list of all MappedLUN objects in this NodeACL.z2Gives a snapshot of the current session or C{None}r™)ršrœr�ržrŸr cCs"| ¡d|j}ttt|ƒƒƒSr¡r¢rsrrrr£ïs z NodeACL._get_authenticate_targetr¤c Csðd|vr|dƒdSz|||dƒ}Wn:ty`}z"|d|d|fƒWYd}~dSd}~00t|| di¡|ƒ| dg¡D]}t ||||¡q‚t|dƒt |¡D]>\}}|r¬zt|||ƒWq¬|d|d|fƒYq¬0q¬dS)Nr”z'node_wwn' missing in node_aclz&Error when creating NodeACL for %s: %sr¥rÖ)r¥rÖr”z'Could not set nodeacl %s attribute '%s') rrrDrrEr r¨r©rª) rFr«r’rHÚacl_objrJr×rr­rrrrE÷s(  ÿz NodeACL.setupcsttt|ƒ ¡}|j|d<dd„|jDƒ|d<|jr<|j|d<| d¡rptD]$}t|d|dƒ}|rJ||d|<qJ|S)Nr”cSsg|] }| ¡‘qSrrKr®rrrrOrPz NodeACL.dump..rÖr;r¯r°) r$r€rLr”rÖr;r=r±r²r³r1rrrLs   z NodeACL.dump)r!)NN)%rSrTrUrVr r%rûrÔrýrÿrhrrØrr=r@rrWÚ tcq_depthr;rÀr”rÖr rrrr¶r·r¸r¹r£rºrXrErLrYrrr1rr€Hsn  ! ÿÿÿÿÿÿ  þ  þ  þ  þÿ r€csØeZdZdZdd„Zd$‡fdd„ Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z ‡fdd„Zeedd�Zee dd�Zee e dd�Zee dd�Zee dd�Zeedd�Zed d!„ƒZ‡fd"d#„Z‡ZS)%raM This is an interface to RTS Target Mapped LUNs. A MappedLUN is a mapping of a TPG LUN to a specific initiator node, and is part of a NodeACL. It allows the initiator to actually access the TPG LUN if ACLs are enabled for the TPG. The initial TPG LUN will then be seen by the initiator node as the MappedLUN. cCs d|jj|j|jjj|jjfS)Nz% tpg%d lun %d>)rr”rrÀr;rrŒrrrrr )s  ÿÿzMappedLUN.__repr__Ncsêtt|ƒ ¡t|tƒs"tdƒ‚n||_|js6tdƒ‚zt|ƒ|_ Wnt y^tdƒ‚Yn0|j dkrrtdƒ‚d|j j |j f|_|durž|duržtdƒ‚|durÜ| d ¡z| |||¡Wqæ| ¡‚Yqæ0n | d ¡dS) a. A MappedLUN object can be instanciated in two ways: - B{Creation mode}: If I{tpg_lun} is specified, the underlying configFS object will be created with that parameter. No MappedLUN with the same I{mapped_lun} index can pre-exist in the parent NodeACL in that mode, or instanciation will fail. - B{Lookup mode}: If I{tpg_lun} is not set, then the MappedLUN will be bound to the existing configFS MappedLUN object of the parent NodeACL having the specified I{mapped_lun} index. The underlying configFS object must already exist in that mode. @param mapped_lun: The mapped LUN index. @type mapped_lun: int @param tpg_lun: The TPG LUN index to map, or directly a LUN object that belong to the same TPG as the parent NodeACL. @type tpg_lun: int or LUN @param write_protect: The write-protect flag value, defaults to False (write-protection disabled). @type write_protect: bool z5The parent_nodeacl parameter must be a NodeACL objectz!The parent_nodeacl does not existz1The mapped_lun parameter must be an integer valuerzMapped LUN must be >= 0z %s/lun_%dNzHThe write_protect parameter has no meaning without the tpg_lun parameterr¾r4)r$rr%r]r€rÚ_parent_nodeaclrÉr9Ú _mapped_lunrérr-rr.r/rÃr@)rrrrrr˜r1rrr%.s.      zMappedLUN.__init__cCsÜ| ¡t|tƒr|j}n(z t|ƒ}Wnty@tdƒ‚Yn0|jjj D]}|j|krL|}qdqLt|tƒrr|s‚tdt |ƒƒ‚|sšt t   ¡ƒdd…}t  |jd|j|f¡zt|ƒdk|_Wnd|_Yn0dS)Nz5The tpg_lun must be either an integer or a LUN objectz!LUN %s does not exist in this TPGrÄr#rF)r&r]r‹rŒr9rérrrÀr�rurÆrÇr6rÊr-r)rrrr˜rŒrrrrÃhs,    ÿzMappedLUN._configurecCsL| ¡t |j¡D]*}tj d|j|f¡rtj |¡Sqtdƒ‚dSrÌrÍrsrrrrÏ„s zMappedLUN._get_aliascCs|jSrg©rrrrrÚ_get_mapped_lunŒszMappedLUN._get_mapped_luncCs|jSrg)rrrrrÚ_get_parent_nodeacl�szMappedLUN._get_parent_nodeaclcCs0| ¡d|j}|r"t|dƒn t|dƒdS)Nú%s/write_protectÚ1Ú0)r&r-r )rrr-rrrÚ_set_write_protect’s   zMappedLUN._set_write_protectcCs"| ¡d|j}ttt|ƒƒƒS)Nrr¢rsrrrÚ_get_write_protectšs zMappedLUN._get_write_protectcCsN| ¡tj d|j|jf¡}|jjjD]}|j|kr*|Sq*tdƒ‚dS)Nr#z"Broken MappedLUN, no TPG LUN found) r&r6r-rÐr˜rrÀr�r)rr-rŒrrrÚ _get_tpg_lunŸs   zMappedLUN._get_tpg_luncCs| ¡|jjSrg)r&rr”rrrrrû¨szMappedLUN._get_node_wwncsX| ¡zd|j|jf}Wnty.Yn0tj |¡rFt |¡tt|ƒ  ¡dS)z' Delete the MappedLUN. r#N) r&r-r˜rr6rÎrßr$rr@)rZlun_linkr1rrr@®s   zMappedLUN.deletez+Get the integer MappedLUN mapped_lun index.rBzGet the parent NodeACL object.ú(Get or set the boolean write protection.ú4Get the TPG LUN object the MappedLUN is pointing at.z8Get the wwn of the node for which the TPG LUN is mapped.zGet the MappedLUN alias.c CsÄd|vr|dƒdSd|vr(|dƒdS|jD]}|j|dkr.|}qfq.|d|d|dfƒdSz2|||d|| d¡| d¡ƒ}| dd¡|_Wn&ttfy¾|d |dƒYn0dS) Nrz'tpg_lun' not in a mapped_lunrez'index' not in a mapped_lunz3Could not find matching TPG LUN %d for MappedLUN %srr˜r;z#Creating MappedLUN object %d failed)r�rŒrDr;rrå)rFr«rr×rHrŒZ tpg_lun_objZmlun_objrrrrEÉs, ÿ  þzMappedLUN.setupcs<tt|ƒ ¡}|j|d<|j|d<|jj|d<|j|d<|S)Nrrerr˜)r$rrLrrrrŒr˜rQr1rrrLås     zMappedLUN.dump)NNN)rSrTrUrVr r%rÃrÏrrrr r!rûr@rWrrrrr”r˜rXrErLrYrrr1rrsD ÿ:  ÿÿÿÿÿÿ rc@sxeZdZdZdd„Zdd„Zdd„Zdd „Zdd d „Zdd d„Z dd„Z dd„Z dd„Z dd„Z dd„Zedd„ƒZd S)ÚGroupz  An abstract base class akin to CFSNode, but for classes that emulate a higher-level group object across the actual NodeACL configfs structure. cCs ||_dS)z¨ members_func is a function that takes a self argument and returns an iterator of the objects that the derived Group class is grouping. N)Ú _mem_func)rZ members_funcrrrr%ôszGroup.__init__cCs0zt| |¡ƒWSty*tdƒ‚Yn0dS)NzGroup is empty)Únextr%Ú StopIterationÚ IndexErrorrrrrÚ_get_first_memberüs zGroup._get_first_membercCst| ¡|ƒS)z¹ Helper fn to use with partial() to support getting a property value from the first member of the group. (All members of the group should be identical.) )r²r))rÚproprrrÚ _get_propszGroup._get_propcCs | |¡D]}t|||ƒq dS)zÛ Helper fn to use with partial() to support setting a property value in all members of the group. Caution: Arguments reversed! This is so partial() can be used on property name. N)r%rª)rr­r*ÚmemrrrÚ _set_prop s zGroup._set_propNcCs| ¡ ||¡Srg)r)Úlist_attributes©rÚwritableÚreadablerrrr.szGroup.list_attributescCs| ¡ ||¡Srg)r)Úlist_parametersr/rrrr2szGroup.list_parameterscCs | |¡D]}| ||¡q dSrg)r%Ú set_attribute)rršr­Úobjrrrr3szGroup.set_attributecCs | |¡D]}| ||¡q dSrg)r%Ú set_parameter)rÚ parameterr­r4rrrr5 szGroup.set_parametercCs| ¡ |¡Srg)r)Ú get_attribute)rršrrrr7$szGroup.get_attributecCs| ¡ |¡Srg)r)Ú get_parameter)rr6rrrr8'szGroup.get_parametercCs| |¡D] }| ¡q dS)z2 Delete all members of the group. N)r%r@)rr,rrrr@*sz Group.deletecCst| |¡ƒSrg)r!r%rrrrrÉ1sz Group.exists)NN)NN)rSrTrUrVr%r)r+r-r.r2r3r5r7r8r@rWrÉrrrrr$îs  r$cCsd|vrtdƒ‚dS)NÚ.z!'.' not permitted in group names.)r©rrrrÚ_check_group_name6sr;cs4eZdZdZdd„Z‡fdd„Zdd„Zdd „Zed d „ƒZ d d „Z dd„Z edd„ƒZ edd„ƒZ dd„Zedd„ƒZd8dd„Zedd„ƒZeeedd�Zdd „Zd!d"„Zd#d$„Zd9d%d&„Zd'd(„Zd:d)d*„Zd+d,„Zd;d-d.„Zd/d0„Zdr:rrrrr @szNodeACLGroup.__repr__cs,tt|ƒ tjj¡t|ƒ||_||_dSrg)r$r‚r%Ú _node_aclsÚfgetr;Ú_namer¿)rrÀrr1rrr%CszNodeACLGroup.__init__cCs|jSrg)r>rrrrÚ _get_nameIszNodeACLGroup._get_namecCs$t|ƒ|jD] }||_q||_dSrg)r;r<r;r>©rrr‰rrrÚ _set_nameLs zNodeACLGroup._set_namecCs|jS)z, Get the parent TPG object. rÓrrrrrÀRszNodeACLGroup.parent_tpgcCsÔt|j|ƒ}||jvrdSzªzt|jƒ}Wnty<Yn~0|jD] }| ¡qD|jD]}t||j|j |j ƒqX|j dd�D]}|  ||  |¡¡q~|jdd�D]}| || |¡¡q¢W|j|_n |j|_0dS)a4 Add a WWN to the NodeACLGroup. If a NodeACL already exists for this WWN, its configuration will be changed to match the NodeACLGroup, except for its auth parameters, which can vary among group members. @param node_wwn: An initiator WWN @type node_wwn: string NT)r0)r€rÀr<r&r'rÖr@rrrrr.r3r7r2r5r8rr;)rr”ÚnaclZmodelr×ÚitemrrrÚadd_aclYs       zNodeACLGroup.add_aclcCst|j|dd�}| ¡dS)z~ Remove a WWN from the NodeACLGroup. @param node_wwn: An initiator WWN @type node_wwn: string r4)r0N)r€rÀr@)rr”rBrrrÚ remove_aclyszNodeACLGroup.remove_aclccs$|jjD]}|j|jkr|VqdS)zL Gives access to the underlying NodeACLs within this group. N)rÀr†r;r)rr‰rrrr<ƒs  zNodeACLGroup._node_aclscCsdd„|jDƒS)z> Give the Node WWNs of members of this group. css|] }|jVqdSrgrù)rNr‰rrrr„‘rPz$NodeACLGroup.wwns..)r<rrrrr*ŒszNodeACLGroup.wwnscCs |j |¡Sr)r¿r=r>rrrr=“szNodeACLGroup.has_featureccs |jD]}|j}|r|VqdS)z. Yields any current sessions. N)r<r )rr‰r rrrÚsessions™s zNodeACLGroup.sessionsNcCst||||d�S)z8 Add a mapped lun to all group members. r)ÚMappedLUNGrouprrrrÚmapped_lun_group£sÿzNodeACLGroup.mapped_lun_groupccs@z | ¡}Wnty YdS0|jD]}t||jƒVq(dS)zL Generates all MappedLUNGroup objects in this NodeACLGroup. N)r)r(rÖrGr)rÚfirstr×rrrÚmapped_lun_groupsªs    zNodeACLGroup.mapped_lun_groupszGet/set NodeACLGroup name.rBccs&|jD]}|jt|d|ƒfVqdS©Nr°)r<r”r²r@rrrÚ _get_chapºs zNodeACLGroup._get_chapcCsD|jD]8}|s t|d||ƒq||jkrt|d||ƒq@qdSrK)r<rªr”)rrr­rr‰rrrÚ _set_chap¾s   zNodeACLGroup._set_chapcCs |jdd�S)zM Returns a (wwn, userid) tuple for each member of the group. rr:©rLrrrrÚ get_useridsÆszNodeACLGroup.get_useridscCs| d||¡S)zk If wwn, set the userid for just that wwn, otherwise set it for all group members. r©rM©rr­rrrrÚ set_useridsÌszNodeACLGroup.set_useridscCs |jdd�S)zO Returns a (wwn, password) tuple for each member of the group. rr:rNrrrrÚ get_passwordsÓszNodeACLGroup.get_passwordscCs| d||¡S)zm If wwn, set the password for just that wwn, otherwise set it for all group members. rrPrQrrrÚ set_passwordsÙszNodeACLGroup.set_passwordscCs |jdd�S)zT Returns a (wwn, mutual_userid) tuple for each member of the group. rr:rNrrrrÚget_mutual_useridsàszNodeACLGroup.get_mutual_useridscCs| d||¡S)zr If wwn, set the mutual_userid for just that wwn, otherwise set it for all group members. rrPrQrrrÚset_mutual_useridsæszNodeACLGroup.set_mutual_useridscCs |jdd�S)zV Returns a (wwn, mutual_password) tuple for each member of the group. rr:rNrrrrÚget_mutual_passwordsísz!NodeACLGroup.get_mutual_passwordscCs| d||¡S)zt If wwn, set the mutual_password for just that wwn, otherwise set it for all group members. rrPrQrrrÚset_mutual_passwordsósz!NodeACLGroup.set_mutual_passwordsr©r*zNSet or get the TCQ depth for the initiator sessions matching this NodeACLGrouprºr¤)NN)N)N)N)N)$rSrTrUrVr r%r?rArWrÀrDrEr<r*r=rFrHrJrrLrMrOrRrSrTrUrVrWrXrr$r+r-rrºrYrrr1rr‚<sN        ÿ     þÿr‚cs„eZdZdZdd„Z‡fdd„Zedd„ƒZedd „ƒZed d „ƒZ ee e j d d �e e j d d �dd�Zee e j dd �dd�Z‡ZS)rGz› Used with NodeACLGroup, this aggregates all MappedLUNs with the same LUN so that it can be configured across all members of the NodeACLGroup. cCsd|jj|jfS)Nz)Ú_nagrrrrrrr szMappedLUNGroup.__repr__csLtt|ƒ tjj¡||_||_|jjD]}t|g|¢Rd|i|¤Žq(dS)Nr) r$rGr%Ú _mapped_lunsr=rZrr<r)rZ nodeaclgrouprÚargsÚkwargsr‰r1rrr% s  zMappedLUNGroup.__init__ccs0|jjD]"}|jD]}|j|jkr|VqqdSrg)rZr<rÖr)rr‰r×rrrr[s   zMappedLUNGroup._mapped_lunscCs|jS)z= Get the integer MappedLUN mapped_lun index. rrrrrrszMappedLUNGroup.mapped_luncCs|jS)z5 Get the parent NodeACLGroup object. )rZrrrrÚparent_nodeaclgroup sz"MappedLUNGroup.parent_nodeaclgrouprrYr"rBrr#)rSrTrUrVr r%rWr[rr^rr$r+r-rrrYrrr1rrGs      þÿrGcCsddlm}|ƒdS)Nr©Útestmod)Zdoctestr`r_rrrÚ_test.s raÚ__main__))rVr6r5rÚ functoolsrZ six.movesrrÆZnoderZutilsrrr r r r r rrrrrrzrr¨r±rr:r‹rlr€rÚobjectr$r;r‚rGrarSrrrrÚsB     i@q WQHG,