ConsulManager/flask-consul/manager.py

51 lines
1.6 KiB
Python
Raw Permalink Normal View History

2022-01-29 02:45:54 +08:00
#!/usr/bin/env python3
from flask import Flask
2022-04-09 09:35:50 +08:00
from units import consul_kv
import uuid
2022-07-17 22:38:23 +08:00
2022-04-09 09:35:50 +08:00
skey_path = 'ConsulManager/assets/secret/skey'
if consul_kv.get_kv_dict(skey_path) == {}:
consul_kv.put_kv(skey_path,{'sk':''.join(str(uuid.uuid4()).split('-'))})
2022-01-29 02:45:54 +08:00
2022-07-17 22:38:23 +08:00
from views import login, blackbox, consul, jobs, nodes, selfnode, avd, exp, jms
2022-04-09 09:35:50 +08:00
from units.cloud import huaweicloud,alicloud,tencent_cloud
2022-06-11 19:26:35 +08:00
from units.avd import avd_list
2022-07-17 22:38:23 +08:00
from units.jms import sync_jms
2022-01-29 02:45:54 +08:00
app = Flask(__name__)
2022-07-17 23:14:29 +08:00
#非nginx调试解决跨域CORS问题
#CORS(app, supports_credentials=True)
2022-01-29 02:45:54 +08:00
app.register_blueprint(login.blueprint)
app.register_blueprint(blackbox.blueprint)
2022-02-10 23:08:12 +08:00
app.register_blueprint(consul.blueprint)
2022-04-09 09:35:50 +08:00
app.register_blueprint(jobs.blueprint)
app.register_blueprint(nodes.blueprint)
2022-05-08 20:37:24 +08:00
app.register_blueprint(selfnode.blueprint)
2022-06-11 19:26:35 +08:00
app.register_blueprint(avd.blueprint)
2022-07-01 07:58:29 +08:00
app.register_blueprint(exp.blueprint)
2022-07-17 22:38:23 +08:00
app.register_blueprint(jms.blueprint)
2022-04-09 09:35:50 +08:00
class Config(object):
JOBS = []
SCHEDULER_API_ENABLED = True
2022-07-17 22:38:23 +08:00
2022-07-01 07:58:29 +08:00
ecs_jobs = consul_kv.get_kv_dict('ConsulManager/jobs')
2022-06-11 19:26:35 +08:00
avd_jobs = consul_kv.get_kv_dict('ConsulManager/avd/jobs')
2022-07-01 07:58:29 +08:00
exp_jobs = consul_kv.get_kv_dict('ConsulManager/exp/jobs')
2022-07-17 22:38:23 +08:00
jms_jobs = consul_kv.get_kv_dict('ConsulManager/jms/jobs')
init_jobs = { **ecs_jobs, **avd_jobs, **exp_jobs, **jms_jobs }
2022-06-11 19:26:35 +08:00
2022-04-09 09:35:50 +08:00
if init_jobs is not None:
for k,v in init_jobs.items():
print(f"【初始化任务】{k}{v['args']}{v['minutes']}m", flush=True)
2022-04-09 09:35:50 +08:00
Config.JOBS = init_jobs.values()
2022-07-17 22:38:23 +08:00
2022-04-09 09:35:50 +08:00
app.config.from_object(Config())
if __name__ == "__main__":
scheduler = jobs.init()
scheduler.init_app(app)
scheduler.start()
2022-01-29 02:45:54 +08:00
app.run(host="0.0.0.0", port=2026)