Source code for saltext.influxdb.states.influxdb_database
"""Manage InfluxDB 0.9-1.x databases statefully... important:: You can optionally specify default connection parameters via the general :ref:`influxdb setup <influxdb-setup>`."""def__virtual__():if"influxdb.db_exists"in__salt__:return"influxdb_database"return(False,"influxdb module could not be loaded")
[docs]defpresent(name,**client_args):""" Ensure that given database is present. name Name of the database to create. """ret={"name":name,"changes":{},"result":True,"comment":f"Database {name} is already present",}ifnot__salt__["influxdb.db_exists"](name,**client_args):if__opts__["test"]:ret["result"]=Noneret["comment"]=f"Database {name} is absent and will be created"returnretif__salt__["influxdb.create_db"](name,**client_args):ret["comment"]=f"Database {name} has been created"ret["changes"][name]="Present"returnretelse:ret["comment"]=f"Failed to create database {name}"ret["result"]=Falsereturnretreturnret
[docs]defabsent(name,**client_args):""" Ensure that given database is absent. name Name of the database to remove. """ret={"name":name,"changes":{},"result":True,"comment":f"Database {name} is not present",}if__salt__["influxdb.db_exists"](name,**client_args):if__opts__["test"]:ret["result"]=Noneret["comment"]=f"Database {name} is present and needs to be removed"returnretif__salt__["influxdb.drop_db"](name,**client_args):ret["comment"]=f"Database {name} has been removed"ret["changes"][name]="Absent"returnretelse:ret["comment"]=f"Failed to remove database {name}"ret["result"]=Falsereturnretreturnret