
    Vh                         d dl mZmZmZ eZdZdZdZ	 d dl	Z
d dlmZ d dlmZ d dlmZ d	 Zd
 Zd Zd Zedk(  r e        yy# e$ r Y -w xY w)    )absolute_importdivisionprint_functiona|  
module: influxdb_database
short_description: Manage InfluxDB databases
description:
  - Manage InfluxDB databases.
author: "Kamil Szczygiel (@kamsz)"
requirements:
  - "influxdb >= 0.9"
  - requests
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  database_name:
    description:
      - Name of the database.
    required: true
    type: str
  state:
    description:
      - Determines if the database should be created or destroyed.
    choices: [absent, present]
    default: present
    type: str
extends_documentation_fragment:
  - community.general.influxdb
  - community.general.attributes
a  
# Example influxdb_database command from Ansible Playbooks
- name: Create database
  community.general.influxdb_database:
    hostname: "{{influxdb_ip_address}}"
    database_name: "{{influxdb_database_name}}"

- name: Destroy database
  community.general.influxdb_database:
    hostname: "{{influxdb_ip_address}}"
    database_name: "{{influxdb_database_name}}"
    state: absent

- name: Create database using custom credentials
  community.general.influxdb_database:
    hostname: "{{influxdb_ip_address}}"
    username: "{{influxdb_username}}"
    password: "{{influxdb_password}}"
    database_name: "{{influxdb_database_name}}"
    ssl: true
    validate_certs: true
z
# only defaults
N)
exceptions)AnsibleModule)InfluxDbc                     d }	 |j                         }|D ]  }|d   |k(  s|} |S  	 |S # t        j                  j                  $ r&}| j	                  t        |             Y d }~|S d }~ww xY w)Nnamemsg)get_list_databaserequestsr   ConnectionError	fail_jsonstr)moduleclientdatabase_namedatabase	databasesdbes          w/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/influxdb_database.pyfind_databaser   P   s    H%,,.	 	B&z]* O	 O .. %SV$$O%s   + + + A.A))A.c                     | j                   s	 |j                  |       | j                  d       y # t        j                  j                  $ r%}| j                  t        |             Y d }~Pd }~ww xY wNr   Tchanged)
check_modecreate_databaser   r   r   r   r   	exit_jsonr   r   r   r   s       r   r    r    ^   sg    	)""=1 T" ""22 	)Q((	)s   2 A4A//A4c                     | j                   s	 |j                  |       | j                  d       y # t        j                  $ r&}| j	                  |j
                         Y d }~Gd }~ww xY wr   )r   drop_databaser   InfluxDBClientErrorr   contentr!   r"   s       r   r$   r$   h   sa    	,  / T" -- 	,++	,s   2 A+A&&A+c            	         t        j                         } | j                  t        dd      t        ddddg             t	        | d      }|j
                  d	   }t        |      }|j                         }|j                  }t        |||      }|dk(  r"|r|j                  d
       nt        |||       |dk(  r#|rt        |||       y |j                  d
       y y )NTr   )requiredtypepresentabsent)defaultr)   choices)r   state)argument_specsupports_check_moder.   Fr   )r   influxdb_argument_specupdatedictr   paramsconnect_to_influxdbr   r   r!   r    r$   )r/   r   r.   influxdbr   r   r   s          r   mainr7   r   s    335MDu5959h:OP   # F
 MM'"EH))+F**MVV];H	U+FFM:&&-8U+	     __main__)
__future__r   r   r   r)   __metaclass__DOCUMENTATIONEXAMPLESRETURNrequests.exceptionsr   r6   r   ImportErroransible.module_utils.basicr   Cansible_collections.community.general.plugins.module_utils.influxdbr   r   r    r$   r7   __name__ r8   r   <module>rE      sx    A @>.
	# 5 X##,> zF Q  		s   
A AA