예제 #1
0
def launchserver(request, appid, launchtype):
    print "Request to launch cloud server for application: " + appid
    print "requesting user is " + str(request.user.id)

    appTag = "NONE"
    endpoint = request.POST['endpoint']
    instance_type = request.POST['resource_type']
    #instance_type = 'Large'
    alias = request.POST['alias']
    recordId = request.POST['recordId']

    appTag = request.POST.get('appTag', '')
    cloud = recordId.split(':')[0]
    imageRecord = recordId.split(':')[1]

    if appTag == "":
        appTag = "NONE"

    print instance_type
    print 'appTag received' + appTag
    print 'Launch server on cloud <' + cloud + '> with image record <' + imageRecord + '> using credential alias <' + alias + '> and cloud url <' + endpoint + '>'

    # Lookup credentials for this user and the specified endpoint
    if cloud == 'os':
        cred = UserCloudCredentials.objects.get(user=request.user,
                                                endpoint=endpoint,
                                                key_alias=alias)
        image_info = ApplicationOpenstackImages.objects.get(id=imageRecord)
    elif cloud == 'ec2':
        # TODO: Add EC2 support
        cred = UserCloudCredentials.objects.get(user=request.user,
                                                endpoint=endpoint,
                                                key_alias=alias)
        image_info = ApplicationEC2Images.objects.get(id=imageRecord)
    else:
        #TODO: Add error checking
        # Error, an invalid cloud was specified
        pass

    app = ApplicationBasicInfo.objects.get(id=appid)
    try:
        rec = UsersApplications.objects.get(user=request.user, application=app)
        rec.run_count = rec.run_count + 1
        print "Updated run count in UsersApplications"
    except UsersApplications.DoesNotExist:
        rec = UsersApplications(user=request.user, application=app)
        print "Inserted new record to UsersApplications"
    rec.save()

    return start_server(appid, cred, endpoint, cloud, imageRecord, appTag,
                        instance_type, image_info, request)
예제 #2
0
def launchserver(request, appid, launchtype):
    print "Request to launch cloud server for application: " + appid
    print "requesting user is " + str(request.user.id)

    appTag = "NONE"
    endpoint = request.POST['endpoint']
    instance_type = request.POST['resource_type']
    #instance_type = 'Large'
    alias = request.POST['alias']
    recordId = request.POST['recordId']

    appTag = request.POST.get('appTag', '')
    cloud = recordId.split(':')[0]
    imageRecord = recordId.split(':')[1]

    if appTag =="":
        appTag = "NONE"

    print instance_type
    print 'appTag received' + appTag
    print 'Launch server on cloud <' + cloud + '> with image record <' + imageRecord + '> using credential alias <' + alias + '> and cloud url <' + endpoint + '>'
    
    # Lookup credentials for this user and the specified endpoint
    if cloud == 'os':
        cred = UserCloudCredentials.objects.get(user=request.user, endpoint=endpoint, key_alias=alias)
        image_info = ApplicationOpenstackImages.objects.get(id=imageRecord)
    elif cloud == 'ec2':
        # TODO: Add EC2 support
        cred = UserCloudCredentials.objects.get(user=request.user, endpoint=endpoint, key_alias=alias)
        image_info = ApplicationEC2Images.objects.get(id=imageRecord)
    else:
        #TODO: Add error checking
        # Error, an invalid cloud was specified
        pass

    app = ApplicationBasicInfo.objects.get(id=appid)
    try:
        rec = UsersApplications.objects.get(user=request.user,application=app)   
        rec.run_count = rec.run_count + 1             
        print "Updated run count in UsersApplications"   
    except UsersApplications.DoesNotExist:
        rec = UsersApplications(user=request.user,application=app)          
        print "Inserted new record to UsersApplications"   
    rec.save()

        
    return start_server(appid, cred, endpoint, cloud, imageRecord, appTag, instance_type, image_info, request)
