Ë
    ÇVhV,  ã                   ó¦   — d dl mZmZmZ dZdZdZd dlZd dlm	Z	 d dl
mZmZ eZ G d„ d	e«      Z G d
„ de«      Zdd„Zd„ Zd„ Zedk(  r e«        yy)é    )Úabsolute_importÚdivisionÚprint_functionat  
module: nxos_vsan
short_description: Configuration of vsan for Cisco NXOS MDS Switches.
description:
- Configuration of vsan for Cisco MDS NXOS.
version_added: 1.0.0
author:
- Suhas Bharadwaj (@srbharadwaj) (subharad@cisco.com)
notes:
- Tested against Cisco MDS NX-OS 8.4(1)
options:
  vsan:
    description:
    - List of vsan details to be added or removed
    type: list
    elements: dict
    suboptions:
      id:
        description:
        - Vsan id
        required: true
        type: int
      name:
        description:
        - Name of the vsan
        type: str
      suspend:
        description:
        - suspend the vsan if True
        type: bool
      remove:
        description:
        - Removes the vsan if True
        type: bool
      interface:
        description:
        - List of vsan's interfaces to be added
        type: list
        elements: str
aÙ  
- name: Test that vsan module works
  cisco.nxos.nxos_vsan:
    vsan:
      - id: 922
        interface:
          - fc1/1
          - fc1/2
          - port-channel 1
        name: vsan-SAN-A
        remove: false
        suspend: false
      - id: 923
        interface:
          - fc1/11
          - fc1/21
          - port-channel 2
        name: vsan-SAN-B
        remove: false
        suspend: true
      - id: 1923
        name: vsan-SAN-Old
        remove: true
zñ
commands:
  description: commands sent to the device
  returned: always
  type: list
  sample:
    - terminal dont-ask
    - vsan database
    - vsan 922 interface fc1/40
    - vsan 922 interface port-channel 155
    - no terminal dont-ask
N)ÚAnsibleModule)Úload_configÚrun_commandsc                   ó   — e Zd Zd„ Zy)ÚVsanc                 óJ   — || _         d | _        d | _        d | _        g | _        y ©N)ÚvsanidÚvsannameÚ	vsanstateÚvsanoperstateÚvsaninterfaces)Úselfr   s     úh/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/cisco/nxos/plugins/modules/nxos_vsan.pyÚ__init__zVsan.__init__f   s'   € ØˆŒØˆŒØˆŒØ!ˆÔØ ˆÕó    N)Ú__name__Ú
__module__Ú__qualname__r   © r   r   r
   r
   e   s   „ ó!r   r
   c                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	ÚGetVsanInfoFromSwitchz#docstring for GetVsanInfoFromSwitchc                 ó`   — || _         i | _        | j                  «        | j                  «        y r   )ÚmoduleÚvsaninfoÚprocessShowVsanÚprocessShowVsanMembership)r   r   s     r   r   zGetVsanInfoFromSwitch.__init__q   s(   € ØˆŒØˆŒØ×ÑÔØ×&Ñ&Õ(r   c                 ó8   — t        d| j                  «      d   }|S )Nz	show vsanr   ©Úexecute_show_commandr   ©r   Úoutputs     r   Úexecute_show_vsan_cmdz+GetVsanInfoFromSwitch.execute_show_vsan_cmdw   s   € Ü% k°4·;±;Ó?ÀÑBˆØˆr   c                 ó8   — t        d| j                  «      d   }|S )Nzshow vsan membershipr   r"   r$   s     r   Úexecute_show_vsan_mem_cmdz/GetVsanInfoFromSwitch.execute_show_vsan_mem_cmd{   s   € Ü%Ð&<¸d¿k¹kÓJÈ1ÑMˆØˆr   c                 óH  — d}d}d}| j                  «       j                  d«      }|D ]G  }t        j                  ||j	                  «       «      }|r7|j                  d«      j	                  «       }t        |«      | j                  |<   t        j                  ||j	                  «       «      }|rf|j                  d«      j	                  «       }	|j                  d«      j	                  «       }
