implement ensure_vms_and_db_are_synced in cron task and add default

sender to readme
This commit is contained in:
2020-05-21 21:40:41 -05:00
parent 2f55ce904e
commit e2c51d067e
6 changed files with 38 additions and 6 deletions

View File

@ -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
)
)