
    Vh                         d dl mZmZmZ eZdZdZdZ	 d dl	m
Z
mZ d dlmZ d dlmZ d dlmZmZmZmZ d d	lmZ  G d
 de      Zd Zedk(  r e        yy# e$ r Y Aw xY w)    )absolute_importdivisionprint_functiona#  
---
module: vmware_dvswitch
short_description: Create or remove a Distributed Switch
description:
    - This module can be used to create, remove a Distributed Switch.
author:
- Joseph Callen (@jcpowermac)
- Abhijeet Kasurde (@Akasurde)
- Christian Kotte (@ckotte)
options:
    datacenter_name:
        description:
            - The name of the datacenter that will contain the Distributed Switch.
            - Required if O(folder) is not provided.
            - Mutually exclusive with O(folder) parameter.
        required: false
        aliases: ['datacenter']
        type: str
    switch_name:
        description:
        - The name of the distribute vSwitch to create or remove.
        required: true
        aliases: ['switch', 'dvswitch']
        type: str
    switch_version:
        description:
            - The version of the Distributed Switch to create.
            - The version must match the version of the ESXi hosts you want to connect.
            - The version of the vCenter server is used if not specified.
            - Required if O(state=present).
        aliases: ['version']
        type: str
    mtu:
        description:
            - The switch maximum transmission unit.
            - Required if O(state=present).
            - Accepts value between 1280 to 9000 (both inclusive).
        type: int
        default: 1500
    multicast_filtering_mode:
        description:
            - The multicast filtering mode.
            - 'V(basic) mode: multicast traffic for virtual machines is forwarded according to the destination MAC address of the multicast group.'
            - 'V(snooping) mode: the Distributed Switch provides IGMP and MLD snooping according to RFC 4541.'
        type: str
        choices: ['basic', 'snooping']
        default: 'basic'
    uplink_quantity:
        description:
            - Quantity of uplink per ESXi host added to the Distributed Switch.
            - The uplink quantity can be increased or decreased, but a decrease will only be successfull if the uplink isn't used by a portgroup.
            - Required if O(state=present).
        type: int
    uplink_prefix:
        description:
            - The prefix used for the naming of the uplinks.
            - Only valid if the Distributed Switch will be created. Not used if the Distributed Switch is already present.
            - Uplinks are created as Uplink 1, Uplink 2, etc. pp. by default.
        default: 'Uplink '
        type: str
    discovery_proto:
        description:
            - Link discovery protocol between Cisco and Link Layer discovery.
            - Required if O(state=present).
            - 'V(cdp): Use Cisco Discovery Protocol (CDP).'
            - 'V(lldp): Use Link Layer Discovery Protocol (LLDP).'
            - 'V(disabled): Do not use a discovery protocol.'
        choices: ['cdp', 'lldp', 'disabled']
        default: 'cdp'
        aliases: [ 'discovery_protocol' ]
        type: str
    discovery_operation:
        description:
            - Select the discovery operation.
            - Required if O(state=present).
        choices: ['both', 'advertise', 'listen']
        default: 'listen'
        type: str
    contact:
        description:
            - Dictionary which configures administrator contact name and description for the Distributed Switch.
        suboptions:
            name:
                type: str
                description: Administrator name.
            description:
                type: str
                description: Description or other details.
        type: dict
    description:
        description:
            - Description of the Distributed Switch.
        type: str
    health_check:
        description:
            - Dictionary which configures Health Check for the Distributed Switch.
        suboptions:
            vlan_mtu:
                type: bool
                description: VLAN and MTU health check.
                default: false
            teaming_failover:
                type: bool
                description: Teaming and failover health check.
                default: false
            vlan_mtu_interval:
                type: int
                description:
                - VLAN and MTU health check interval (minutes).
                - The default value is 1 in the vSphere Client if the VLAN and MTU health check is enabled.
                default: 0
            teaming_failover_interval:
                type: int
                description:
                - Teaming and failover health check interval (minutes).
                - The default value is 1 in the vSphere Client if the Teaming and failover health check is enabled.
                default: 0
        type: dict
        default: {
            vlan_mtu: false,
            teaming_failover: false,
            vlan_mtu_interval: 0,
            teaming_failover_interval: 0,
        }
    network_policy:
        description:
            - Dictionary which configures the different default security values for portgroups.
            - If set, these options are inherited by the portgroups of the DVS.
        suboptions:
            promiscuous:
                type: bool
                description: Indicates whether promiscuous mode is allowed.
                default: false
            forged_transmits:
                type: bool
                description: Indicates whether forged transmits are allowed.
                default: false
            mac_changes:
                type: bool
                description: Indicates whether mac changes are allowed.
                default: false
        required: false
        type: dict
    state:
        description:
            - If set to V(present) and the Distributed Switch does not exist, the Distributed Switch will be created.
            - If set to V(absent) and the Distributed Switch exists, the Distributed Switch will be deleted.
        default: 'present'
        choices: ['present', 'absent']
        type: str
    folder:
        description:
            - Destination folder, absolute path to place dvswitch in.
            - The folder should include the datacenter.
            - Required if O(datacenter) is not provided.
            - Mutually exclusive with O(datacenter) parameter.
            - 'Examples:'
            - '   folder: /datacenter1/network'
            - '   folder: datacenter1/network'
            - '   folder: /datacenter1/network/folder1'
            - '   folder: datacenter1/network/folder1'
            - '   folder: /folder1/datacenter1/network'
            - '   folder: folder1/datacenter1/network'
            - '   folder: /folder1/datacenter1/network/folder2'
        required: false
        type: str
    net_flow:
        description:
            - Dictionary which configures the Net Flow for the Distributed Switch.
        suboptions:
            collector_ip:
                type: str
                description: The IP Address (IPv4 or IPv6) of the NetFlow collector.
            collector_port:
                type: int
                description: The Port of the NetFlow collector.
                default: 0
            observation_domain_id:
                type: int
                description: Identifies the information related to the switch.
                default: 0
            switch_ip:
                type: str
                description:
                    - Assign an IP address to see the distributed switch as a single network device in the NetFlow collector.
                    - This is instead of as multiple devices corresponding to each host.
                    - In an IPv6 environment, the ESXi hosts ignore the switch IP address.
                version_added: '4.3.0'
            active_flow_timeout:
                type: int
                description: The time, in seconds, to wait before sending information after the flow is initiated.
                default: 60
            idle_flow_timeout:
                type: int
                description: The time, in seconds, to wait before sending information after the flow is initiated.
                default: 15
            sampling_rate:
                type: int
                description:
                    - The portion of data that the switch collects.
                    - The sampling rate represents the number of packets that NetFlow drops after every collected packet.
                    - If the rate is 0, NetFlow samples every packet, that is, collect one packet and drop none.
                    - If the rate is 1, NetFlow samples a packet and drops the next one, and so on.
                default: 4096
            internal_flows_only:
                type: bool
                description: If True, data on network activity between vms on the same host will be collected only.
                default: false
        type: dict
        default: {
            'collector_port': 0,
            'observation_domain_id': 0,
            'active_flow_timeout': 60,
            'idle_flow_timeout': 15,
            'sampling_rate': 4096,
            'internal_flows_only': false
        }
extends_documentation_fragment:
- community.vmware.vmware.documentation

a  
- name: Create dvSwitch
  community.vmware.vmware_dvswitch:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: '{{ datacenter }}'
    switch: dvSwitch
    version: 6.0.0
    mtu: 9000
    uplink_quantity: 2
    discovery_protocol: lldp
    discovery_operation: both
    state: present
  delegate_to: localhost

- name: Create dvSwitch with all options
  community.vmware.vmware_dvswitch:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: '{{ datacenter }}'
    switch: dvSwitch
    version: 6.5.0
    mtu: 9000
    uplink_quantity: 2
    uplink_prefix: 'Uplink_'
    discovery_protocol: cdp
    discovery_operation: both
    multicast_filtering_mode: snooping
    health_check:
      vlan_mtu: true
      vlan_mtu_interval: 1
      teaming_failover: true
      teaming_failover_interval: 1
    net_flow:
        collector_ip: 192.168.10.50
        collector_port: 50034
        observation_domain_id: 0
        switch_ip: 192.168.10.40
        active_flow_timeout: 60
        idle_flow_timeout: 15
        sampling_rate: 4096
        internal_flows_only: false
    state: present
  delegate_to: localhost

- name: Delete dvSwitch
  community.vmware.vmware_dvswitch:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter: '{{ datacenter }}'
    switch: dvSwitch
    state: absent
  delegate_to: localhost
aT  
result:
    description: information about performed operation
    returned: always
    type: str
    sample: {
        "changed": false,
        "contact": null,
        "contact_details": null,
        "description": null,
        "discovery_operation": "both",
        "discovery_protocol": "cdp",
        "dvswitch": "test",
        "health_check_teaming": false,
        "health_check_teaming_interval": 0,
        "health_check_vlan": false,
        "health_check_vlan_interval": 0,
        "net_flow_collector_ip": "192.168.10.50",
        "net_flow_collector_port": 50034,
        "net_flow_observation_domain_id": 0,
        "net_flow_switch_ip": "192.168.10.40",
        "net_flow_active_flow_timeout": 60,
        "net_flow_idle_flow_timeout": 15,
        "net_flow_sampling_rate": 4096,
        "net_flow_internal_flows_only": false,
        "mtu": 9000,
        "multicast_filtering_mode": "basic",
        "result": "DVS already configured properly",
        "uplink_quantity": 2,
        "uplinks": [
            "Uplink_1",
            "Uplink_2"
        ],
        "version": "6.6.0"
    }
)vimvmodl)AnsibleModule)	to_native)PyVmomi	TaskErrorfind_dvs_by_namewait_for_task)base_argument_specc                        e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
ed	        Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )VMwareDvSwitchz,Class to manage a Distributed Virtual Switchc                 
   t         t        |   |       d | _        | j                  j
                  d   | _        | j                  j
                  d   | _        | j                  Z| j                         }| j                  |vr<| j                  j                  d| j                  ddj                  |      d       | j
                  d   }|r`| j                  j                  j                  |      | _        | j                  s| j                  j                  d	| j
                  z         n^| j
                  j                  d
      }| j!                  |      }|s| j                  j                  d|z         |j"                  | _        | j                  j
                  d   | _        d| j$                  cxk  rdk  s+n | j                  j                  d| j$                  z         | j                  j
                  d   | _        | j                  j
                  d   | _        | j                  j
                  d   | _        | j                  j
                  d   | _        | j                  j
                  d   | _        | j
                  d   j                  d      | _        | j
                  d   j                  d      | _        | j
                  d   j                  d      | _        | j
                  d   j                  d      | _        | j
                  d   rG| j
                  d   j                  d      | _        | j
                  d   j                  d      | _        nd | _        d | _        | j                  j
                  d   | _        | j                  j
                  d   | _        | j>                  i | _        | j                  j
                  d   j                  d      xs d | _         | j                  j
                  d   j                  d       | _!        | j                  j
                  d   j                  d!      | _"        | j                  j
                  d   j                  d"      | _#        | j                  j
                  d   j                  d#      | _$        | j                  j
                  d   j                  d$      | _%        | j                  j
                  d   j                  d%      | _&        | j                  j
                  d   j                  d&      | _'        | j                  j
                  d'   | _(        y )(Nswitch_nameswitch_versionzUnsupported version 'z'. Supported versions are: , .msgfolderz1Failed to find the folder specified by %(folder)sdatacenter_namezIFailed to find datacenter '%s' required for managing distributed vSwitch.mtui   i(#  zHMTU value should be between 1280 and 9000 (both inclusive), provided %d.multicast_filtering_modeuplink_quantityuplink_prefixdiscovery_protodiscovery_operationhealth_checkvlan_mtuvlan_mtu_intervalteaming_failoverteaming_failover_intervalcontactnamedescriptionnetwork_policynet_flowcollector_ipcollector_portobservation_domain_id	switch_ipactive_flow_timeoutidle_flow_timeoutsampling_rateinternal_flows_onlystate))superr   __init__dvsmoduleparamsr   r   available_dvs_versions	fail_jsonjoincontentsearchIndexFindByInventoryPath
folder_objgetfind_datacenter_by_namenetworkFolderr   r   r   r   discovery_protocolr   health_check_vlanhealth_check_vlan_intervalhealth_check_teaminghealth_check_teaming_intervalcontact_namecontact_detailsr'   r(   netFlow_collector_ipnetFlow_collector_portnetFlow_observation_domain_idnetFlow_switch_ipnetFlow_active_flow_timeoutnetFlow_idle_flow_timeoutnetFlow_sampling_ratenetFlow_internal_flows_onlyr2   )selfr6   r8   r   r   datacenter_obj	__class__s         t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/vmware/plugins/modules/vmware_dvswitch.pyr4   zVMwareDvSwitch.__init__]  se   nd,V4;;--m<"kk001AB*%)%@%@%B"""*@@%%eiexexz~  {D  {D  E[  {\  +]%  ^X&"ll66JJ6RDO??%%*]`d`k`k*k%l"kkoo.?@O!99/JN!%% +OQ`+a% b,::DO;;%%e,txx'4'KK!!^aeaiaii "  )-(:(:;U(V%#{{112CD![[//@"&++"4"45F"G#';;#5#56K#L !%^!<!@!@!L*.++n*E*I*IJ]*^'$(KK$?$C$CDV$W!-1[[-H-L-LMh-i*;;y! $I 6 : :6 BD#';;y#9#=#=m#LD  $D#'D ;;--m<"kk001AB&"$D$(KK$6$6z$B$F$F~$V$^Z^!&*kk&8&8&D&H&HIY&Z#-1[[-?-?
-K-O-OPg-h*!%!3!3J!?!C!CK!P+/;;+=+=j+I+M+MNc+d()-););J)G)K)KL_)`&%)[[%7%7
%C%G%G%X"+/;;+=+=j+I+M+MNc+d([[''0
    c                     | j                   j                  }|j                  d      }g }|D ]  }|j                  |j                          |S )z,Get the DVS version supported by the vCenterT)recommended)r;   dvSwitchManagerQueryAvailableDvsSpecappendversion)rQ   dvs_mngavailable_dvs_specsr8   available_dvs_specs        rT   r8   z%VMwareDvSwitch.available_dvs_versions  sZ    ,,..%;;;M!#"5 	F"))*<*D*DE	F &%rU   c                 T   | j                   | j                  d| j                  | j                  dd}	  || j                     | j                                    y# t        j                  $ r9}| j                  j                  t        |j                               Y d}~yd}~wt        j                  $ r9}| j                  j                  t        |j                               Y d}~yd}~wt        $ r/}| j                  j                  t        |             Y d}~yd}~ww xY w)z$Process the current state of the DVS)presentabsent)ra   r`   r   N)destroy_dvswitchexit_unchangedupdate_dvswitchcreate_dvswitchr2   	check_dvsr   RuntimeFaultr6   r9   r	   r   MethodFault	Exception)rQ   
dvs_statesruntime_faultmethod_faultes        rT   process_statezVMwareDvSwitch.process_state  s      00--
  //..	

	44Jtzz"4>>#346!! 	DKK!!i0A0A&B!CC   	CKK!!i0@0@&A!BB 	4KK!!il!33	4s/   %A D'./B""D'8/C,,D'8%D""D'c                     t        | j                  | j                  | j                        | _        | j                  yy)zCheck if DVS is present)r   ra   r`   )r   r;   r   r>   r5   )rQ   s    rT   rf   zVMwareDvSwitch.check_dvs  s0    #DLL$2B2B4??[88rU   c                    d}t        |      }t        j                  j                         }t        j                  j
                  j                         |_        | j                  |d<   | j                  |j                  _	        | j                  |d<   | j                  |j                  _        | j                  |d<   | j                  |d<   | j                         |j                  _        | j                   |d<   | j"                  |d<   | j                   s| j"                  r| j%                         |j                  _        | j(                  |d	<   | j(                  r| j(                  |_        | j*                  |d
<   t        j                  j-                         |j                  _        t1        d| j*                  dz         D ]@  }|j                  j.                  j2                  j5                  d| j6                  |fz         B |j                  j.                  j2                  |d<   | j8                  |d<   | j8                  r | j;                  | j8                        |_        | j>                  j@                  rd}n"| jB                  }|jE                  |      }	 tG        |       tO        | jP                  | j                        | _        dx}	}
t        j                  j
                  j                         }| j                  jR                  jT                  |_*        | jV                  |d<   | jY                  | jV                        }| j                  jR                  jZ                  |k7  r	d}	||_-        | jY                  | jV                        |_-        | j\                  }d|v sd|v sd|v ri |d<   d|v r|d   |d   d<   d|v r|d   |d   d<   d|v r|d   |d   d<   | j_                         }|d   }
