示例#1
0
 def test_get_aws_cloudinstances_list(self):
     APIClient(enforce_csrf_checks=True)
     app = ApplicationBasicInfo(owner=self.user, name="demo", description="name", public=True, client_downloads=0)
     app.save()
     url = reverse("AWSCloudInstancesList", kwargs={"appid": 1})
     response = self.client.get(url, format="json")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#2
0
 def test_get_aws_cloudinstances_list(self):
     APIClient(enforce_csrf_checks=True)
     app = ApplicationBasicInfo(owner=self.user,name="demo",description="name",public=True,client_downloads=0)
     app.save()
     url = reverse('AWSCloudInstancesList',kwargs={'appid':1})
     response = self.client.get(url,format='json')
     self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#3
0
    def test_detach_app_from_group(self):
        """
            Test to detach application from the group
        """
        APIClient(enforce_csrf_checks=True)
        app = ApplicationBasicInfo(owner=self.user, name="demo", description="name", public=True, client_downloads=0)
        app.save()
        mg = MyGroup(name="demo", description="demo description", owner="foo", group_role="Owner")
        mg.save()
        gat = GroupApplicationTag(group=mg, tagname="tagname", description="tagdesc", tagid="tagid", application=app)
        gat.save()
        url = reverse("detachapp", kwargs={"appid": 1})

        response = self.client.post(url, format="json")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#4
