Exemplo n.º 1
0
def login():
    if request.method == 'POST':
        print(DbFunctions.match_user_credentials(request.form['username'], request.form['password']))
        if DbFunctions.match_user_credentials(request.form['username'], request.form['password']):
            user = load_user(request.form['username'])
            print('Logged in')
            login_user(user, duration=timedelta.max)
        return redirect(next)
    if request.method == 'GET':
        return render_template('login.html')
Exemplo n.º 2
0
def totalUsageUser():
    arr = DbFunctions.all_active_vms_by_user(request.form['user_id'])
    items = []
    totalCost = 0
    for event in arr:
        if event.user_id == request.form['user_id']:
            items.add(event)
    start = 0
    stop = 0
    for item in items:
        if item.event_type == EventType.START.name:
            start = event.timestamp
            for i in items:
                if i.event_type == EventType.STOP.name& i.vm_id== item.vm_id:
                    stop = event.timestamp
        if start != 0 & stop != 0:
            cost = 0
            if item.vm_config == VmType.BASIC.name:
                cost = 0.05 / 60
            if item.vm_config == VmType.LARGE.name:
                cost = 0.10 / 60
            if item.vm_config == VmType.ULTRALARGE.name:
                cost = 0.15 / 60
            timeUsed = start - stop
            totalCost = totalCost + (timeUsed.total_seconds() * cost)
            stop = 0
            start = 0
    return totalCost
Exemplo n.º 3
0
def totalUsageVM():
   arr = DbFunctions.get_all_events_from_certain_vm(request.form['vm_id'])
   items = []
   totalCost =0
   for event in arr:
       if event.vm_id ==request.form['vm_id']:
            items.add(event)
   start = 0
   stop = 0
   for item in items:
       if item.event_type == EventType.START.name:
           start = event.timestamp
       if item.event_type == EventType.STOP.name:
           stop = event.timestamp
       if start!=0 & stop!=0:
           cost = 0
           if item.vm_config == VmType.BASIC.name:
               cost = 0.05/60
           if item.vm_config == VmType.LARGE.name:
               cost = 0.10/60
           if item.vm_config == VmType.ULTRALARGE.name:
               cost = 0.15/60
           timeUsed = start - stop
           totalCost = totalCost + (timeUsed.total_seconds()*cost)
           stop = 0
           start = 0
   return totalCost
Exemplo n.º 4
0
def createVM():

    if request.form['vm_config'] == "Basic":
        DbFunctions.create_new_vm(VmType.BASIC.name, 1)
        return 'Created Basic vm'
    elif request.form['vm_config'] == "Large":
        DbFunctions.create_new_vm(VmType.LARGE.name, 1)
        return 'Created Large vm'
    else:
        DbFunctions.create_new_vm(VmType.ULTRALARGE.name,1)
        return 'Created UltraLarge vm'
Exemplo n.º 5
0
def downgradeVM():
   DbFunctions.downgrade_vm_configuration(request.form['vm_id'])
   return "downgraded:" + request.form['vm_id']
Exemplo n.º 6
0
def upgradeVM():
   DbFunctions.upgrade_vm_configuration(request.form['vm_id'])
   return "upgraded:" + request.form['vm_id']
Exemplo n.º 7
0
def deleteVM():
   DbFunctions.delete_vm(request.form['vm_id'])
   return "deleted:" + request.form['vm_id']
Exemplo n.º 8
0
def stopVM():
   DbFunctions.stop_vm(request.form['vm_id'])
   return "stopped:" + request.form['vm_id']
Exemplo n.º 9
0
def startVM():
   DbFunctions.start_vm(request.form['vm_id'])
   return "started:" + request.form['vm_id']