예제 #3
0
def launchapp(request, appid, launchtype, apptag):
    print "Request to launch app with ID <" + appid + "> and launch type <" + launchtype + ">" + "> with tag name <" + apptag + ">"
    print "requesting user is " + str(request.user.id)

    appObject = ApplicationBasicInfo.objects.get(id=appid)
    app_files = ApplicationFile.objects.filter(file_type='S',
                                               application_id=appid,
                                               image_type='C')
    print "Found " + str(len(app_files)) + " files for this application."

    print "Using file locations: "
    for app in app_files:
        print "File: " + app.file.name + " for app <" + app.application.name + ">"

    if len(app_files) == 0:
        return HttpResponse("<h1> No image available to launch</h1>")
    else:
        vm_name = str(app.application.name)
        app_owner = str(
            ApplicationBasicInfo.objects.filter(id=appid)[0].owner.username)
        #request.user.get_username()
        launcher_args = '    <argument>' + vm_name + '</argument>'
        #launcher_args = ''
        for app in app_files:
            launcher_args += '\n    <argument>' + os.path.join(
                request.build_absolute_uri("/"), 'media', app_owner, vm_name,
                os.path.basename(app.file.name)) + '</argument>'

        fs = FileSystemStorage()

        filedir = os.path.join(fs.location, 'jnlp',
                               request.user.get_username())

        if not os.path.isdir(filedir):
            os.makedirs(filedir, 0700)
            print "Created user directory for JNLP launch files: " + filedir

        jnlp_file_name = tempfile.mktemp(suffix='.jnlp', dir=filedir)
        jnlp_file_url_path = os.path.join('/media', 'jnlp',
                                          request.user.get_username(),
                                          os.path.basename(jnlp_file_name))
        executable_file_name = os.path.join(
            fs.location, 'isocreator', os.path.basename(ISO_GENERATOR_EXE))
        print "executable file" + executable_file_name
        if apptag != "NONE":
            print "Create an ISO with Group <" + apptag + ">"
            (tagname, tagid) = str(apptag).split("-")

            if tagname.lower() == 'vas':
                print "create  VAS contextualized ISO"
                iso_file_name = tempfile.mktemp(suffix='.iso', dir=filedir)
                iso_file_url_path = os.path.join(
                    '/media', 'jnlp', request.user.get_username(),
                    os.path.basename(iso_file_name))
                arg = [executable_file_name] + [tagid] + [iso_file_name]
                subprocess.call(arg)
                launcher_args += '\n    <argument>' + os.path.join(
                    request.build_absolute_uri("/"), 'media', 'jnlp',
                    request.user.get_username(),
                    os.path.basename(iso_file_name)) + '</argument>'
            elif tagname.lower() == 'boinc':
                print "create BOINC contextualized ISO"
            else:
                pass
        else:
            pass

        # We now generate the jnlp file which will be returned to the client in order
        # to begin the webstart process that will download and run the image.
        jnlp_properties = {
            'base_url': request.build_absolute_uri("/"),
            'jnlp_location': jnlp_file_url_path,
            'app_name': app.application.name,
            'launcher_args': launcher_args,
        }

        formatted_jnlp = jnlp_base.format(**jnlp_properties)

        print "Formatted JNLP: " + formatted_jnlp

        # Write JNLP file to the filesystem
        with open(jnlp_file_name, 'w') as f:
            f.write(formatted_jnlp)

        appObject.client_downloads = appObject.client_downloads + 1
        appObject.save()
        print "Updated client_download in ApplicationBasicInfo"

        try:
            rec = UsersApplications.objects.get(user=request.user,
                                                application=appObject)
            rec.run_count = rec.run_count + 1
            print "Updated run count in UsersApplications"
        except UsersApplications.DoesNotExist:
            rec = UsersApplications(user=request.user, application=appObject)
            print "Inserted new record to UsersApplications"
        rec.save()

        return HttpResponse(formatted_jnlp,
                            content_type='application/x-java-jnlp-file')
