
    VhC                         d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZmZ  G d de      Zd	 Zd
 Zedk(  r e        yy)    )absolute_importdivisionprint_functiona  
module: proxmox_cluster
version_added: 1.0.0
short_description: Create and join Proxmox VE clusters
description:
  - Create and join Proxmox VE clusters with PVE nodes.
author: Florian Paul Azim Hoberg (@gyptazy)
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  link0:
    description:
      - The first IP address to use for cluster communication.
    type: str
    required: false
  link1:
    description:
      - The second IP address to use for cluster communication.
    type: str
    required: false
  master_ip:
    description:
      - The IP address of the cluster master when joining the cluster.
    type: str
    required: false
  fingerprint:
    description:
      - The fingerprint of the cluster master when joining the cluster.
    type: str
    required: false
  cluster_name:
    description:
      - The cluster name to use for cluster creation.
    type: str
    required: false
  state:
    description:
      - Possible module state to perform the required steps within the Proxmox VE API.
    choices: ["present"]
    type: str
extends_documentation_fragment:
  - community.proxmox.proxmox.actiongroup_proxmox
  - community.proxmox.proxmox.documentation
  - community.proxmox.attributes
a)  
- name: Create a Proxmox VE Cluster
  community.proxmox.proxmox_cluster:
    state: present
    api_host: proxmoxhost
    api_user: root@pam
    api_password: password123
    api_ssl_verify: false
    link0: 10.10.1.1
    link1: 10.10.2.1
    cluster_name: "devcluster"

- name: Join a Proxmox VE Cluster
  community.proxmox.proxmox_cluster:
    state: present
    api_host: proxmoxhost
    api_user: root@pam
    api_password: password123
    master_ip: "{{ primary_node }}"
    fingerprint: "{{ cluster_fingerprint }}"
    cluster_name: "devcluster"
z
cluster:
  description: The name of the cluster that was created or joined.
  returned: success
  type: str
  sample: "devcluster"
)AnsibleModule)proxmox_auth_argument_specProxmoxAnsiblec                       e Zd Zd Zd Zy)ProxmoxClusterAnsiblec                 t   | j                   j                  j                  d      xs% | j                   j                  j                  d      }d|i}| j                   j                  j                  d      (| j                   j                  j                  d      |d<   | j                   j                  j                  d      (| j                   j                  j                  d      |d<   | j                   j                  r| j                  j
                  j                  j                  j                         }t        |      dkD  r| j                   j                  d       n-| j                   j                  d	d
j                  |      |       	  | j                  j
                  j                  j                  di | | j                   j                  d	dj                  |      |       y # t        $ r>}| j                   j                  dj                  t        |                   Y d }~pd }~ww xY w)Ncluster_nameapi_hostclusternamelink0link1r   z@Error while creating cluster: Node is already part of a cluster!msgTz+Cluster '{}' would be created (check mode).changedr   clusterz Error while creating cluster: {}zCluster '{}' created. )moduleparamsget
check_modeproxmox_apir   confignodeslen	fail_json	exit_jsonformatpost	Exceptionstr)selfr   payloadcluster_objectses        u/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/proxmox/plugins/modules/proxmox_cluster.pycluster_createz$ProxmoxClusterAnsible.cluster_createb   s   {{))--n=cASASAWAWXbAc ,/;;!!'*6#{{1155g>GG;;!!'*6#{{1155g>GG;;!!"..66==CCGGIO?#a'%%*l%m%%d8e8l8lmy8z  EQ%  R	Y0D$$++00;7; 	d0G0N0N|0\frs  	YKK!!&H&O&OPSTUPV&W!XX	Ys   0G0 0	H794H22H7c                    | j                   j                  j                  d      }| j                   j                  j                  d      }| j                   j                  j                  d      }| j                   j                  j                  d      }d}| j                   j                  r| j                  j
                  j                  j                         }|d   }|j                  d      }|dk(  rd}|r| j                   j                  d	
       n-| j                   j                  ddj                  |      |       	 | j                  j
                  j                  j                  j                  |||       | j                   j                  dd|       y # t        $ r>}| j                   j                  dj                  t        |            
       Y d }~ad }~ww xY w)N	master_ipfingerprintapi_passwordr   Tr   nodeidFz?Error while joining cluster: Node is already part of a cluster!r   z.Node would join the cluster '{}' (check mode).r   )hostnamer-   passwordz#Error while joining the cluster: {}zNode joined the cluster.)r   r   r   r   r   r   statusr   r    r!   r   joinr"   r#   r$   )	r%   r,   r-   r.   r   is_in_clusterr'   
cluster_idr(   s	            r)   cluster_joinz"ProxmoxClusterAnsible.cluster_joiny   s   KK&&**;7	kk((,,];{{))--n={{))--n=;;!!"..66==AACO-a0O(,,X6JQ %%%*k%l%%d8h8o8op|8}  HT%  U	\$$++0055"'% 6  	d0JT`a  	\KK!!&K&R&RSVWXSY&Z![[	\s   <F   	G')4G""G'N)__name__
__module____qualname__r*   r6   r       r)   r
   r
   a   s    t.br:   r
   c                      t               S )N)dictr   r:   r)   'proxmox_cluster_join_info_argument_specr=      s	    6Mr:   c            
      F   t               } t        t        d dg      t        d      t        d      t        d      t        d      t        d            }| j                  |       t        | dgdgd	      }t        d
      }t	        |      }|j
                  j                  d      dk(  rX|j
                  j                  d      r,|j
                  j                  d      r|j                         }n|j                         }ni }||d<    |j                  di | y )Npresent)defaultchoicesr$   )type)stater   r   r   r,   r-   )r.   api_token_id)rD   api_token_secretT)argument_specrequired_one_ofrequired_togethersupports_check_modeF)r   rC   r,   r-   proxmox_clusterr   )
r   r<   updater   r
   r   r   r6   r*   r    )module_argscluster_argsr   resultproxmoxcluster_actions         r)   mainrQ      s
   ,.K4)5u%E"e$L |$!9:?@ 	F F $F+G
 }}!Y.==[)fmm.?.?.N$113N$335N .FFvr:   __main__N)
__future__r   r   r   rB   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   Bansible_collections.community.proxmox.plugins.module_utils.proxmoxr   r   r
   r=   rQ   r7   r   r:   r)   <module>rZ      sa    A @/b.
 506bN 6br&R zF r:   