mirror of https://github.com/ansible/ansible.git
Add ssl, validate_certs in InfluxDB modules (#33327)
This fix adds ssl and validate_certs argument spec for InfluxDB modules. Also, refactors code. Add BSD License. Fixes: #31923 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>pull/33801/head
parent
74a7cc7130
commit
1d53fbeb59
@ -0,0 +1,66 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright: (c) 2017, Ansible Project
|
||||
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
|
||||
|
||||
try:
|
||||
import requests.exceptions
|
||||
HAS_REQUESTS = True
|
||||
except ImportError:
|
||||
HAS_REQUESTS = False
|
||||
|
||||
try:
|
||||
from influxdb import InfluxDBClient
|
||||
from influxdb import exceptions
|
||||
HAS_INFLUXDB = True
|
||||
except ImportError:
|
||||
HAS_INFLUXDB = False
|
||||
|
||||
|
||||
class InfluxDb(object):
|
||||
def __init__(self, module):
|
||||
self.module = module
|
||||
self.params = self.module.params
|
||||
self.check_lib()
|
||||
self.hostname = self.params['hostname']
|
||||
self.port = self.params['port']
|
||||
self.username = self.params['username']
|
||||
self.password = self.params['password']
|
||||
self.database_name = self.params['database_name']
|
||||
|
||||
def check_lib(self):
|
||||
if not HAS_REQUESTS:
|
||||
self.module.fail_json(msg='This module requires "requests" module.')
|
||||
|
||||
if not HAS_INFLUXDB:
|
||||
self.module.fail_json(msg='This module requires influxdb python package.')
|
||||
|
||||
@staticmethod
|
||||
def influxdb_argument_spec():
|
||||
return dict(
|
||||
hostname=dict(required=True, type='str'),
|
||||
port=dict(default=8086, type='int'),
|
||||
username=dict(default='root', type='str'),
|
||||
password=dict(default='root', type='str', no_log=True),
|
||||
database_name=dict(required=True, type='str'),
|
||||
ssl=dict(default=False, type='bool'),
|
||||
validate_certs=dict(default=True, type='bool'),
|
||||
timeout=dict(default=None, type='int'),
|
||||
retries=dict(default=3, type='int'),
|
||||
proxies=dict(default={}, type='dict'),
|
||||
)
|
||||
|
||||
def connect_to_influxdb(self):
|
||||
return InfluxDBClient(
|
||||
host=self.hostname,
|
||||
port=self.port,
|
||||
username=self.username,
|
||||
password=self.password,
|
||||
database=self.database_name,
|
||||
ssl=self.params['ssl'],
|
||||
verify_ssl=self.params['validate_certs'],
|
||||
timeout=self.params['timeout'],
|
||||
retries=self.params['retries'],
|
||||
use_udp=self.params['use_udp'],
|
||||
udp_port=self.params['udp_port'],
|
||||
proxies=self.params['proxies'],
|
||||
)
|
@ -0,0 +1,63 @@
|
||||
# Copyright: (c) 2017, Ansible Project
|
||||
# Copyright: (c) 2017, Abhijeet Kasurde (akasurde@redhat.com)
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
||||
class ModuleDocFragment(object):
|
||||
# Parameters for influxdb modules
|
||||
DOCUMENTATION = '''
|
||||
options:
|
||||
hostname:
|
||||
description:
|
||||
- The hostname or IP address on which InfluxDB server is listening
|
||||
required: true
|
||||
username:
|
||||
description:
|
||||
- Username that will be used to authenticate against InfluxDB server
|
||||
default: root
|
||||
password:
|
||||
description:
|
||||
- Password that will be used to authenticate against InfluxDB server
|
||||
default: root
|
||||
port:
|
||||
description:
|
||||
- The port on which InfluxDB server is listening
|
||||
default: 8086
|
||||
validate_certs:
|
||||
description:
|
||||
- If set to C(no), the SSL certificates will not be validated.
|
||||
- This should only set to C(no) used on personally controlled sites using self-signed certificates.
|
||||
default: true
|
||||
version_added: "2.5"
|
||||
ssl:
|
||||
description:
|
||||
- Use https instead of http to connect to InfluxDB server.
|
||||
default: False
|
||||
version_added: "2.5"
|
||||
timeout:
|
||||
description:
|
||||
- Number of seconds Requests will wait for client to establish a connection.
|
||||
default: None
|
||||
version_added: "2.5"
|
||||
retries:
|
||||
description:
|
||||
- Number of retries client will try before aborting.
|
||||
- C(0) indicates try until success.
|
||||
default: 3
|
||||
version_added: "2.5"
|
||||
use_udp:
|
||||
description:
|
||||
- Use UDP to connect to InfluxDB server.
|
||||
default: False
|
||||
version_added: "2.5"
|
||||
udp_port:
|
||||
description:
|
||||
- UDP port to connect to InfluxDB server.
|
||||
default: 4444
|
||||
version_added: "2.5"
|
||||
proxies:
|
||||
description:
|
||||
- HTTP(S) proxy to use for Requests to connect to InfluxDB server.
|
||||
default: None
|
||||
version_added: "2.5"
|
||||
'''
|
Loading…
Reference in New Issue