mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
fix vm_power parameter, add basic vm expire email
This commit is contained in:
parent
3fd24e42ea
commit
d0368e743f
3 changed files with 13 additions and 9 deletions
|
@ -150,7 +150,7 @@ def vm_power(vmid, action):
|
|||
proxmox, user) or 'rtp' in session['userinfo']['groups']:
|
||||
if action == 'start':
|
||||
config = get_vm_config(proxmox, vmid)
|
||||
usage_check = check_user_usage(proxmox, user, config['cores'],
|
||||
usage_check = check_user_usage(proxmox, db, user, config['cores'],
|
||||
config['memory'], 0)
|
||||
if usage_check:
|
||||
return usage_check
|
||||
|
|
|
@ -18,13 +18,14 @@ def send_email(toaddr, subject, body):
|
|||
server.quit()
|
||||
|
||||
|
||||
def send_vm_expire_email(user, name, days):
|
||||
def send_vm_expire_email(user, vms):
|
||||
toaddr = "{}@csh.rit.edu".format(user)
|
||||
subject = 'Proxstar VM Expiration Notice'
|
||||
if days != 1:
|
||||
body = "{} is expiring in {} days. If you would like to keep this VM, please log into Proxstar and renew it.".format(
|
||||
name, days)
|
||||
else:
|
||||
body = "{} is expiring in {} day. If you would like to keep this VM, please log into Proxstar and renew it.".format(
|
||||
name, days)
|
||||
body = "The following VMs in Proxstar are expiring soon:\n\n"
|
||||
for vm in vms:
|
||||
if vm[1] != 1:
|
||||
body += " - {} in {} days\n".format(vm[0], vm[1])
|
||||
else:
|
||||
body += " - {} in {} day\n".format(vm[0], vm[1])
|
||||
body += "\nPlease login to Proxstar and renew any VMs you would like to keep."
|
||||
send_email(toaddr, subject, body)
|
||||
|
|
|
@ -78,6 +78,7 @@ def process_expiring_vms_task():
|
|||
starrs = connect_starrs()
|
||||
pools = get_pools(proxmox)
|
||||
for pool in pools:
|
||||
expiring_vms = []
|
||||
vms = get_vms_for_user(proxmox, pool)
|
||||
for vm in vms:
|
||||
vmid = vm['vmid']
|
||||
|
@ -86,4 +87,6 @@ def process_expiring_vms_task():
|
|||
days = (expire - datetime.date.today()).days
|
||||
if days in [10, 7, 3, 1]:
|
||||
name = get_vm_config(proxmox, vmid)['name']
|
||||
send_vm_expire_email('com6056', name, days)
|
||||
expiring_vms.append([name, days])
|
||||
if expiring_vms:
|
||||
send_vm_expire_email('com6056', expiring_vms)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue