-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update module influxdb2_organizations
- Loading branch information
1 parent
b112562
commit f171633
Showing
17 changed files
with
935 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,7 @@ platforms: | |
pre_build_image: true | ||
provisioner: | ||
name: ansible | ||
env: | ||
ANSIBLE_VERBOSITY: 3 | ||
verifier: | ||
name: ansible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# !/usr/bin/python3 | ||
|
||
# Copyright (c) 2024, Tobias Bauriedel <tobias.bauriedel@netways.de> | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
|
||
from influxdb_client import InfluxDBClient | ||
|
||
class Api(): | ||
def new_client(host, token, timeout=10000) -> InfluxDBClient: | ||
return InfluxDBClient(host, token, timeout=timeout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# !/usr/bin/python3 | ||
|
||
# Copyright (c) 2024, Tobias Bauriedel <tobias.bauriedel@netways.de> | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# You may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
from influxdb_client import Organization | ||
from ansible_collections.tbauriedel.influxdb2.plugins.module_utils.api import ( | ||
Api | ||
) | ||
|
||
class Org(): | ||
def __init__(self, name, state, desc, result, host, token): | ||
self.name = name | ||
self.state = state | ||
self.desc = desc | ||
self.result = result | ||
|
||
self.client = Api.new_client(host=host, token=token).organizations_api() | ||
|
||
self.handle() | ||
|
||
return | ||
|
||
|
||
def return_result(self) ->dict: | ||
return self.result | ||
|
||
|
||
def handle(self): | ||
if self.state == 'absent': | ||
self.handle_absent() | ||
elif self.state == 'present': | ||
self.handle_present() | ||
|
||
return | ||
|
||
|
||
def handle_absent(self): | ||
org = Organization(name=self.name, status='inactive') | ||
for row in self.get_all(): | ||
if row.name != self.name: | ||
continue | ||
org = row | ||
break | ||
|
||
if org.status != 'active': | ||
return | ||
|
||
res = self.delete(org.id) | ||
self.result['debug'] = res | ||
self.result['changed'] = True | ||
self.result['msg'] = self.name + " has been deleted" | ||
|
||
return | ||
|
||
|
||
def handle_present(self): | ||
pre_org = Organization(name=self.name, description=self.desc, status='inactive') | ||
for row in self.get_all(): | ||
if row.name != self.name: | ||
continue | ||
pre_org = self.get(row.id) | ||
break | ||
|
||
if pre_org.status != 'active': | ||
res = self.create() | ||
self.result['changed'] = True | ||
self.result['msg'] = self.name + " has been created" | ||
return | ||
|
||
if self.desc != pre_org.description: | ||
self.update(pre_org.id) | ||
self.result['changed'] = True | ||
self.result['msg'] = self.name + " has been updated" | ||
|
||
return | ||
|
||
|
||
def create(self) -> Organization: | ||
return self.client.create_organization(name=self.name, organization=Organization(name=self.name, description=self.desc)) | ||
|
||
|
||
def update(self, id) -> Organization: | ||
return self.client.update_organization(organization=Organization(name=self.name, description=self.desc, id=id)) | ||
|
||
|
||
def delete(self, id): | ||
return self.client.delete_organization(org_id=id) | ||
|
||
|
||
def get_all(self) -> list[Organization]: | ||
return self.client.find_organizations() | ||
|
||
|
||
def get(self, id) -> Organization: | ||
return self.client.find_organization(org_id=id) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/python3 | ||
# pylint: disable=missing-module-docstring | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
def run_module(): | ||
''' | ||
Module to manage InfluxDB buckets | ||
''' | ||
|
||
# Define new Module with arguments | ||
module = AnsibleModule( | ||
argument_spec=dict( | ||
name=dict(type=str, required=True), | ||
state=dict(type=str, required=True), | ||
token=dict(type=str, Required=True, no_log=True), | ||
host=dict(type=str, Required=True), | ||
org=dict(type=str, required=False), | ||
retention=dict(type=dict, required=False) | ||
) | ||
) | ||
|
||
if module.params['state'] != 'absent' and module.params['state'] != 'present': | ||
module.exit_json( | ||
failed=True, | ||
stderr="Invalid state provided. Use 'present' or 'absent'" | ||
) | ||
|
||
# Default result | ||
result = dict( | ||
changed=False, | ||
failed=False, | ||
) | ||
|
||
# TODO add handling | ||
|
||
module.exit_json(**result) | ||
|
||
|
||
if __name__ == '__main__': | ||
run_module() |
Oops, something went wrong.