예제 #4
0
def launchapp(request, appid, launchtype, apptag):
    print "Request to launch app with ID <" + appid + "> and launch type <" + launchtype + ">" + "> with tag name <" + apptag +">"
    print "requesting user is " + str(request.user.id)

    appObject = ApplicationBasicInfo.objects.get(id=appid)
    app_files = ApplicationFile.objects.filter( file_type='S', application_id=appid,image_type='C')
    print "Found " + str(len(app_files)) + " files for this application."

    print "Using file locations: "
    for app in app_files:
        print "File: " + app.file.name + " for app <" + app.application.name + ">"

    if len(app_files) == 0:
        return HttpResponse("<h1> No image available to launch</h1>")
    else:
        vm_name = str(app.application.name)
        app_owner = str(ApplicationBasicInfo.objects.filter(id=appid)[0].owner.username)
        #request.user.get_username()
        launcher_args = '    <argument>' + vm_name + '</argument>'
        #launcher_args = ''
        for app in app_files:
            launcher_args += '\n    <argument>' + os.path.join(request.build_absolute_uri("/"), 'media', app_owner, vm_name, os.path.basename(app.file.name)) + '</argument>'

        fs = FileSystemStorage()

        filedir = os.path.join(fs.location, 'jnlp', request.user.get_username())

        if not os.path.isdir(filedir):
            os.makedirs(filedir, 0700)
            print "Created user directory for JNLP launch files: " + filedir

        jnlp_file_name = tempfile.mktemp(suffix='.jnlp', dir=filedir)
        jnlp_file_url_path = os.path.join('/media', 'jnlp', request.user.get_username(), os.path.basename(jnlp_file_name))
        executable_file_name = os.path.join(fs.location,'isocreator', os.path.basename(ISO_GENERATOR_EXE))
        print "executable file"+ executable_file_name
        if apptag != "NONE":
            print "Create an ISO with Group <" + apptag + ">"
            (tagname,tagid) = str(apptag).split("-")

            if tagname.lower() == 'vas':
                print "create  VAS contextualized ISO"
                iso_file_name = tempfile.mktemp(suffix='.iso', dir=filedir)
                iso_file_url_path = os.path.join('/media', 'jnlp', request.user.get_username(), os.path.basename(iso_file_name))
                arg = [executable_file_name] + [tagid] + [iso_file_name]
                subprocess.call(arg)
                launcher_args += '\n    <argument>' + os.path.join(request.build_absolute_uri("/"), 'media', 'jnlp', request.user.get_username(), os.path.basename(iso_file_name)) + '</argument>'
            elif tagname.lower() == 'boinc':
                print "create BOINC contextualized ISO"
            else:
                pass
        else:
            pass

        # We now generate the jnlp file which will be returned to the client in order
        # to begin the webstart process that will download and run the image.
        jnlp_properties = {'base_url': request.build_absolute_uri("/"),
                           'jnlp_location': jnlp_file_url_path,
                           'app_name': app.application.name,
                           'launcher_args': launcher_args,
                           }

        formatted_jnlp = jnlp_base.format(**jnlp_properties)

        print "Formatted JNLP: "+ formatted_jnlp

        # Write JNLP file to the filesystem
        with open(jnlp_file_name, 'w') as f:
            f.write(formatted_jnlp)


        appObject.client_downloads = appObject.client_downloads + 1
        appObject.save()
        print "Updated client_download in ApplicationBasicInfo"   
         
        try:
            rec = UsersApplications.objects.get(user=request.user,application=appObject)   
            rec.run_count = rec.run_count + 1             
            print "Updated run count in UsersApplications"   
        except UsersApplications.DoesNotExist:
            rec = UsersApplications(user=request.user,application=appObject)          
            print "Inserted new record to UsersApplications"   
        rec.save()
    
        return HttpResponse(formatted_jnlp, content_type='application/x-java-jnlp-file')