|
rM|j`                  -t        j                  j
                  jc                         |_0        |d   |j`                  _2        | jf                  x| jf                  |d<   | jh                  |d<   | jj                  |d<   | jl                  |d<   | jn                  |d<   | jp                  |d<   | jr                  |d <   | jt                  |d!<   | jw                         }|d"   }|r|d   |_<        |d   |_=        |	s|
s|r| j}                  | j                  |       | j~                  |d#<   | j                  |d$<   | j                  j                  |d%<   | j                  | j                  jR                  j                        }|d   }|r| j                  | j                  |d          d&}| j>                  j                  |tM        |      '       y# tH        $ r3}| j>                  jK                  dtM        |      z         Y d}~Wd}~ww xY w)(zCreate a DVSTchangeddvswitchr   rB   r   r%   rH   r'   r      %s%duplinksr[   zDVS would be createdzFailed to create DVS : %sr   NFr   promiscuousforged_transmitsmac_changesr(   r   net_flow_collector_ipnet_flow_collector_portnet_flow_observation_domain_idnet_flow_active_flow_timeoutnet_flow_idle_flow_timeoutnet_flow_sampling_ratenet_flow_internal_flows_onlynet_flow_switch_ip   rC   rE   uuidzDVS created)rr   result)Fdictr   DistributedVirtualSwitch
CreateSpecr5   VmwareDistributedVirtualSwitch
ConfigSpec
configSpecr   r&   r   maxMturB   r   create_ldp_speclinkDiscoveryProtocolConfigrG   rH   create_contact_specr%   r'   r   NameArrayUplinkPortPolicyuplinkPortPolicyrangeuplinkPortNamerZ   r   r   create_product_specproductInfor6   
check_moder>   CreateDVS_Taskr   r   r9   r	   r   r;   configconfigVersionr   get_api_mc_filtering_modemulticastFilteringModer(   check_network_policy_configdefaultPortConfigVmwarePortConfigPolicymacManagementPolicyrI   rJ   rK   rM   rN   rO   rP   rL   check_netFlow_configipfixConfigswitchIpAddressupdate_dvs_configrC   rE   r   check_health_check_confighealthCheckConfigupdate_health_check_config	exit_json)rQ   rr   resultsspeccountr   network_foldertaskinvalid_argumentchanged_multicastchanged_network_policyr   r(   changed_netFlowchanged_health_checks                  rT   re   zVMwareDvSwitch.create_dvswitch  sw   w'++668''@@KKM"..
#//!%(,(?(?$%)-)A)A%&6:6J6J6L3!..	%)%9%9!" 4 4&*&>&>&@DOO#!%!1!1#//D%)%9%9!"+.+G+G+a+a+c(1d22Q67 	iEOO,,;;BB6TM_M_afLgCgh	i!__==LL	!00	#778K8KLD;;!!+F "__N!006Dd# (d6F6FGDH9>> 67799DDFD!%!>!>D262O2OG./'+'E'EdFcFc'd$xx559QQ$(!.F+*.*H*HIfIf*gD'!00N.2D2VZgkyZy,.() N2?Mm?\G,-m<%7DRSeDfG,-.@A N2?Mm?\G,-m<99;)/&)--5141W1W1n1n1p.AGD**> ((4373L3L/0595P5P12<@<^<^89:>:Z:Z678<8V8V45484N4N01:>:Z:Z67040F0F,-..0F$QiO#)!9 '-ay$ $:o&&txx6 ,0+A+AG'(.2.G.GG*+"hhmmGFO33DHHOO4U4UVF#)!9 #//&)D"Fgi6GHE  %%3i@P6QQ &  s   W 	X(W<<Xc                     t         j                  j                         }| j                  dk(  rd|_        d|_        |S | j                  |_        | j                  |_        |S )z*Create Link Discovery Protocol config specdisabledcdpnone)r   hostLinkDiscoveryProtocolConfigrB   protocol	operationr   )rQ   ldp_config_specs     rT   r   zVMwareDvSwitch.create_ldp_spec6  s^    ((>>@""j0',O$(.O%  (,'>'>O$(,(@(@O%rU   c                 P    t         j                  j                         }||_        |S )zCreate product info spec)r   r5   ProductSpecr[   )rQ   r   product_info_specs      rT   r   z"VMwareDvSwitch.create_product_specA  s$    GG//1$2!  rU   c                     | dk(  ryy)zGet Multicast filtering modebasiclegacyFilteringsnooping )modes    rT   r   z(VMwareDvSwitch.get_api_mc_filtering_modeG  s     7?$rU   c                     t         j                  j                         }| j                  |_        | j
                  |_        |S )zCreate contact info spec)r   r   ContactInforG   r&   rH   r%   )rQ   contact_info_specs     rT   r   z"VMwareDvSwitch.create_contact_specN  s;    88DDF!%!2!2$($8$8!  rU   c                     	 |j                  |      }t        |       y# t        $ r2}| j                  j	                  dt        |      z         Y d}~yd}~ww xY w)zUpdate DVS configzFailed to update DVS : %sr   N)ReconfigureDvs_Taskr   r   r6   r9   r	   )rQ   switch_objectr   r   r   s        rT   r   z VMwareDvSwitch.update_dvs_configU  sY    	 44T:D$ 	KK!!/)<L2MM "  	s    	A(AAc                    dx}x}}d x}x}}| j                   j                  j                  }t        j                   j                  j                         }d| j                  v rR|j                  j                  | j                  d   k7  r,d}|j                  j                  }| j                  d   |_        d| j                  v rR|j                  j                  | j                  d   k7  r,d}|j                  j                  }| j                  d   |_	        d| j                  v rR|j                  j                  | j                  d   k7  r,d}|j                  j                  }| j                  d   |_
        |xs |xs |}	||	||||||fS )NFrw   Trx   ry   )r5   r   r   r   r   MacManagementPolicyr(   r   allowPromiscuousforgedTransmits
macChanges)
rQ   changed_promiscuouschanged_forged_transmitschanged_mac_changespromiscuous_previousforged_transmits_previousmac_changes_previouscurrent_configpolicyrr   s
             rT   r   z*VMwareDvSwitch.check_network_policy_config_  s   OTTT69LRVVV8;O::77KKMD///N4V4V4g4gkok~k~  @M  lN  5N"&#1#E#E#V#V &*&9&9-&HF#!4!449[9[9k9kos  pC  pC  DV  pW  :W'+$(6(J(J(Z(Z%%)%8%89K%LF"D///N4V4V4a4aeiexex  zG  fH  5H"&#1#E#E#P#P  $ 3 3M BF%X)AXEX!46JLd)+>@TV 	VrU   c           
         dx}x}x}x}}dx}}dx}	}
|D ]d  }t        |t        j                  j                  j                        r|j
                  | j                  k7  r!dx}}|j
                  }| j                  |_        |j
                  r:|j                  | j                  k7  r!dx}}|j                  }	| j                  |_        t        |t        j                  j                  j                        s|j
                  | j                  k7  r!dx}}|j
                  }| j                  |_        |j
                  s)|j                  | j                  k7  sDdx}}|j                  }
| j                  |_        g ||||||	||||
f
S )zCheck Health Check configFNr   T)
isinstancer   r5   r   VlanMtuHealthCheckConfigenablerC   intervalrD   TeamingHealthCheckConfigrE   rF   )rQ   health_check_configrr   changed_vlanchanged_vlan_intervalchanged_teamingchanged_teaming_intervalvlan_previousteaming_previousvlan_interval_previousteaming_interval_previousr   s               rT   r   z(VMwareDvSwitch.check_health_check_configy  s{   fkkk,k!6kKc+//(=>>!:) 	IF&#''"H"H"a"ab==D$:$::-11Gl$*MMM$($:$:FM==V__8W8W%W6::G3-3__*&*&E&EFO&#''"H"H"a"ab==D$=$==044Go'-}}$$($=$=FM==V__8Z8Z%Z9==G606-&*&H&HFO%	I& $WlMK`bx!13KMfh 	hrU   c                 n   	 |j                  |      }	 t               y# t        j                  j                  $ r2}| j                  j                  dt        |      z         Y d}~Wd}~wt        j                  j                  $ r2}| j                  j                  dt        |      z         Y d}~d}~wt        $ r2}| j                  j                  dt        |      z         Y d}~d}~ww xY w# t        $ r2}| j                  j                  dt        |      z         Y d}~yd}~ww xY w)zUpdate Health Check config)r   z#Update failed due to DVS fault : %sr   Nz-Health check not supported on the switch : %sz%Failed to configure health check : %sz)Failed to update health check config : %s)UpdateDVSHealthCheckConfig_Taskr   faultDvsFaultr6   r9   r	   r   NotSupportedr   r   )rQ   r   r   r   	dvs_faultnot_supportedr   s          rT   r   z)VMwareDvSwitch.update_health_check_config  s   	m @@Sf@gD	q$ yy!! 	dKK!!&KiXaNb&b!cc{{'' 	rKK!!&UXaboXp&p!qq 	mKK!!&MPYZjPk&k!ll	m  	qKK!!&QT]^nTo&o!pp	qsC   ! C9 C6(A++ C6(B88C6(C11C69	D4(D//D4c                 \   dx}x}x}x}x}x}x}x}}	dx}
x}x}x}x}x}x}}| j                   j                  j                  }|)t        j                   j                  j                         }n|}| j                   j                  j                  }|5t        j                   j                  j                         }|j                  }n|}| j                  |j                  | j                  k7  r!dx}}|j                  }
| j                  |_	        |j                  | j                  k7  r!dx}}|j                  }| j                  |_
        |j                  | j                  k7  r!dx}}|j                  }| j                  |_        |j                  | j                  k7  r!dx}}|j                  }| j                  |_        |j                   | j"                  k7  r!dx}}|j                   }| j"                  |_        |j$                  | j&                  k7  r!dx}}|j$                  }| j&                  |_        |j(                  | j*                  k7  r!dx}}|j(                  }| j*                  |_        | j,                  !|| j,                  k7  rdx}}	|}| j,                  }|||||
