forked from 3wordchant/capsul-flask
implement ensure_vms_and_db_are_synced in cron task and add default
sender to readme
This commit is contained in:
@ -243,5 +243,36 @@ def notify_users_about_account_balance():
|
||||
|
||||
|
||||
def ensure_vms_and_db_are_synced():
|
||||
db_ids = get_model().all_vm_ids()
|
||||
#virt_ids = current_app.config["VIRTUALIZATION_MODEL"].
|
||||
db_ids = get_model().all_non_deleted_vm_ids()
|
||||
virt_ids = current_app.config["VIRTUALIZATION_MODEL"].list_ids()
|
||||
|
||||
db_ids_dict = dict()
|
||||
virt_ids_dict = dict()
|
||||
|
||||
for id in db_ids:
|
||||
db_ids_dict[id] = True
|
||||
|
||||
for id in virt_ids:
|
||||
virt_ids_dict[id] = True
|
||||
|
||||
errors = list()
|
||||
|
||||
for id in db_ids_dict:
|
||||
if id not in virt_ids_dict:
|
||||
errors.append(f"{id} is in the database but not in the virtualization model")
|
||||
|
||||
for id in virt_ids_dict:
|
||||
if id not in db_ids_dict:
|
||||
errors.append(f"{id} is in the virtualization model but not in the database")
|
||||
|
||||
if len(errors) > 0:
|
||||
email_addresses_raw = current_app.config['ADMIN_EMAIL_ADDRESSES'].split(",")
|
||||
email_addresses = list(filter(lambda x: len(x) > 6, map(lambda x: x.strip(), email_addresses_raw ) ))
|
||||
current_app.config["FLASK_MAIL_INSTANCE"].send(
|
||||
Message(
|
||||
"Capsul Consistency Check Failed",
|
||||
body="\n".join(errors),
|
||||
recipients=email_addresses
|
||||
)
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user