first cosmoserver commit
This commit is contained in:
85
files/api/Cosmos_Settings.py
Normal file
85
files/api/Cosmos_Settings.py
Normal file
@ -0,0 +1,85 @@
|
||||
import yaml
|
||||
#######################################################################
|
||||
### Settings Handler Functions
|
||||
#######################################################################
|
||||
|
||||
# default application setting variables
|
||||
app_settings = {
|
||||
"noisy_test" : False,
|
||||
"debug_output" : True,
|
||||
"log_output" : True,
|
||||
"secure_api" : True,
|
||||
"push_redis" : False,
|
||||
"run_background" : True,
|
||||
"cosmostat_server": False,
|
||||
"cosmostat_server_reporter": False,
|
||||
"update_frequency": 1,
|
||||
"custom_api_port": "5000",
|
||||
"cosmostat_server_api": "http://10.200.27.20:5000/"
|
||||
}
|
||||
|
||||
with open('cosmostat_settings.yaml', 'r') as f:
|
||||
print("Loading cosmostat_settings file")
|
||||
cosmostat_settings = yaml.safe_load(f)
|
||||
print("...Done")
|
||||
# initialize system variables from settings file
|
||||
print("Checking for system var overrides")
|
||||
for setting in app_settings:
|
||||
if setting in cosmostat_settings:
|
||||
cosmos_setting = cosmostat_settings[setting]
|
||||
if app_settings["debug_output"]:
|
||||
print(f"{setting}: {cosmos_setting}")
|
||||
app_settings[setting] = cosmos_setting
|
||||
print("...Done")
|
||||
|
||||
# this returns the docker gateway from the settings
|
||||
def docker_gateway_settings() -> str:
|
||||
return cosmostat_settings["docker_gateway"]
|
||||
|
||||
# this returns the jenkins user that ran the pipeline
|
||||
def jenkins_user_settings() -> str:
|
||||
return cosmostat_settings["jenkins_user"]
|
||||
|
||||
# this returns the ansible_hostname from setup
|
||||
def jenkins_hostname_settings() -> str:
|
||||
return cosmostat_settings["ansible_hostname"]
|
||||
|
||||
# this returns the inventory_generation_timestamp
|
||||
def jenkins_inventory_generation_timestamp_settings() -> str:
|
||||
return cosmostat_settings["inventory_generation_timestamp"]
|
||||
|
||||
def run_cosmostat_server():
|
||||
return cosmostat_settings["cosmostat_server"]
|
||||
|
||||
def service_gateway_ip():
|
||||
if cosmostat_settings["secure_api"]:
|
||||
return docker_gateway_settings()
|
||||
else:
|
||||
return "0.0.0.0"
|
||||
|
||||
def cosmostat_server_api():
|
||||
return cosmostat_settings["cosmostat_server_api"]
|
||||
|
||||
def service_api_port():
|
||||
return cosmostat_settings["custom_api_port"]
|
||||
|
||||
def log_data(log_output:str, log_level = cosmostat_settings["noisy_test"]):
|
||||
log_levels = [
|
||||
"noisy_test",
|
||||
"debug_output",
|
||||
"log_output",
|
||||
]
|
||||
|
||||
if log_level in log_levels:
|
||||
if cosmostat_settings[log_level]:
|
||||
print(log_output)
|
||||
else:
|
||||
print(f"Warning - {log_level} not valid log level")
|
||||
|
||||
|
||||
|
||||
|
||||
#for level_check in log_levels:
|
||||
# if log_level == level_check:
|
||||
# print(f"log_level: {log_level} - level_check - {level_check}")
|
||||
# print(log_output)
|
||||
Reference in New Issue
Block a user