|	| j                     _        |
| j                  |   _	        t        j                  ||j	                  «       «      }|sŒ|j                  d«      j	                  «       }|| j                     _
        ŒJ t        d«      | j                  d<   t        d«      | j                  d<   y )	Nz^vsan\s+(\d+)\s+informationzname:(.*)state:(.*)zoperational state:(.*)ú
é   é   Ú4079Ú4094)r&   ÚsplitÚreÚmatchÚstripÚgroupr
   r   r   r   r   )r   ÚpatvÚpatnamestateÚpatoperstater%   ÚoÚzÚvÚz1ÚnÚsÚz2Úopers                r   r   z%GetVsanInfoFromSwitch.processShowVsan   sG  € Ø-ˆØ,ˆØ/ˆà×+Ñ+Ó-×3Ñ3°DÓ9ˆØó 	6ˆAÜ—‘˜˜qŸw™w›yÓ)ˆAÙØ—G‘G˜A“J×$Ñ$Ó&Ü#'¨£7—‘˜aÑ ä—‘˜,¨¯©«	Ó2ˆBÙØ—H‘H˜Q“K×%Ñ%Ó'Ø—H‘H˜Q“K×%Ñ%Ó'Ø,-—‘˜aÑ Ô)Ø-.—‘˜aÑ Ô*ä—‘˜,¨¯©«	Ó2ˆBÛØ—x‘x “{×(Ñ(Ó*Ø15—‘˜aÑ Ö.ð!	6ô& !% V£ˆ‰fÑÜ $ V£ˆ‰fÒr   c                 ór  — d}| j                  «       j                  d«      }g }d }|D ]y  }t        j                  ||j	                  «       «      }|r)||| j
                  |   _        g }|j                  d«      }d|vsŒW|j	                  «       j                  «       }||z   }Œ{ || j
                  |   _        y )Nz^vsan\s+(\d+).*r*   r+   Ú
interfaces)r(   r/   r0   r1   r2   r   r   r3   )r   r4   r%   Úmemlistr9   r7   r8   Úllists           r   r    z/GetVsanInfoFromSwitch.processShowVsanMembership›   s°   € Ø!ˆØ×/Ñ/Ó1×7Ñ7¸Ó=ˆØˆØˆØò 		*ˆAÜ—‘˜˜qŸw™w›yÓ)ˆAÙØ=Ø6=D—M‘M !Ñ$Ô3Ø GØ—G‘G˜A“JØ 1Ò$ØŸ™›	Ÿ™Ó)Ø! E™/‘ð		*ð +2ˆ‰aÑÕ'r   c                 ó   — | j                   S r   )r   )r   s    r   ÚgetVsanInfoObjectsz(GetVsanInfoFromSwitch.getVsanInfoObjects¬   s   € Ø}‰}Ðr   N)
r   r   r   Ú__doc__r   r&   r(   r   r    rD   r   r   r   r   r   n   s#   „ Ù-ò)òòò-ò82ó"r   r   c                 ó*   — d}| |dœg}t        ||«      S )NÚtext)Úcommandr%   )r   )rH   r   Úcommand_typer%   Úcommandss        r   r#   r#   °   s!   € Ø€FØ#¨vÑ6Ð7€HÜ˜ Ó)Ð)r   c                 ó~   — g }| D ]5  }t        |t        «      r|j                  |«       Œ%|j                  |«       Œ7 |S r   )Ú
isinstanceÚlistÚextendÚappend)Úcommand_listsÚflat_command_listrH   s      r   Úflatten_listrR   ¶   sE   € ØÐØ ò .ˆÜgœtÔ$Ø×$Ñ$ WÕ-à×$Ñ$ WÕ-ð	.ð
 Ðr   c            
      ó
  — t        t        dd¬«      t        d¬«      t        d¬«      t        d¬«      t        dd¬«      ¬	«      } t        t        dd
| ¬«      ¬«      }t        |d¬«      }t        «       }t        «       }t        «       }ddi}t        |«      }|j	                  «       }g }	|j
                  d   }
