Exemplo n.º 1
0
Arquivo: admin.py Projeto: kes1smmn/TS
def tsvm_control(request, action=''):
    if request.method == 'GET':
        log_files = []
        for logfile in ["provisioning.log", "running.log"]:
            if os.path.exists(os.path.join("/var/log/ion/", logfile)):
                log_files.append(logfile)

        ctxd = {
            'versions': tsvm.versions(),
            'status': tsvm.status(),
            'host': request.META.get('HTTP_HOST'),
            'log_files': log_files
        }
        return render_to_response("admin/tsvm_control.html", RequestContext(request, ctxd))

    elif request.method == 'POST':
        if "setup" in action:
            version = request.REQUEST.get('version', '')
            response_object = tsvm.setup(version)
        elif action in ["start", "stop", "suspend", "destroy"]:
            response_object = tsvm.ctrl(action)
        elif "status" in action:
            response_object = tsvm.status()
        elif "check_update" in action:
            stdout = subprocess.check_output(['sudo', '/opt/ion/iondb/bin/ion_check_for_new_tsvm.py'])
            response_object = json.loads(stdout)
        elif "update" in action:
            response_string = subprocess.check_output(['sudo', '/opt/ion/iondb/bin/install_new_tsvm.py'])
            response_object = json.load(response_string)
        else:
            return http.HttpResponseBadRequest('Error: unknown action type specified: %s' % action)

        return http.HttpResponse(json.dumps(response_object), content_type='application/json')
Exemplo n.º 2
0
Arquivo: admin.py Projeto: skner/TS
def tsvm_control(request, action=''):

    if request.method == 'GET':
        status = tsvm.status()
        versions = tsvm.versions()
        log_files = []
        for logfile in ["provisioning.log", "running.log"]:
            if os.path.exists(os.path.join("/var/log/ion/", logfile)):
                log_files.append(logfile)

        ctxd = {
            'versions': versions.split() if len(versions) > 0 else '',
            'status': status,
            'host': request.META.get('HTTP_HOST'),
            'log_files': log_files
        }
        return render_to_response("admin/tsvm_control.html",
                                  RequestContext(request, ctxd))

    elif request.method == 'POST':
        if "setup" in action:
            version = request.REQUEST.get('version', '')
            response_object = tsvm.setup(version)
        elif action in ["start", "stop", "suspend", "destroy"]:
            response_object = tsvm.ctrl(action)
        elif "status" in action:
            response_object = tsvm.status()
        elif "check_update" in action:
            async_result = tsvm.check_for_new_tsvm.delay()
            response_object = async_result.get()
        elif "update" in action:
            async_result = tsvm.install_new_tsvm.delay()
            response_object = async_result.get()
        else:
            return http.HttpResponseBadRequest(
                'Error: unknown action type specified: %s' % action)

        return http.HttpResponse(json.dumps(response_object),
                                 content_type='application/json')
Exemplo n.º 3
0
Arquivo: admin.py Projeto: skner/TS
def tsvm_control(request, action=''):

    if request.method == 'GET':
        status = tsvm.status()
        versions = tsvm.versions()
        log_files = []
        for logfile in ["provisioning.log", "running.log"]:
            if os.path.exists(os.path.join("/var/log/ion/",logfile)):
                log_files.append(logfile)

        ctxd = {
            'versions': versions.split() if len(versions) > 0 else '',
            'status': status,
            'host': request.META.get('HTTP_HOST'),
            'log_files': log_files
        }
        return render_to_response("admin/tsvm_control.html", RequestContext(request, ctxd))
    
    elif request.method == 'POST':
        if "setup" in action:
            version = request.REQUEST.get('version','')
            response_object = tsvm.setup(version)
        elif action in ["start","stop","suspend","destroy"]:
            response_object = tsvm.ctrl(action)
        elif "status" in action:
            response_object = tsvm.status()
        elif "check_update" in action:
            async_result = tsvm.check_for_new_tsvm.delay()
            response_object = async_result.get()
        elif "update" in action:
            async_result = tsvm.install_new_tsvm.delay()
            response_object = async_result.get()
        else:
            return http.HttpResponseBadRequest('Error: unknown action type specified: %s' % action)
    
        return http.HttpResponse(json.dumps(response_object), content_type='application/json')