Beispiel #1
0
def do_destroying_comp(request):
    try:
        post = request.POST
        id = post['id']
        comp = Computing.objects.get(id=id)
        message = Message(comp.note)
        message.append({
            'direction': 'Send',
            'info_type': '',
            'user_name': request.user.username,
            'text': get_comp_destroying_log()
        })
        note = message.tostring()
        packed_update_computing(request,
                                id, {
                                    'status': DESTROYING_KEY,
                                    'note': note
                                },
                                log=get_comp_destroying_log())
        send_user_mail(comp.account, 'Aglaia Item Notify',
                       get_comp_destroying_mail())
        return HttpResponseRedirect(
            reverse('computing.views.show_comp_verify'))
    except Exception as e:
        return show_message(request,
                            'Destroy computing failed: ' + e.__str__())
Beispiel #2
0
def do_approve_return(request):
    try:
        post = request.POST
        id = post['id']
        note = post['note']
        comp = Computing.objects.get(id=id)
        if not comp.status == RETURNING_KEY:
            return show_denied_message(request)

        if note == '':
            note = get_comp_reted_log()
        message = Message(comp.note)
        message.append({
            'direction': 'Send',
            'info_type': '',
            'user_name': request.user.username,
            'text': note
        })
        note = message.tostring()

        packed_update_computing(request,
                                id, {
                                    'status': RETURNED_KEY,
                                    'note': note
                                },
                                log=get_comp_reted_log())
        return HttpResponseRedirect(
            reverse('computing.views.show_comp_verify'))
    except Exception as e:
        return show_message(
            request, 'Something wrong when approve return: ' + e.__str__())
Beispiel #3
0
def do_disapprove_modify(request):
    try:
        post = request.POST
        id = post['id']
        note = post['note']
        comp = Computing.objects.get(id=id)
        if not comp.status == MODIFY_APPLY_KEY:
            return show_denied_message(request)

        if note == '':
            note = get_comp_rej_modf_log()
        message = Message(comp.note)
        message.append({
            'direction': 'Send',
            'info_type': '',
            'user_name': request.user.username,
            'text': note
        })
        note = message.tostring()

        packed_update_computing(request,
                                id, {
                                    'status': BORROWED_KEY,
                                    'note': note
                                },
                                log=get_comp_rej_modf_log())
        send_notify_mail(request, CompRejectModfMail, comp=comp)

        return HttpResponseRedirect(
            reverse('computing.views.show_comp_verify'))
    except Exception as e:
        return show_message(
            request, 'Something wrong when disapprove modify: ' + e.__str__())
Beispiel #4
0
def do_modif_request(request):
    try:
        post = request.POST
        id = post['id']
        comp = Computing.objects.get(id=id)
        if not comp.status == BORROWED_KEY:
            return HttpResponse('denied')

        if post['reason'] == '':
            post['reason'] = get_comp_modif_log()
        message = Message(comp.note)
        message.append({
            'direction': 'Recv',
            'info_type': '',
            'user_name': request.user.username,
            'text': post['reason']
        })
        note = message.tostring()

        packed_update_computing(request,
                                id, {
                                    'status': MODIFY_APPLY_KEY,
                                    'note': note
                                },
                                log=get_comp_modif_log())
        send_notify_mail(request, CompModfApplyMail, comp=comp)

        return HttpResponse('ok')
    except:
        return HttpResponse('denied')
Beispiel #5
0
def do_return_request(request):
    try:
        id = request.POST['id']
        comp = Computing.objects.get(id=id)
        if not (comp.status == DESTROYING_KEY or comp.status == BORROWED_KEY
                or comp.status == MODIFY_APPLY_KEY):
            return HttpResponse('denied')
        message = Message()
        message.append({
            'direction': 'Recv',
            'info_type': '',
            'user_name': request.user.username,
            'text': get_comp_ret_log()
        })
        packed_update_computing(request,
                                id, {
                                    'status': RETURNING_KEY,
                                    'note': message.tostring()
                                },
                                log=get_comp_ret_log())
        send_notify_mail(request, CompReturnMail, comp=comp)
        return HttpResponseRedirect(reverse('goods.views.show_borrow'))
    #		return HttpResponse('ok')
    except:
        return HttpResponse('denied')