|||||||||||||	|fS )zCheck NetFlow configFNT)r5   r   r   r   r   IpfixConfigr   r   rI   collectorIpAddresscollectorPortrJ   observationDomainIdrK   activeFlowTimeoutrM   idleFlowTimeoutrN   samplingRaterO   internalFlowsOnlyrP   rL   )rQ   rr   changed_collectorIpAddresschanged_collectorPortchanged_observationDomainIdchanged_activeFlowTimeoutchanged_idleFlowTimeoutchanged_samplingRatechanged_internalFlowsOnlychanged_switchIpAddresscollectorIpAddress_previouscollectorPort_previousobservationDomainId_previousactiveFlowTimeout_previousidleFlowTimeout_previoussamplingRate_previousinternalFlowsOnly_previousswitchIpAddress_previousr   
new_configcurrent_switchIpAddressnew_config_specnew_switchIpAddresss                          rT   r   z#VMwareDvSwitch.check_netFlow_config  s    ',	, 	,, 	,/D 	,Gb 	,%	,(?	,BV	,Yr#w{	|# 	|&< 	|?[ 	|^x 	|$	|'<	|?Y\t44!??KKMJ'J"&((//"A"A"*!ggDDOOQO"1"A"A"9$$000D4M4MM7;;4.<.O.O+040I0I
-++t/J/JJ266/)7)E)E&+/+F+F
(11T5W5WW8<<5/=/Q/Q,151S1S
.//43S3SS6::3-;-M-M*/3/O/O
,--1O1OO4881+9+I+I(-1-K-K
***d.H.HH155.(6(C(C%*.*D*D
'//43S3SS6::3-;-M-M*/3/O/O
,%%16MQUQgQg6g4881+B(&*&<&<#/:TVq%'=?Z\x)+EG^`x$&;=VXr')A	C 	CrU   c                     d}t        |      }| j                  |d<   d|d<    | j                  j                  di | y)zExit with status messageFrq   rs   zDVS not presentr   Nr   )r   r   r6   r   )rQ   rr   r   s      rT   rc   zVMwareDvSwitch.exit_unchanged  sB    w'"..
-((rU   c                    d}t        |      }| j                  |d<   | j                  j                  rd|d<   n+	 | j                  j                         }t               d	|d<    | j                  j                  d
i | y# t        j                  j                  $ r2}| j                  j                  dt        |      z         Y d}~wd}~ww xY w)zDelete a DVSTrq   rs   zDVS would be deletedr   zFailed to deleted DVS : %sr   NzDVS deletedr   )r   r   r6   r   r5   Destroy_Taskr   r   VimFaultr9   r	   r   r   )rQ   rr   r   r   	vim_faults        rT   rb   zVMwareDvSwitch.destroy_dvswitch  s    w'"..
;;!! 6GH_xx,,. $ -GH((	 99%% _%%*FS\I]*]%^^_s   B C(CCc                    dx}x}x}x}x}x}}t        |      }| j                  |d<   g }	d}
t        j                  j                  j                         }| j                  j                  j                  |_        | j                  |d<   | j                  j                  j                  | j                  k7  r5dx}}|	j                  d       |j                  |d<   | j                  |_	        | j                  j                  j                  j                  }| j                  j                  j                  j                  }| j                  dk(  r+| j                  |d	<   d
|d<   |dk7  s|dk7  rsd}||d<   ||d<   nf| j                  |d	<   | j                  |d<   || j                  k7  s|| j                  k7  r*d}|| j                  k7  r||d<   || j                  k7  r||d<   |r*dx}}|	j                  d       | j!                         |_        | j"                  |d<   | j%                  | j"                        }| j                  j                  j&                  |k7  r?dx}}|	j                  d       | j                  j                  j&                  |d<   ||_        | j(                  |d<   | j*                  |d<   | j                  j                  j,                  j.                  | j(                  k7  s7| j                  j                  j,                  j,                  | j*                  k7  rdx}}|	j                  d       | j                  j                  j,                  j.                  |d<   | j                  j                  j,                  j,                  |d<   | j1                         |_        | j2                  |d<   | j                  j                  j2                  | j2                  k7  r]dx}}|	j                  d       | j                  j                  j2                  |d<   | j2                  d|_        n| j2                  |_        | j4                  |d<   t7        | j                  j                  j8                  j:                        | j4                  k7  rdx}}|	j                  d       t7        | j                  j                  j8                  j:                        |d<   t        j<                  j?                         |_        t7        | j                  j                  j8                  j:                        | j4                  k  rRtA        d| j4                  dz         D ]6  }|j8                  j:                  j                  d| jB                  |fz         8 t7        | j                  j                  j8                  j:                        | j4                  kD  rRtA        d| j4                  dz         D ]6  }|j8                  j:                  j                  d| jB                  |fz         8 |j8                  j:                  |d <   | j                  j                  j8                  j:                  |d!<   n-| j                  j                  j8                  j:                  |d <   | jD                  |d"<   | jF                  |d#<   | jH                  |d$<   | jJ                  |d%<   | jM                  | j                  j                  jN                        \
  }}}}}}}}}}|r/d}|	j                  d&       |r||d'<   |r||d(<   |r||d)<   |r||d*<   d+| jP                  v sd,| jP                  v sd-| jP                  v ri |d.<   d+| jP                  v r| jP                  d+   |d.   d+<   d,| jP                  v r| jP                  d,   |d.   d,<   d-| jP                  v r| jP                  d-   |d.   d-<   | jS                         \  }}}}}}}}|rdx}}|	j                  d/       i |d0<   |r||d0   d+<   |r||d0   d,<   |r||d0   d-<   |jT                  -t        j                  j                  jW                         |_*        ||jT                  _,        d} | jZ                  rd| jZ                  |d1<   | j                  j                  j\                  j^                  | jZ                  k7  rMd}| ja                  | jZ                        } n/| j                  j                  j\                  j^                  |d1<   d}|r@d}|	j                  d2       | j                  j                  j\                  j^                  |d3<   | jb                  x| jb                  |d4<   | jd                  |d5<   | jf                  |d6<   | jh                  |d7<   | jj                  |d8<   | jl                  |d9<   | jn                  |d:<   | jp                  |d;<   | js                         \  }!}"}}#}$}%}&}'}(})}*}+},}-}.}/}0}1}2|r[dx}}|	j                  d<       |#r|$|d=<   |%r|&|d><   |'r|(|d?<   |)r|*|d@<   |+r|,|dA<   |-r|.|dB<   |/r|0|dC<   |1r|2|dD<   |!|_:        |"|_;        |r| jx                  jz                  rdE}3ndF}3t7        |	      dGkD  r'dHj}                  |	ddI       dJz   t        |	dI         z   }
