Пример #1
0
def restart(request):
    if request.method == 'POST':
        domain_name = request.POST.get('domain_name')
        cmds = 'python /opt/kvm.py restart_api %s' % domain_name
        arg = server['bob']
        ssh_client.ssh_cmd(arg['ip'], arg['username'], arg['password'], cmds)
        return HttpResponseRedirect("/servicelist/kvm")
    else:
        return HttpResponseRedirect("/servicelist/kvm")
Пример #2
0
def pinfo(request):
    if request.method == 'GET':
        id = request.GET.get('id')
        usual_username = '******'
        usual_passwd = 'dzH8KLewRT49WWuNbESI'
        upload_path = 'C:\Users\pc\Desktop\qkyunwei\upload\\getinfo.py'
        accept_path = '/tmp/getinfo.py'
        sql = "select ip,username,project_name,passwd from server_info where id='%s'" % (
            id)
        ip, username, project_name, password = ssh_client.get_parameter(sql)
        if username == None:
            username = usual_username
        if password == None:
            password = usual_passwd
        cmds = 'python /tmp/getinfo.py %s' % (project_name)
        ssh_client.upload_file(ip, username, password, upload_path,
                               accept_path)
        info = ssh_client.ssh_cmd(ip, username, password, cmds)[0]
        info = eval(info)
        print info[0], info[1], info[2]
        dict = {
            "project_name": project_name,
            "port": info[0],
            "path": info[1],
            "docBase": info[2],
            "url": 'http://' + ip + ':' + info[0] + info[1]
        }

    return JsonResponse(dict)
Пример #3
0
def api(request):
    if request.method == 'GET':
        cmds = 'python /opt/kvm.py data_api'
        arg = server['bob']
        info = ssh_client.ssh_cmd(arg['ip'], arg['username'], arg['password'],
                                  cmds)[0]
        info = eval(info)['list']
        #return HttpResponse(json.dumps(info),content_type="application/json")
    return render(request, 'kvm.html', {'info': info, 'ip': arg['ip']})
Пример #4
0
def listinfo(request):
    get_info = Service.objects.all()
    if request.method == 'POST':
        upload_path = 'C:\Users\pc\Desktop\qkyunwei\upload\\restart.py'
        accept_path = '/tmp/restart.py'
        usual_username = '******'
        usual_passwd = 'dzH8KLewRT49WWuNbESI'
        pname = request.POST['pname']
        service_id = request.POST['service_id']
        cmds = 'python /tmp/restart.py %s' % (pname)
        sql = "select ip,username,passwd from server_info where id='%s'" % (
            service_id)
        ip, username, password = ssh_client.get_parameter(sql)
        if username == None:
            username = usual_username
        if password == None:
            password = usual_passwd
        ssh_client.upload_file(ip, username, password, upload_path,
                               accept_path)
        ssh_client.ssh_cmd(ip, username, password, cmds)
        return render(request, 'list.html', locals())
    else:
        return render(request, 'list.html', locals())