Beispiel #6
0
 def setUp(self):
     self.message = Message(max_num=5)
     self.assertEqual(
         self.message.getTime()['Recv_Readed_Time'] < time.strftime(
             '%Y-%m-%d %H:%M:%S', time.localtime(time.time())), True)
     self.assertEqual(
         self.message.getTime()['Send_Readed_Time'] < time.strftime(
             '%Y-%m-%d %H:%M:%S', time.localtime(time.time())), True)
Beispiel #7
0
def do_borrow_request(request):
    post = request.POST
    comp = {}
    try:
        p_nm = no_excp_post(request, 'package')
        if p_nm != 'none':
            get_pack_prop(comp, p_nm)
        else:
            if post['type'] == 'real':
                comp['pc_type'] = PHYSICAL_MACHINE_KEY
            else:
                comp['pc_type'] = VIRTUAL_MACHINE_KEY
            comp['cpu'] = post['cpu']
            comp['memory'] = post['memory']
            comp['disk'] = post['disk']
            if post['disk_type'] == 'SSD':
                comp['disk_type'] = SSD_KEY
            else:
                comp['disk_type'] = MACHINE_KEY
            comp['os'] = post['os']
            comp['pack_name'] = 'user_defined'
        comp['expire_time'] = datetime.now()
        comp['login'] = post['login']
        comp['password'] = post['initial_password']
        comp['status'] = VERIFYING_KEY
        comp['account'] = Account.objects.get(user=request.user)
        comp['address'] = UNKNOWN_ADDR
        comp['note'] = post['reason']
        comp['flag'] = post['flag']
        comp['data_content'] = post['data_content']

        if comp['note'] == '':
            comp['note'] = get_comp_request_log()
        message = Message()
        message.append({
            'direction': 'Recv',
            'info_type': '',
            'user_name': request.user.username,
            'text': comp['note']
        })
        comp['note'] = message.tostring()

        if 'name' in post:
            comp['name'] = post['name']
        else:
            comp['name'] = ''
        c = packed_create_computing(request, [comp],
                                    log=get_comp_request_log())
        send_notify_mail(request, CompRequestMail, comp=c[0])
        return HttpResponse('ok')
    except Exception as e:
        return HttpResponse('denied')
Beispiel #8
0
def create_borrow(account, sn, status, note=Message().tostring()):
    single = None
    try:
        single = Single.objects.get(sn=sn)
    except:
        raise Exception("Invalid SN number")
    try:
        borrow = Borrow(single=single,
                        status=status,
                        note=note,
                        account=account)
        borrow.save()
    except:
        raise Exception("Error in borrow create")
    return borrow
Beispiel #9
0
def do_approve_modify(request):
    try:
        post = request.POST
        id = post['id']
        comp = Computing.objects.get(id=id)
        if not comp.status == MODIFY_APPLY_KEY:
            return show_denied_message(request)

        note = post['note']
        if note == '':
            note = get_comp_modfed_log()
        message = Message(comp.note)
        message.append({
            'direction': 'Send',
            'info_type': '',
            'user_name': request.user.username,
            'text': note
        })
        note = message.tostring()
        dic = {}
        dic['status'] = BORROWED_KEY
        dic['note'] = note
        if post['type'] == 'real':
            dic['pc_type'] = PHYSICAL_MACHINE_KEY
        else:
            dic['pc_type'] = VIRTUAL_MACHINE_KEY

        if post['disktype'] == 'SSD':
            dic['disk_type'] = SSD_KEY
        else:
            dic['disk_type'] = MACHINE_KEY
        dic['cpu'] = post['cpu']
        dic['memory'] = post['memory']
        dic['disk'] = post['disk']
        dic['address'] = post['ip']
        dic['os'] = post['os']
        dic['data_content'] = post['data_content']
        # dic['login'] = post['login']
        # dic['password'] = post['initial_password']

        packed_update_computing(request, id, dic, log=get_comp_modfed_log())
        send_notify_mail(request, CompModfedMail, comp=comp)

        return HttpResponseRedirect(
            reverse('computing.views.show_comp_verify'))
    except Exception as e:
        return show_message(
            request, 'Something wrong when approve modify: ' + e.__str__())