n3t7        |	      dGk(  rdKj}                  |	      }
nt7        |	      dk(  r|	dL   }
|
|3z  }
| jx                  jz                  si|r| j                  | j                  |       |r| j                  | j                  |       |r+| j                  j                  dM|       }4	 t        |4       ndP}
| j                  j                  |dQ<   ||dR<   |
|dS<    | jx                  j                  dTi | y# t        $ r2}5| jx                  j                  dNt        |5      z  O       Y d}5~5vd}5~5ww xY w)UzCheck and update DVS settingsFrq   rs    r   Tmtu_previousr   rB   zn/ar   r   r   discovery_protocol_previousdiscovery_operation_previouszdiscovery protocolr   zmulticast filtering!multicast_filtering_mode_previousr%   rH   contact_previouscontact_details_previousr'   description_previousNr   zuplink quantityuplink_quantity_previousrt   ru   rv   uplinks_previousrC   rE   rD   rF   zhealth checkhealth_check_vlan_previous#health_check_vlan_interval_previoushealth_check_teaming_previous&health_check_teaming_interval_previousrw   rx   ry   r(   znetwork policynetwork_policy_previousr[   zswitch versionversion_previousrz   r{   r|   r}   r~   r   r   r   netFlownet_flow_collector_ip_previous net_flow_collector_port_previous'net_flow_observation_domain_id_previous%net_flow_active_flow_timeout_previous#net_flow_idle_flow_timeout_previousnet_flow_sampling_rate_previous%net_flow_internal_flows_only_previousnet_flow_switch_ip_previousz would be changedz changedr   r   z, and z and r   upgradez!Failed to update DVS version : %sr   zDVS already configured properlyr   rr   r   r   )Ir   r   r   r5   r   r   r   r   r   r   rZ   r   r   r   rB   r   r   r   r   r   rG   rH   r%   r&   r   r'   r   lenr   r   r   r   r   r   rC   rE   rD   rF   r   r   r(   r   r   r   r   r   r   r[   r   rI   rJ   rK   rM   rN   rO   rP   rL   r   r   r   r6   r   r:   strr   r   #PerformDvsProductSpecOperation_Taskr   r   r9   r	   r   r   )6rQ   rr   changed_settingschanged_ldpchanged_versionr   r   r   r   changed_listmessageconfig_specldp_protocolldp_operationr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   spec_productr   switchIpAddress_netFlowr   r   r   r   r   r   r   r   r   r  r   r  r   r  r   r  changed_suffixr   r   s6                                                         rT   rd   zVMwareDvSwitch.update_dvswitch  s    HM  	M  	M"  	M[  	M?  	MEY  	M\r  vEw'"..
gg<<GGI$(HHOO$A$A! 88??!!TXX-)--G&&&1&8&8GN#!%K xxBBKKCCMM""j0,0,C,CG()-2G)*u$(?"9E56:G67,0,C,CG()-1-E-EG)*t666-4KcKc:c"4#:#::=IG9: D$<$<<>KG:;)--G& 456:6J6J6LK3 /3.K.K*+#'#A#A$B_B_#` 88??115MM)--G& 56;?88??;a;aG781IK. "..	%)%9%9!"88??""''4+<+<<@W@W@_@_cgcwcw@w)--G&	**.((//*A*A*F*FG&'26((//2I2I2Q2QG./"&":":"<K "&!1!188??&&$*:*::)--G&..2hhoo.I.IG*+'*,'*.*:*:' &*%9%9!"txx//>>?4CWCWW)--G& 1225dhhoo6V6V6e6e2fG./+.+G+G+a+a+cK(488??33BBCdFZFZZ"1d&:&:Q&>? mE00??FFvQUQcQcejPkGklm 488??33BBCdFZFZZ"1d&:&:Q&>? mE00??FFvQUQcQcejPkGklm!,!=!=!L!LGI*.((//*J*J*Y*YG&' "&!A!A!P!PGI (,'='=#$*.*C*C&'040O0O,-373U3U/0 **488??+L+LM	>	2L-	 6IY	!#<G/8E45$AW=>;K78'D]@A D///3EI\I\3\`mqu  rE  rE  aE(*G$% 3 33;?;N;N};]()-8!T%8%88@D@S@STf@g()*<= 3 33;?;N;N};]()-8 002SV+-@BVXp&(;=Q &-11*##$455712&H\G56}E+MfG567IJ&H\G56}E00847GG4Z4Z4q4q4sK1DJ--A !%!4!4GIxx**22d6I6II"&#778K8KL!%!<!<!D!DGI#OG 01*.((//*E*E*M*MG&' $$0/3/H/HG+,151L1LG-.8<8Z8ZG456:6V6VG23484R4RG01040J0JG,-6:6V6VG23,0,B,BG()
 vz  vO  vO  vQ	s-@Z\w	 68SUq  tM	#%<>VXl  oD	"$>@WYq)--G&	*)<W89$>T:;*EaAB(C]?@&AY=>#=R9:(C]?@&9Q56&1K#*AK'{{%%!4!+< 1$))L"$56ACUWHXDYY\"a'!,,|4\"a'&q/~%G;;))#**488[A'33DHH>QR"88GG	S_`Du%d+ 8G((--$	#(( % u--2UXabrXs2s-ttus   n& &	o!/(oo!)__name__
