
    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mZmZ d dlmZ d d	lmZ  G d
 de      Zd Zedk(  r e        yy# e$ r Y ?w xY w)    )absolute_importdivisionprint_functiona  
---
module: vmware_cluster
short_description: Manage VMware vSphere clusters
description:
    - Adds or removes VMware vSphere clusters.
    - To manage DRS, HA and VSAN related configurations, use the modules vmware_cluster_drs, vmware_cluster_ha and vmware_cluster_vsan.
author:
- Joseph Callen (@jcpowermac)
- Abhijeet Kasurde (@Akasurde)
deprecated:
  removed_in: 6.0.0
  why: This module has been moved to the L(new vmware.vmware collection,https://forum.ansible.com/t/5880)
  alternative: Use M(vmware.vmware.cluster) instead.
options:
    cluster_name:
      description:
      - The name of the cluster to be managed.
      type: str
      required: true
    datacenter:
      description:
      - The name of the datacenter.
      type: str
      required: true
      aliases: [ datacenter_name ]
    state:
      description:
      - Create V(present) or remove V(absent) a VMware vSphere cluster.
      choices: [ absent, present ]
      default: present
      type: str
seealso:
- module: community.vmware.vmware_cluster_drs
- module: community.vmware.vmware_cluster_ha
- module: community.vmware.vmware_cluster_vsan
extends_documentation_fragment:
- community.vmware.vmware.documentation

a  
- name: Create Cluster
  community.vmware.vmware_cluster:
    hostname: '{{ vcenter_hostname }}'
    username: '{{ vcenter_username }}'
    password: '{{ vcenter_password }}'
    datacenter_name: datacenter
    cluster_name: cluster
  delegate_to: localhost

- name: Delete Cluster
  community.vmware.vmware_cluster:
    hostname: "{{ vcenter_hostname }}"
    username: "{{ vcenter_username }}"
    password: "{{ vcenter_password }}"
    datacenter_name: datacenter
    cluster_name: cluster
    state: absent
  delegate_to: localhost
z#
)vimvmodl)AnsibleModule)PyVmomifind_datacenter_by_namewait_for_task)base_argument_spec)	to_nativec                   <     e Zd Z fdZd Zd Zd Zd Zd Z xZ	S )VMwareClusterc                     t         t        |   |       |j                  d   | _        |j                  d   | _        |j                  d   | _        d | _        d | _        y )Ncluster_name
datacenterstate)	superr   __init__paramsr   datacenter_namedesired_stater   cluster)selfmodule	__class__s     s/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/vmware/plugins/modules/vmware_cluster.pyr   zVMwareCluster.__init__]   sS    mT+F3"MM.9%}}\:#]]73    c                     | j                   | j                  d| j                  | j                  dd}| j                         } || j                     |           y)z3
        Manage internal states of cluster
        )presentabsent)r!   r    N)state_destroy_clusterstate_exit_unchangedstate_create_clustercheck_cluster_configurationr   )r   cluster_statescurrent_states      r   process_statezVMwareCluster.process_statee   se      5533
  4433	
 88: 	:t))*=9;r   c           	         	 t         j                  j                         }| j                  j                  s0| j
                  j                  j                  | j                  |       | j                  j                  d       y# t        j                  j                  $ r<}| j                  j                  dt        |j                        z         Y d}~yd}~wt         j                  j                   $ rI}| j                  j                  d| j                  dt        |j                               Y d}~yd}~wt        j                  j"                  $ r<}| j                  j                  dt        |j                        z         Y d}~yd}~w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(        $ r2}| j                  j                  d	t        |      z         Y d}~yd}~ww xY w)
z9
        Create cluster with given configuration
        Tchangedz=Cluster configuration specification parameter is invalid : %smsgN'z%' is an invalid name for a cluster : z=Trying to create a cluster on an incorrect folder object : %sz4Failed to create cluster due to generic exception %s)r   r   ConfigSpecExr   
