
    Vh                         d dl mZmZmZ eZdZdZd dlZdZ		 d dl
Z
dZd dlmZmZ d dlmZ  G d	 d
e      Z G d de      ZddZd Zd Zd Zedk(  r e        yy# e$ r  ej                         Z	dZY Yw xY w)    )absolute_importdivisionprint_functiona  
module: vertica_configuration
short_description: Updates Vertica configuration parameters
description:
  - Updates Vertica configuration parameters.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  parameter:
    description:
      - Name of the parameter to update.
    required: true
    aliases: [name]
    type: str
  value:
    description:
      - Value of the parameter to be set.
    type: str
  db:
    description:
      - Name of the Vertica database.
    type: str
  cluster:
    description:
      - Name of the Vertica cluster.
    default: localhost
    type: str
  port:
    description:
      - Vertica cluster port to connect to.
    default: '5433'
    type: str
  login_user:
    description:
      - The username used to authenticate with.
    default: dbadmin
    type: str
  login_password:
    description:
      - The password used to authenticate with.
    type: str
notes:
  - The default authentication assumes that you are either logging in as or sudo'ing to the C(dbadmin) account on the host.
  - This module uses C(pyodbc), a Python ODBC database adapter. You must ensure that C(unixODBC) and C(pyodbc) is installed
    on the host and properly configured.
  - Configuring C(unixODBC) for Vertica requires C(Driver = /opt/vertica/lib64/libverticaodbc.so) to be added to the C(Vertica)
    section of either C(/etc/odbcinst.ini) or C($HOME/.odbcinst.ini) and both C(ErrorMessagesPath = /opt/vertica/lib64) and
    C(DriverManagerEncoding = UTF-16) to be added to the C(Driver) section of either C(/etc/vertica.ini) or C($HOME/.vertica.ini).
requirements: ['unixODBC', 'pyodbc']
author: "Dariusz Owczarek (@dareko)"
z}
- name: Updating load_balance_policy
  community.general.vertica_configuration: name=failovertostandbyafter value='8 hours'
NTF)AnsibleModulemissing_required_lib)	to_nativec                       e Zd Zy)NotSupportedErrorN__name__
__module____qualname__     {/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/vertica_configuration.pyr
   r
   W       r   r
   c                       e Zd Zy)CannotDropErrorNr   r   r   r   r   r   [   r   r   r   c                     i }| j                  d||       	 | j                  d      }|s	 |S |D ]A  }|j                  |j                  |j                  d||j                  j                         <   C ])Nz
        select c.parameter_name, c.current_value, c.default_value
        from configuration_parameters c
        where c.node_name = 'ALL'
        and (? = '' or c.parameter_name ilike ?)
    d   )parameter_namecurrent_valuedefault_value)execute	fetchmanyr   r   r   lower)cursorr   factsrowsrows        r   get_configuration_factsr!   a   s    E
NN 
 
) $ L  	4C"%"4"4!$!2!2!$!2!214E#$$**,-	4	 r   c                 x    |j                         }|r(|j                         | |   d   j                         k7  ryy)Nr   FT)r   )configuration_factsr   r   parameter_keys       r   checkr%   u   s>    "((*M,,.2Em2TUd2e2k2k2mmr   c                     |j                         }d}|rJ|j                         | |   d   j                         k7  r#|j                  dj                  ||             d}|r| j                  t	        ||             |S )NFr   z)select set_config_parameter('{0}', '{1}')T)r   r   formatupdater!   )r#   r   r   r   r$   changeds         r   presentr*   |   s{    "((*MG,,.2Em2TUd2e2k2k2mmBII.Zghi""#:6>#RSNr   c                     t        t        t        ddg      t        d       t        d       t        d      t        d      t        d      t        d d      	      d
      } t        s | j                  t	        d      t
               | j                  d   }| j                  d   }d}| j                  d   r| j                  d   }d}	 dj                  | j                  d   | j                  d   || j                  d   | j                  d   d      }t        j                  |d      }|j                         }	 t              }	| j                   rt#        |	||       }n	 t%        |	|||      }| j/                  ||d	i       y # t        $ rG}| j                  dj                  t        |            t        j                                Y d }~d }~ww xY w# t        j&                  $ r8}| j                  t        |      t        j                                Y d }~d }~ww xY w# t(        $ r(}| j                  t        |      d	i       Y d }~d }~wt*        $ r)}| j                  t        |      d	i       Y d }~d }~wt,        $ r  t        $ r9}| j                  t        |      t        j                                Y d }~]d }~ww xY w)NTname)requiredaliases)default	localhost5433dbadmin)r/   no_log)	parametervaluedbclusterport
login_userlogin_password)argument_specsupports_check_modepyodbc)msg	exceptionr4   r5    r6   Fz_Driver=Vertica;Server={0};Port={1};Database={2};User={3};Password={4};ConnectionLoadBalance={5}r7   r8   r9   r:   true)
autocommitz#Unable to connect to database: {0}.vertica_configuration)r>   ansible_facts)r)   r4   rD   )r   dictpyodbc_found	fail_jsonr   PYODBC_IMP_ERRparamsr'   r=   connectr   	Exceptionr   	traceback
format_excr!   
check_moder%   r*   Errorr
   r   
SystemExit	exit_json)
moduler   r   r6   r)   dsndb_connr   er#   s
             r   mainrV      s   D6(;t$D!-f%I.T:
  $	%F 1(;~V]];/NMM'*M	B}}T]]4 G;( &y)6==+@"|,fmm<L.MvW 	 ..6!
M5f= 3^]SSGU!"5v~}] WOfh{N|}/  ;BII)TU,W#,#7#7#9 	 	; 	;; << U  Yq\Y=Q=Q=S TTU iYq\:QSf9ghh iYq\:QSf9ghh  MYq\Y5I5I5KLLMsm   A1F  &H- 'G 	G=GGH*2.H% H- %H**H- -	K6IK%J		K.KK__main__)r@   )
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESrL   rH   r=   rF   ImportErrorrM   ansible.module_utils.basicr   r   +ansible.module_utils.common.text.convertersr   rK   r
   r   r!   r%   r*   rV   r   r   r   r   <module>r`      s    A @7r 
 L J A		 		i 	(<~~ zF w  )Y))+NLs   A A87A8