__module____qualname____doc__r4   r8   rn   rf   re   r   r   staticmethodr   r   r   r   r   r   r   rc   rb   rd   __classcell__)rS   s   @rT   r   r   Z  st    6>1@	&4,oIb	!  !V4h6q:Cx))"g)rU   r   c                     t               } | j                  t        d<i dt        dg      dt               dt        dddg	      d
t        dd      dt        ddddg      dt        ddgd      dt        d      dt        dd      dt        dg dddg      d t        dg d!d"#      d$t        d%t        t        d&d'      t        d&d'      t        dd(      t        dd(      )      t        d'd'd(d()      *      d+t        d%t        t        d      t        d      ,      -      d.t        d      d/t        d0d0d1g2      d3t        d%t        t        d&d'      t        d&d'      t        d&d'      4      -      d5t        d%t        t        d      t        dd(      t        dd(      t        d      t        dd6      t        dd7      t        dd8      t        d&d'      9      t        d(d(d6d7d8d':      *             t        | d/d0dgfgddggddggd;      }t	        |      }|j                          y)=Mainr   
datacenter)aliasesr   r   Tswitchrs   )requiredrA  r   inti  )typedefaultr   r+  r   r   )rE  rF  choicesr   r[   N)rE  rA  rF  r   )rE  r   zUplink r   )r   lldpr   r   rB   )rE  rG  rF  rA  r   )both	advertiselistenrK  )rE  rG  rF  r    r   boolFr   )r!   r#   r"   r$   )rE  optionsrF  r%   )r&   r'   )rE  rM  r'   r2   r`   ra   )rF  rG  r(   )rw   rx   ry   r)   <      i   )r*   r+   r,   r-   r.   r/   r0   r1   )r+   r,   r.   r/   r0   r1   )argument_specrequired_ifrequired_one_ofmutually_exclusivesupports_check_moder   )r   updater   r   r   rn   )rP  r6   vmware_dvswitchs      rT   mainrW    s   &(M F	
 ,8F	
6F	
 dXz4JKF	
 %.	F	

 &*ugPWYcOd%eF	
  "F	
 !e,F	
 E9=F	
 !$?YmXnF	
  !%%9Xbj k!F	
" !vu=%)vu%E&*q&A.2q.I	 "%*&'./	#F	
@ 5) $% 0AF	
N %(OF	
P y9h2GHQF	
R   $&% @%)vu%E $&% @SF	
b !%5!1#'UA#>*.E1*E".(,%(D&*r&B"&E4"@(,&%(H	 #$*+(*&("&(-cF	
HT #i "

 ()
 ()
 !F %V,O!!#rU   __main__N)
__future__r   r   r   rE  __metaclass__DOCUMENTATIONEXAMPLESRETURNpyVmomir   r   ImportErroransible.module_utils.basicr   ansible.module_utils._textr	   @ansible_collections.community.vmware.plugins.module_utils.vmwarer
   r   r   r   Hansible_collections.community.vmware.plugins.module_utils._argument_specr   r   rW  r8  r   rU   rT   <module>rd     s    A @]~8t#
J	" 5 0  hE
)W E
)P]$@ zF g  		s   A AA