|
D ]Ñ  }t        |d   «      }|d   }|d   }|d   }|d   }t        |«      dk  st        |«      dk\  r|j                  |dz   ¬«       ||j                  «       v r0|}||   j                  }||   j                  }||   j                  }nd }d }d }g }|rŠ|dk(  s|dk(  r|j                  t        |«      dz   «       ŒË||k(  r;|	j                  dt        |«      z   «       |j                  dt        |«      z   «       n |j                  dt        |«      z   d z   «       Œ-|dk(  s|dk(  r|j                  t        |«      d!z   «       n`||k(  r!|j                  d"t        |«      z   d#z   «       n:|	j                  d$t        |«      z   «       |j                  d%t        |«      z   «       |š|dk(  s|dk(  r|j                  t        |«      d&z   «       nr||k(  r'|j                  d"t        |«      z   d'z   |z   d(z   «       nF|	j                  d$t        |«      z   d)z   |z   «       |j                  d*|z   d+z   t        |«      z   «       |rŒ|dk(  s|dk(  r|j                  t        |«      d,z   «       nÇ|d-k(  r!|j                  d"t        |«      z   d.z   «       n¡|	j                  d$t        |«      z   d/z   «       |j                  d0t        |«      z   «       nc|d1k(  r!|j                  d"t        |«      z   d2z   «       n=|	j                  dt        |«      z   d/z   «       |j                  d3t        |«      z   «       |€ŒF|D ]‡  }t        j                  d4d5|«      }||v r$|j                  |d6z   t        |«      z   d7z   «       ŒB|	j                  d$t        |«      z   d8z   |z   «       |j                  d9|z   d:z   t        |«      z   «       Œ‰ ŒÔ t!        |	«      d;k7  rd<gd=gz   |	z   d>gz   }	t#        |	«      }|}|r2|j$                  r|j'                  d|d?¬@«       nd|d<   t)        ||«       ||dA<   ||dB<   ||dC<    |j&                  dDi |¤Ž y )ENTÚint)ÚrequiredÚtypeÚstr)rV   ÚboolrM   )rV   Úelements)ÚidÚnameÚremoveÚsuspendÚ	interfaceÚdict)rV   rY   Úoptions)Úvsan)Úargument_specÚsupports_check_modeÚchangedFra   rZ   r[   r\   r]   r^   r+   iÿ  z: - This is an invalid vsan. Supported vsan range is 1-4094)Úmsgr-   r.   z, is a reserved vsan, hence cannot be removedzno vsan zdeleting the vsan zThere is no vsan z8 present in the switch. Hence there is nothing to deletez5 is a reserved vsan, and always present on the switchzThere is already a vsan z; present in the switch. Hence there is nothing to configurezvsan zcreating vsan z* is a reserved vsan, and cannot be renamedz+ present in the switch, which has the name z$ Hence there is nothing to configurez name zsetting vsan name to z
 for vsan z, is a reserved vsan, and cannot be suspendedÚ	suspendedz4 present in the switch, which is in suspended state z suspendzsuspending the vsan Úactivez1 present in the switch, which is in active state zno suspending the vsan z +Ú z  is already present in the vsan z interface listz interface zadding interface z	 to vsan r   zterminal dont-askzvsan databasezno terminal dont-askz'Check Mode: No cmds issued to the hosts)rd   rJ   re   ÚmessagesrJ   Úwarningsr   )r_   r   rM   r   rD   ÚparamsrW   rT   Ú	fail_jsonÚkeysr   r   r   rO   r0   ÚsubÚlenrR   Ú
check_modeÚ	exit_jsonr   )Úvsan_element_specrb   r   rj   ri   Úcommands_executedÚresultÚobjÚdictSwVsanObjsrJ   Ú	vsan_listÚeachvsanr   r   Ú
vsanremoveÚvsansuspendÚvsaninterface_listÚ	sw_vsanidÚsw_vsannameÚsw_vsanstateÚsw_vsaninterfacesÚeach_interface_nameÚtempÚcmdss                           r   Úmainrƒ   À   s‘  € ÜÜ˜ EÔ*ÜuÔÜ˜Ô Ü˜&Ô!Ü˜F¨UÔ3ôÐô Üv¨Ð8IÔJô€Mô ¨ÈDÔQ€FÜ‹v€HÜ‹v€HÜ›ÐØ˜Ð€Fä
 Ó
'€CØ×+Ñ+Ó-€Nà€HØ—‘˜fÑ%€Iàó {ˆÜX˜d‘^Ó$ˆØ˜FÑ#ˆØ˜hÑ'ˆ
Ø˜yÑ)ˆØ% kÑ2Ðäˆv‹;˜Š?œc &›k¨TÒ1Ø×ÑØÐYÑYð ô ð ^×(Ñ(Ó*Ñ*ØˆIØ(¨Ñ0×9Ñ9ˆKØ)¨&Ñ1×;Ñ;ˆLØ .¨vÑ 6× EÑ EÑàˆIØˆKØˆLØ "Ðáà˜Ò 6¨VÒ#3Ø—‘Ü˜“KÐ"PÑPôð Ø˜Ò"Ø—‘ 
¬S°«[Ñ 8Ô9Ø—‘Ð 4´s¸6³{Ñ BÕCà—‘Ø'Ü˜&“kñ"àPñQôñ
 ð ˜Ò 6¨VÒ#3Ø—‘Ü˜“KÐ"YÑYõð ˜YÒ&Ø—O‘OØ2Ü˜f›+ñ&àWñXõð —O‘O G¬c°&«kÑ$9Ô:Ø—O‘OÐ$4´s¸6³{Ñ$BÔCàÐà˜Ò 6¨VÒ#3Ø—‘Ü˜“KÐ"NÑNõð ˜{Ò*Ø—O‘OØ2Ü˜f›+ñ&àGñHð #ñ#ð Añ	Aõð —O‘O G¬c°&«kÑ$9¸HÑ$DÀxÑ$OÔPØ—O‘OØ/°(Ñ:¸\ÑIÌCÐPVËKÑWôñ à˜Ò 6¨VÒ#3Ø—‘Ü˜“KÐ"PÑPõð   ;Ò.Ø—O‘OØ2Ü˜f›+ñ&àPñQõð —O‘O G¬c°&«kÑ$9¸JÑ$FÔGØ—O‘OÐ$:¼SÀ»[Ñ$HÕIà˜xÒ'Ø—‘Ø.Ü˜&“kñ"àIñJõð —‘ 
¬S°«[Ñ 8¸:Ñ EÔFØ—‘Ð 9¼CÀ»KÑ GÔHàÒ)Ø'9ò Ð#ô —v‘v˜d BÐ(;Ó<ØÐ,Ñ,Ø—O‘OØ+Ø<ñ=ä˜f›+ñ&ð ,ñ,õð —O‘OØ¤# f£+Ñ-°Ñ=Ð@SÑSôð —O‘OØ+Ð.AÑAÀKÑOÔRUÐV\ÓR]Ñ]õòðU{ôz ˆ8ƒ}˜ÒØ'Ð(¨OÐ+<Ñ<¸xÑGÐKaÐJbÑbˆä˜Ó!€DØÐáØ×ÒØ×ÑØØ*Ø=ð õ ð !%ˆF9ÑÜ˜Ð 1Ô2à!€Fˆ:ÑØ*€Fˆ:ÑØ!€Fˆ:ÑØ€F×ÑÑvÓr   Ú__main__)Úcli_show)Ú
__future__r   r   r   ÚDOCUMENTATIONÚEXAMPLESÚRETURNr0   Úansible.module_utils.basicr   ÚEansible_collections.cisco.nxos.plugins.module_utils.network.nxos.nxosr   r   rV   Ú__metaclass__Úobjectr
   r   r#   rR   rƒ   r   r   r   r   ú<module>rŽ      sv   ð÷ AÑ @ð'€ðR€ð2
€ó 
å 4÷ð €ô!ˆ6ô !ô?˜Fô ?óD*òòjðZ ˆzÒÙ…Fð r   