Exemplo n.º 1
0
def vm_edit_remarks_ajax(req):
    remarks = req.POST.get('remarks')
    vmid = req.POST.get('vmid')
    res = api_vm_edit({'req_user': req.user, 'uuid': vmid, 'remarks': remarks})
    if not res['res'] and res['err'] in ERROR_CN:
        res['error'] = ERROR_CN[res['err']]
    return HttpResponse(json.dumps(res), content_type='application/json')
Exemplo n.º 2
0
def vm_edit_remarks_ajax(req):
    remarks = req.POST.get('remarks')
    vmid = req.POST.get('vmid')
    res = api_vm_edit({
                       'req_user': req.user,
                       'uuid': vmid, 
                       'remarks': remarks})
    if not res['res'] and res['err'] in ERROR_CN:
        res['error'] = ERROR_CN[res['err']]
    return HttpResponse(json.dumps(res), content_type='application/json')
Exemplo n.º 3
0
def vm_edit_view(req):
    dicts = {}
    arg_vmid = req.GET.get('vmid')

    if req.method == 'POST':
        arg_cpu = req.POST.get('cpu')
        arg_mem = req.POST.get('mem')

        status_res = api_vm_status({'req_user': req.user, 'uuid': arg_vmid})

        if status_res['res'] and status_res['status'] != 1:
            if arg_cpu.isdigit() and arg_mem.isdigit():
                edit_res = api_vm_edit({
                    'req_user': req.user,
                    'uuid': arg_vmid,
                    'vcpu': arg_cpu,
                    'mem': arg_mem
                })
                if not edit_res['res']:
                    dicts['warning'] = '修改失败。'
        else:
            dicts['warning'] = '只能修改处于关机状态的虚拟机。'

    obj_res = api_vm_get({'req_user': req.user, 'uuid': arg_vmid})
    if obj_res['res']:
        obj = obj_res['info']
    else:
        return HttpResponseRedirect('../list/')
    dicts['vmobj'] = obj

    host_res = api_host_get({'req_user': req.user, 'host_id': obj['host_id']})
    if host_res['res']:
        host = host_res['info']
        dicts['remain_mem'] = host['mem_total'] - \
                              host['mem_allocated'] - \
                              host['mem_reserved']
        if dicts['remain_mem'] < 0:
            dicts['remain_mem'] = 0
        dicts['remain_cpu'] = host['vcpu_total'] - host['vcpu_allocated']
        if dicts['remain_cpu'] < 0:
            dicts['remain_cpu'] = 0

    return render_to_response('vmadmin_edit.html',
                              dicts,
                              context_instance=RequestContext(req))
Exemplo n.º 4
0
def vm_edit_view(req):
    dicts = {}
    arg_vmid = req.GET.get('vmid')
    
    if req.method == 'POST':
        arg_cpu = req.POST.get('cpu')
        arg_mem = req.POST.get('mem')
        
        status_res = api_vm_status({'req_user': req.user, 'uuid': arg_vmid})
        
        if status_res['res'] and status_res['status'] != 1:
            if arg_cpu.isdigit() and arg_mem.isdigit():
                edit_res = api_vm_edit({'req_user': req.user,
                                        'uuid': arg_vmid,
                                        'vcpu': arg_cpu, 
                                        'mem': arg_mem})
                if not edit_res['res']:
                    dicts['warning'] = '修改失败。'
        else:
            dicts['warning'] = '只能修改处于关机状态的虚拟机。'
            
    obj_res = api_vm_get({'req_user': req.user, 'uuid': arg_vmid})
    if obj_res['res']:
        obj = obj_res['info']
    else:
        return HttpResponseRedirect('../list/')
    dicts['vmobj'] = obj
    
    host_res = api_host_get({'req_user': req.user, 'host_id': obj['host_id']})
    if host_res['res']:
        host = host_res['info']
        dicts['remain_mem'] = host['mem_total'] - \
                              host['mem_allocated'] - \
                              host['mem_reserved']   
        if dicts['remain_mem'] < 0:
            dicts['remain_mem'] = 0
        dicts['remain_cpu'] = host['vcpu_total'] - host['vcpu_allocated']
        if dicts['remain_cpu'] < 0:
            dicts['remain_cpu'] = 0
    
    return render_to_response('vmadmin_edit.html', dicts, context_instance=RequestContext(req))