0
    def test_detach_app_from_group(self):
        """
            Test to detach application from the group
        """
        APIClient(enforce_csrf_checks=True)
        app = ApplicationBasicInfo(owner=self.user,name="demo",description="name",public=True,client_downloads=0)
        app.save()
        mg = MyGroup(name="demo",description="demo description",owner="foo", group_role ='Owner')
        mg.save()
        gat = GroupApplicationTag(group=mg,tagname='tagname',description='tagdesc',tagid='tagid',application=app)
        gat.save()
        url = reverse('detachapp',kwargs={'appid':1})

        response = self.client.post(url,format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
示例#5
0
 def test_attach_app_to_group(self):
     """
         Attaches application to the group
     """
     APIClient(enforce_csrf_checks=True)
     mg = MyGroup(name="demo", description="demo description", owner="foo", group_role="Owner")
     mg.save()
     mg.user.add(self.user)
     app = ApplicationBasicInfo(owner=self.user, name="demo", description="name", public=True, client_downloads=0)
     app.save()
     url = reverse("attachapp", kwargs={"groupid": 1})
     data = {"tagname": "tagname", "tagdesc": "tagdesc", "tagid": "tagid", "appid": 1}
     mg = MyGroup(name="demo", description="demo description", owner="foo", group_role="Owner")
     mg.save()
     mg.user.add(self.user)
     response = self.client.post(url, data, format="json")
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
示例#6
0
 def test_attach_app_to_group(self):
     """
         Attaches application to the group
     """
     APIClient(enforce_csrf_checks=True)
     mg = MyGroup(name="demo",description="demo description",owner="foo", group_role ='Owner')
     mg.save()
     mg.user.add(self.user)
     app = ApplicationBasicInfo(owner=self.user,name="demo",description="name",public=True,client_downloads=0)
     app.save()
     url = reverse('attachapp',kwargs={'groupid':1})
     data = {'tagname':'tagname','tagdesc':'tagdesc','tagid':'tagid','appid':1}
     mg = MyGroup(name="demo",description="demo description",owner="foo", group_role ='Owner')
     mg.save()
     mg.user.add(self.user)
     response = self.client.post(url,data,format='json')
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
 def create(self, request, *args, **kwargs):
     data = request.DATA
     name = data.get('name')
     public = data.get('public')
     if public == 'on':
         public = True
     else:
         public = False
     desc = data.get('description')
     keywords = data.get('keywords')
     client_downloads = data.get('client_downloads')
     new_app = ApplicationBasicInfo(owner =self.request.user ,name=name,description=desc,client_downloads=client_downloads,
                                    keywords = keywords,public=public)
     new_app.save()
     created_data = ApplicationBasicInfo.objects.filter(id=new_app.id)
     serializer = MyApplicationSerializer(created_data)
     headers = self.get_success_headers(serializer.data)
     #return Response(serializer.data, status=201, headers=headers)
     return HttpResponse("Application Created Successfully!", status=202)
示例#8
0
 def create(self, request, *args, **kwargs):
     data = request.DATA
     name = data.get('name')
     public = data.get('public')
     if public == 'on':
         public = True
     else:
         public = False
     desc = data.get('description')
     keywords = data.get('keywords')
     client_downloads = data.get('client_downloads')
     new_app = ApplicationBasicInfo(owner=self.request.user,
                                    name=name,
                                    description=desc,
                                    client_downloads=client_downloads,
                                    keywords=keywords,
                                    public=public)
     new_app.save()
     created_data = ApplicationBasicInfo.objects.filter(id=new_app.id)
     serializer = MyApplicationSerializer(created_data)
     headers = self.get_success_headers(serializer.data)
     #return Response(serializer.data, status=201, headers=headers)
     return HttpResponse("Application Created Successfully!", status=202)
示例#9
0
def application_provider_view_data(request):
    formErrorVal = False

    if request.method == "POST":
        # If we've not come from the welcome page then we can
        # look for a valid form to parse, otherwise there's no point.
        if "cancelWelcome" not in request.POST:
            # We've received a standard post from the CG page and there
            # may be an application form and request to register an app
            form = ApplicationBasicInfoForm(request.POST, request=request)

            if form.is_valid():
                name = form.cleaned_data["name"]
                desc = form.cleaned_data["description"]
                image_id = form.cleaned_data["image_id"]
                image_location = form.cleaned_data["image_location"]
                public = form.cleaned_data["public"]
                additional_information = form.cleaned_data["additional_Information"]

                print "APP REGISTRATION FORM VALID:"
                print "\tName: " + name
                print "\tDescription: " + desc
                print "\tImage ID: " + image_id
                print "\tImage location: " + str(image_location)
                print "\tPublic: " + str(public)
                print "\tAdditionalInformation: " + str(additional_information)

                # Now create the application model and store it
                app = ApplicationBasicInfo(
                    owner=request.user,
                    name=name,
                    description=desc,
                    client_downloads=0,
                    image_id=image_id,
                    image_location=str(image_location),
                    public=public,
                )
                app.save()

                print "Created new application with new ID: " + str(app.id)

                # Now that the model is stored, we switch the associated
                # files to stored status and set the owning application to
                # the one that's just been created.
                tempfiles = ApplicationFile.objects.filter(file_type="T", owner_id=request.user)
                for tempfile in tempfiles:
                    tempfile.file_type = "S"
                    tempfile.application = app
                    tempfile.save()

                # Generate the identicon for the application
                fs = FileSystemStorage()
                icon_location = os.path.join(fs.location, "..", "static", "img", "ident", str(app.id) + ".png")
                print "Debug: IconLocation is %s" % (icon_location)
                gen_icon.create_icon(icon_location)

                app.iconfile = os.path.join("img", "ident", str(app.id) + ".png")
                app.save()

            else:
                print "APP REGISTRATION FORM IS NOT VALID..."
                active_tab = "NA"
                form = ApplicationBasicInfoForm()
                formErrorVal = True

        else:
            form = ApplicationBasicInfoForm()

    else:
        form = ApplicationBasicInfoForm()

    # Populate the application list
    apps = ApplicationBasicInfo.objects.filter(owner=request.user)
    # Get the list of app ids that we're going to look up application files for.
    app_ids = []
    for app in apps:
        app_ids.append(app.id)  # Appending the all app id in the app_id list
    print "Looking up file for apps: " + str(app_ids)
    files = ApplicationFile.objects.filter(
        owner_id=request.user, file_type="S", application__in=app_ids
    )  # __in django filter list

    os_images = ApplicationOpenstackImages.objects.filter(application__in=app_ids)
    ec2_images = ApplicationEC2Images.objects.filter(application__in=app_ids)

    # We now have a list of files for all the applications of the request.user.
    # For each application, prepare a new list. Each item in the list
    # will be a dict containing the details about a file for an application.
    # This list will then be added to the file_info_dict with the key
    # as the app id.
    file_info_dict = {}

    file_formats = {
        "NONE": "Local file (Unknown type)",
        "HD": "Local image (RAW_ID)",
        "IMG": "Local image (RAW_Image)",
        "VDI": "Local image (Virtualbox)",
        "VMDK": "Local image (VMware VMDK)",
        "ISO": "CD/DVD ROM Image",
        "OVF": "OVF Appliance",
        "OVA": "Local Appliance Archive (OVA)",
    }

    for appfile in files:
        if appfile.application.id not in file_info_dict:
            file_info_dict[appfile.application.id] = []
        file_info = {}
        file_info["appfile"] = appfile
        file_info["name"] = appfile.filename()
        # FIXME: Need a more foolproof way to get the file path for the link
        file_info["path"] = os.path.join("media", request.user.username, appfile.filename())
        print appfile.file_format
        file_info["formatstring"] = file_formats[appfile.file_format]
        file_info["image_type"] = appfile.image_type
        file_info_dict[appfile.application.id].append(file_info)
    ## Current role appended  in session
    user_info_list = UserInfo.objects.filter(user=request.user)
    role = user_info_list[0].user_primary_role_desc
    branches = Branch.objects.all()
    category = Category.objects.all()
    subcategory = SubCategory.objects.all()

    return (branches, category, subcategory, form, apps, formErrorVal, file_info_dict, os_images, ec2_images, role)
示例#10
0
def application_provider_view_data(request):
    formErrorVal = False

    if request.method == 'POST':
        # If we've not come from the welcome page then we can
        # look for a valid form to parse, otherwise there's no point.
        if 'cancelWelcome' not in request.POST:
            # We've received a standard post from the CG page and there
            # may be an application form and request to register an app
            form = ApplicationBasicInfoForm(request.POST, request=request)

            if form.is_valid():
                name = form.cleaned_data['name']
                desc = form.cleaned_data['description']
                image_id = form.cleaned_data['image_id']
                image_location = form.cleaned_data['image_location']
                public = form.cleaned_data['public']
                additional_information = form.cleaned_data['additional_Information']

                print "APP REGISTRATION FORM VALID:"
                print "\tName: " + name
                print "\tDescription: " + desc
                print "\tImage ID: " + image_id
                print "\tImage location: " + str(image_location)
                print "\tPublic: " + str(public)
                print "\tAdditionalInformation: " + str(additional_information)

                # Now create the application model and store it
                app = ApplicationBasicInfo(owner=request.user, name=name,
                                  description=desc, client_downloads=0,
                                  image_id=image_id, image_location=str(image_location), public=public)
                app.save()

                print 'Created new application with new ID: ' + str(app.id)

                # Now that the model is stored, we switch the associated
                # files to stored status and set the owning application to
                # the one that's just been created.
                tempfiles = ApplicationFile.objects.filter(file_type='T', owner_id=request.user)
                for tempfile in tempfiles:
                    tempfile.file_type='S'
                    tempfile.application = app
                    tempfile.save()

                # Generate the identicon for the application
                fs = FileSystemStorage()
                icon_location = os.path.join(fs.location, '..', 'static', 'img', 'ident', str(app.id)+'.png')
                print "Debug: IconLocation is %s" %(icon_location)
                gen_icon.create_icon(icon_location)

                app.iconfile = os.path.join('img', 'ident', str(app.id)+'.png')
                app.save()

            else:
                print "APP REGISTRATION FORM IS NOT VALID..."
                active_tab = 'NA'
                form = ApplicationBasicInfoForm()
                formErrorVal = True

        else:
            form = ApplicationBasicInfoForm()

    else:
        form = ApplicationBasicInfoForm()


    # Populate the application list
    apps = ApplicationBasicInfo.objects.filter(owner=request.user)
    # Get the list of app ids that we're going to look up application files for.
    app_ids = []
    for app in apps:
        app_ids.append(app.id) #Appending the all app id in the app_id list
    print 'Looking up file for apps: ' + str(app_ids)
    files = ApplicationFile.objects.filter(owner_id=request.user, file_type='S', application__in=app_ids) #__in django filter list

    os_images = ApplicationOpenstackImages.objects.filter(application__in=app_ids)
    ec2_images = ApplicationEC2Images.objects.filter(application__in=app_ids)

    # We now have a list of files for all the applications of the request.user.
    # For each application, prepare a new list. Each item in the list
    # will be a dict containing the details about a file for an application.
    # This list will then be added to the file_info_dict with the key
    # as the app id.
    file_info_dict = {}

    file_formats = { 'NONE': 'Local file (Unknown type)',
                   'HD' : 'Local image (RAW_ID)',
                   'IMG' : 'Local image (RAW_Image)',
                   'VDI' : 'Local image (Virtualbox)',
                   'VMDK': 'Local image (VMware VMDK)',
                   'ISO' : 'CD/DVD ROM Image',
                   'OVF' : 'OVF Appliance',
                   'OVA' : 'Local Appliance Archive (OVA)'}

    for appfile in files:
        if appfile.application.id not in file_info_dict:
            file_info_dict[appfile.application.id] = []
        file_info = {}
        file_info['appfile'] = appfile
        file_info['name'] = appfile.filename()
        # FIXME: Need a more foolproof way to get the file path for the link
        file_info['path'] = os.path.join('media', request.user.username, appfile.filename())
        print appfile.file_format
        file_info['formatstring'] = file_formats[appfile.file_format]
        file_info['image_type'] = appfile.image_type
        file_info_dict[appfile.application.id].append(file_info)
## Current role appended  in session
    user_info_list = UserInfo.objects.filter(user=request.user)
    role = user_info_list[0].user_primary_role_desc
    branches = Branch.objects.all()
    category = Category.objects.all()
    subcategory = SubCategory.objects.all()

    return  (branches,category,subcategory,form,apps,formErrorVal, file_info_dict, os_images, ec2_images,role)