Beispiel #10
0
def do_approve_borrow(request):
    try:
        post = request.POST
        id = post['id']
        comp = Computing.objects.get(id=id)
        login = post['login']
        pw = post['initial_password']
        note = post['note']
        sn = post['sn']
        addr = post['ip']
        if not comp.status == VERIFYING_KEY:
            return show_denied_message(request)

        if note == '':
            note = get_comp_approve_log()
        message = Message(comp.note)
        message.append({
            'direction': 'Send',
            'info_type': '',
            'user_name': request.user.username,
            'text': note
        })
        note = message.tostring()

        packed_update_computing(request,
                                id, {
                                    'status': BORROWED_KEY,
                                    'note': note,
                                    'sn': sn,
                                    'login': login,
                                    'password': pw,
                                    'address': addr
                                },
                                log=get_comp_approve_log())

        send_notify_mail(request, CompApproveMail, comp=comp)

        return HttpResponseRedirect(
            reverse('computing.views.show_comp_verify'))
    except Exception as e:
        return show_message(
            request,
            'Something wrong when approve computing resource: ' + e.__str__())
Beispiel #11
0
 def test_pretty_print(self):
     self.message.append({
         'direction': 'Recv',
         'info_type': 'test',
         'info_data': 'TEST',
         'user_name': '1',
         'text': 'text1'
     })
     self.message.append({
         'direction': 'Send',
         'info_type': 'aaa',
         'info_data': '111',
         'user_name': '2',
         'text': 'text2'
     })
     self.message.append({
         'direction': 'Send',
         'info_type': 'bbb',
         'info_data': '222',
         'user_name': '3',
         'text': 'text3'
     })
     self.message.append({
         'direction': 'Send',
         'info_type': 'bbb',
         'info_data': '222',
         'user_name': '4',
         'text': 'text4'
     })
     self.message.append({
         'direction': 'Send',
         'info_type': '',
         'user_name': '5',
         'text': 'text5'
     })
     tmp = Message(origin=self.message.pretty_print().decode())
     self.assertEqual(tmp.index(3)['direction'], 'Send')
     self.assertEqual(tmp.index(3)['info_type'], 'bbb')
     self.assertEqual(tmp.index(3)['info_data'], '222')
     self.assertEqual(tmp.index(3)['user_name'], '4')
     self.assertEqual(tmp.index(3)['text'], 'text4')
Beispiel #12
0
def get_context_computing(comp):
    dc = {}
    dc['id'] = comp.id
    dc['name'] = comp.name
    dc['status'] = comp.get_status_display()
    dc['package_name'] = comp.pack_name
    dc['type'] = comp.get_pc_type_display()
    dc['cpu'] = comp.cpu
    dc['memory'] = comp.memory
    dc['disk'] = comp.disk
    dc['disktype'] = comp.get_disk_type_display()
    dc['ip'] = comp.address
    dc['os'] = comp.os
    dc['login'] = comp.login
    dc['initial_password'] = comp.password
    # dc['expire_time'] = comp.expire_time.strftime('%Y-%m-%d')
    dc['name'] = comp.account.real_name
    dc['flag'] = comp.flag
    dc['sn'] = comp.sn
    dc['data_content'] = comp.data_content
    dc['note'] = Message(comp.note).last()['text']
    return dc
Beispiel #13
0
 def test_tostring_origin(self):
     self.message.append({
         'direction': 'Recv',
         'info_type': 'test',
         'info_data': 'TEST',
         'user_name': '1',
         'text': 'text1'
     })
     self.message.append({
         'direction': 'Send',
         'info_type': 'aaa',
         'info_data': '111',
         'user_name': '2',
         'text': 'text2'
     })
     self.message.append({
         'direction': 'Send',
         'info_type': 'bbb',
         'info_data': '222',
         'user_name': '3',
         'text': 'text3'
     })
     self.message.append({
         'direction': 'Send',
         'info_type': 'bbb',
         'info_data': '222',
         'user_name': '4',
         'text': 'text4'
     })
     self.message.append({
         'direction': 'Send',
         'info_type': '',
         'user_name': '5',
         'text': 'text5'
     })
     tmp = Message(origin=self.message.tostring().decode())
     self.assertEqual(self.message.tostring(), tmp.tostring())