check_moder   
hostFolderCreateClusterExr   	exit_jsonr   faultInvalidArgument	fail_jsonr   r-   InvalidNameNotSupportedRuntimeFaultMethodFault	Exception)r   cluster_config_specinvalid_argsinvalid_namenot_supportedruntime_faultmethod_faultgeneric_excs           r   r$   z"VMwareCluster.state_create_clusterx   s   	_"%++":":"<;;))**::4;L;LNabKK!!$!/{{** 	bKK!! 'CEN|O_O_E`'a! b byy$$ 	WKK!!9=9J9J9B<CSCS9T'V! W W {{'' 	\KK!! '<>GHYHY>Z'[! \ \!! 	DKK!!i0A0A&B!CC   	CKK!!i0@0@&A!BB 	_KK!! 'EGPQ\G]'^! _ _	_sT   B B I$ 2C I$7?D;; I$2FI$(/GI$2/H&&I$2(II$c                    d\  }}	 | j                   j                  s(| j                  j                         }t	        |      \  }}| j                   j                  ||       y# t        j                  j                  $ r9}| j                   j                  t        |j                               Y d}~yd}~w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        $ r2}| j                   j                  dt        |      z         Y d}~yd}~ww xY w)z!
        Destroy cluster
        )TN)r+   resultr,   Nz5Failed to destroy cluster due to generic exception %s)r   r0   r   Destroy_Taskr   r3   r   r4   VimFaultr6   r   r-   r   r9   r:   r;   )r   r+   rD   task	vim_faultr@   rA   rB   s           r   r"   z#VMwareCluster.state_destroy_cluster   s5    %	_;;))||002"/"5KK!!'&!Ayy!! 	@KK!!i	&>!??!! 	DKK!!i0A0A&B!CC   	CKK!!i0@0@&A!BB 	_KK!! 'EGPQ\G]'^! _ _	_s<   AA# #F /B44F
/C>>F/EF(FFc                 <    | j                   j                  d       y)z)
        Exit without any change
        Fr*   N)r   r3   )r   s    r   r#   z"VMwareCluster.state_exit_unchanged   s     	e,r   c                    	 t        | j                  | j                        | _        | j                  )| j                  j                  d| j                  z         | j                  | j                  | j                        | _        | j                  y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        $ r2}| j                  j                  dt        |      z         Y d}~yd}~ww xY w)zj
        Check cluster configuration
        Returns: 'Present' if cluster exists, else 'absent'

        NzDatacenter %s does not exist.r,   )r   r   r!   r    z9Failed to check configuration due to generic exception %s)r
   contentr   r   r   r6   find_cluster_by_namer   r   r   r9   r   r-   r:   r;   )r   r@   rA   rB   s       r   r%   z)VMwareCluster.check_cluster_configuration   s(   	_5dllDDXDXYDO&%%*IDL`L`*`%a44$BSBSeietet4uDL||#!! 	DKK!!i0A0A&B!CC   	CKK!!i0@0@&A!BB 	_KK!! 'EGPQ\G]'^! _ _	_s0   BB E%)/CE%3/D''E%3(E  E%)
__name__
__module____qualname__r   r(   r$   r"   r#   r%   __classcell__)r   s   @r   r   r   \   s$    <&_:_*-_r   r   c                      t               } | j                  t        t        dd      t        dddg      t        ddddg      	             t        | d
      }t	        |      }|j                          y )NstrT)typerequiredr   )rS   rT   aliasesr    r!   )rS   defaultchoices)r   r   r   )argument_specsupports_check_mode)r   updatedictr   r   r(   )rX   r   vmware_clusters      r   mainr]      sx    &(Mut4UT<M;NO$$i02  # F
 #6*N  "r   __main__N)
__future__r   r   r   rS   __metaclass__DOCUMENTATIONEXAMPLESRETURNpyVmomir   r   ImportErroransible.module_utils.basicr   @ansible_collections.community.vmware.plugins.module_utils.vmwarer	   r
   r   Hansible_collections.community.vmware.plugins.module_utils._argument_specr   ansible.module_utils._textr   r   r]   rM    r   r   <module>rk      s    A @'R*
	" 5  h 0j_G j_Z#& zF Y  		s   A AA