Beispiel #1
0
def addnew(request):
	groups = request.META.get('ADFS_GROUP','')
	groupsList = groups.split(';') ;
	userIsSuperUser = isSuperUser(groupsList)
	## Check user cloudman resource manager privileges
	if not userIsSuperUser:
		message = "You don't have cloudman resource manager privileges. Hence you are not authorized to add new Region";
		html = "<html><body> %s.</body></html>" % message
		return HttpResponse(html)
	if request.method == 'POST':
		form = RegionForm(request.POST)
		### Check whether all the fields for creating a region are provided with non-empty values
		if form.is_valid():
			redirectURL = '/cloudman/message/?msg='
			name = form.cleaned_data['name']
			regionExists = checkNameIgnoreCase(name)
			if regionExists:
				msgAlreadyExists = 'Region ' + name + ' already exists. Hence Add Region Operation Stopped'
				return HttpResponseRedirect(redirectURL + msgAlreadyExists)
			description = form.cleaned_data['description']
			admin_group = form.cleaned_data['admin_group']
			comment = form.cleaned_data['comment']	
			## Check that name provided as admin_group exists in the EGroups TABLE
			## If not, then check its existence in external egroup database through ldap
			## If not present there also, then raise an alert or else add the group name to EGroups table also
			egroup = None
			try:
				egroup = Egroups.objects.get(name=admin_group)
			except Egroups.DoesNotExist:
				if not (checkEGroup(admin_group)):
					errorMessage = 'Selected Admin E-Group ' + admin_group + ' does not exists'
					return HttpResponseRedirect(redirectURL + errorMessage)
				egroup = Egroups(name=admin_group)
				egroup.save()
			## Create the Region with all the required values
			regionObj = Region(name=name, description=description, admin_group=egroup)
			regionObj.save()
			regionObj = Region.objects.get(name=name)
			if addLog(request,name,comment,regionObj,None,'region','add',True):
				transaction.commit()
				## Return the Success message
				msgSuccess = 'New region ' + name  + ' added successfully'
			else:
				transaction.rollback()
				msgSuccess = 'Error in creating New region ' + name				
			html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/region/list/\"></HEAD><body> %s.</body></html>" % msgSuccess
			return HttpResponse(html)
	else:
		## If not POST operation, then return the Region Creation Form
		form = RegionForm()
	return render_to_response('region/addnew.html',locals(),context_instance=RequestContext(request))
Beispiel #2
0
def addnew(request):
    groups = request.META.get('ADFS_GROUP','')
    groupsList = groups.split(';') ;
    ## Check the user has cloudman resource manager privileges
    userIsSuperUser = isSuperUser(groupsList)  
    '''if not userIsSuperUser:
          message = "You don't have cloudman resource manager privileges. Hence you are not authorized to add new Group";
          html = "<html><body> %s.</body></html>" % message
          return HttpResponse(html)
    '''
    ## if the request is through form submission, then add the group or else return a new form 
    if request.method == 'POST':
        ## Validate the form by checking whether all the required values are provided or not
        form = GroupsForm(request.POST)
        if form.is_valid():
            redirectURL = '/cloudman/message/?msg='
            name = form.cleaned_data['name']
            groupExists = checkNameIgnoreCase(name)
            if groupExists:
                msgAlreadyExists = 'Group ' + name + ' already exists. Hence Add Group Operation Failed'
                return HttpResponseRedirect(redirectURL + msgAlreadyExists);
            description = form.cleaned_data['description']
            admin_group = form.cleaned_data['admin_group']
            comment = form.cleaned_data['comment']
            ## check first whether the admin_group exists in the local egroup table
            ## if not, then in the remote egroup database through ldap. If exists here, then add to the local table 
            egroup = None
            try:
                egroup = Egroups.objects.get(name=admin_group)
            except Egroups.DoesNotExist:
                if not (checkEGroup(admin_group)):
                    errorMessage = 'Admin E-Group Entered ' + admin_group + ' does not exists'
                    return HttpResponseRedirect(redirectURL + errorMessage)
                else:
                    egroup = Egroups(name=admin_group)
                    egroup.save()
            ## Create the group and return a success message to the user
            groupObj = Groups(name=name, description=description, admin_group=egroup)
            groupObj.save()
            groupObj = Groups.objects.get(name=name)
            if addLog(request,name,comment,groupObj,None,'group','add',True):                
                msgSuccess = 'New group ' + name  + ' added successfully'
            else:
                transaction.rollback()
                msgSuccess = 'Error in creating group ' + name              
            html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/group/list/\"></HEAD><body> %s.</body></html>" % msgSuccess
            return HttpResponse(html)
    else:
        form = GroupsForm()    
    return render_to_response('group/addnew.html',locals(),context_instance=RequestContext(request))
Beispiel #3
0
def update(request):
	regionName = request.REQUEST.get("name", "")
	redirectURL = '/cloudman/message/?msg='
	groups = request.META.get('ADFS_GROUP','')
	groupsList = groups.split(';') ;
	## Update is allowed if user has either cloudman resource manager privileges or 
	## belongs to the egroup selected as administrative e-group for this region
	if  not isUserAllowedToUpdateOrDeleteRegion(regionName,groupsList):
		message = "You neither have membership of administrative group of region " + regionName + " nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to Edit Region";
		html = "<html><body> %s.</body></html>" % message
		return HttpResponse(html)
	## Get the region Object
	regionObject = None
	try:
		regionObject = Region.objects.get(name=regionName)
	except Region.DoesNotExist:
		failureMessage = "Region with Name " + regionName + " could not be found"
		return HttpResponseRedirect(redirectURL+failureMessage)
	oldRegionInfo = getRegionInfo(regionObject)
	## If the current request is due to form submission then do update 
	## or else return to template to display the update form
	if request.method == 'POST':
	        ## Existing values
		currName = regionObject.name
		currDescription = regionObject.description
		currAdmin_group = regionObject.admin_group
		## New Values
		newName = request.POST['name']
		newDescription = request.POST['description']
		newAdmin_group = request.POST['admin_group']
		comment = request.REQUEST.get("comment", "")
		try:
			validate_name(newName)
			validate_descr(newDescription)
			validate_name(newAdmin_group)
			validate_comment(comment)
		except ValidationError as e:
			message ='Edit Region Form  '+', '.join(e.messages)
			html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/region/list/\"></HEAD><body> %s.</body></html>" % message
			return HttpResponse(html)
		## Check for atleast one field value change
		if ( (currName == newName) and (currDescription == newDescription) and (currAdmin_group == newAdmin_group) ):
			message = 'No New Value provided for any field to perform Edit Operation. Hence Edit Region ' + regionName + ' aborted'
			return HttpResponseRedirect(redirectURL + message)
		## Assign the new name to the region if it is changed
		if (currName != newName):
			if (newName == ''):
				errorMsg = 'Region name field cannot be left blank. So Edit Region operation stopped'
				return HttpResponseRedirect(redirectURL + errorMsg)
			regionExists = checkNameIgnoreCase(newName)
			if regionExists:
				msgAlreadyExists = 'Region ' + newName + ' already exists. Hence Edit Region Operation Stopped'
				return HttpResponseRedirect(redirectURL + msgAlreadyExists);
			regionObject.name = newName
		## Assign the new description if it is changed
		if (currDescription != newDescription):
			regionObject.description = newDescription
		## If admin egroup is changed, then first check its existence in the local egroups table
		## If not present, then check its existence in the external egroup database through ldap
		## If checked using external database and found, then add the egroup to the local egroups table
		## If not found both local and external, then return an error to the user
		egroup = None
		if (currAdmin_group != newAdmin_group):
			if (newAdmin_group == ''):
				errorMsg = 'Admin E-Group field cannot be left blank. So Edit Region operation stopped'
				return HttpResponseRedirect(redirectURL + errorMsg)
			try:
				egroup = Egroups.objects.get(name=newAdmin_group)
			except Egroups.DoesNotExist:
				if not (checkEGroup(newAdmin_group)):
					errorMessage = 'Selected Admin E-Group ' + newAdmin_group + ' does not exists'
					return HttpResponseRedirect(redirectURL + errorMessage)
				egroup = Egroups(name=newAdmin_group)
				egroup.save()
			regionObject.admin_group = egroup
		## Save the new values and return success message to the user
		regionObject.save()
		newRegionInfo = getRegionInfo(regionObject)
		objectId = regionObject.id 
		if addUpdateLog(request,newName,objectId,comment,oldRegionInfo,newRegionInfo,'region',True):
			transaction.commit()
			message = 'Region ' + regionName + ' Successfully Updated'
		else:
			message = 'Error in Updating Region ' + regionName
			transaction.rollback()
		html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/region/list/\"></HEAD><body> %s.</body></html>" % message

      		return HttpResponse(html)
        else:
                form=RegionForm();    

	return render_to_response('region/update.html',locals(),context_instance=RequestContext(request))
Beispiel #4
0
def update(request):
    groupName = request.REQUEST.get("name", "")
    redirectURL = '/cloudman/message/?msg='
    groups = request.META.get('ADFS_GROUP','')
    groupsList = groups.split(';') ;
    ## Allow only if the user has either cloudman resource manager privileges
    ## or user has membership of the administrative egroup selected for this group
    if not isUserAllowedToUpdateOrDeleteGroup(groupName,groupsList):
        message = "You neither have membership of administrative group of Group " + groupName + " nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to Edit Group";
        html = "<html><body> %s.</body></html>" % message
        return HttpResponse(html)	
    ## Get the Group Object
    groupObject = None
    try:
        groupObject = Groups.objects.get(name=groupName)
    except Groups.DoesNotExist:
        failureMessage = "Group with Name " + groupName + " could not be found"
        return HttpResponseRedirect(redirectURL+failureMessage)
    oldGroupInfo = getGroupInfo(groupObject)
    ## if the request is through form submission then update the fields, or else return to present an form for update
    if request.method == 'POST':
        ## Existing values
        currName = groupObject.name
        currDescription = groupObject.description
        currAdmin_group = groupObject.admin_group
        ## New Values
        newName = request.REQUEST.get("newname", "")
        newDescription = request.REQUEST.get("description", "")
        newAdmin_group = request.REQUEST.get("admin_group", "")
        comment = request.REQUEST.get("comment", "")
        try:
            validate_name(newName)
            validate_descr(newDescription)
            validate_name(newAdmin_group)
            validate_comment(comment)
        except ValidationError as e:
            message ='Edit Group Form  '+', '.join(e.messages)
            html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/group/list/\"></HEAD><body> %s.</body></html>" % message
            return HttpResponse(html)
        ## update is allowed if atleast one field value has been changed
        if ( (currName == newName) and (currDescription == newDescription) and (currAdmin_group == newAdmin_group) ):
            message = 'No New Value provided for any field to perform Edit Operation. Hence Edit Group ' + groupName + ' aborted'
            return HttpResponseRedirect(redirectURL + message)
        ## if name has been changed, validate it and assign the new value 
        if (currName != newName):
            if (newName == ''):
                errorMsg = 'Group name field cannot be left blank. So Edit Group operation stopped'
                return HttpResponseRedirect(redirectURL + errorMsg)
            groupExists = checkNameIgnoreCase(newName)
            if groupExists:
                msgAlreadyExists = 'Group ' + newName + ' already exists. Hence Edit Group Operation Stopped'
                return HttpResponseRedirect(redirectURL + msgAlreadyExists);
            groupObject.name = newName
        ## if description has been changed, then assign the new value
        if (currDescription != newDescription):
            groupObject.description = newDescription
        ## if administrative egroup has been changed, first check its existence and then assign it if exists.
        egroup = None
        if (currAdmin_group != newAdmin_group):
            if (newAdmin_group == ''):
                errorMsg = 'Admin E-Group field cannot be left blank. So Edit Group operation stopped'
                return HttpResponseRedirect(redirectURL + errorMsg)
            try:
                egroup = Egroups.objects.get(name=newAdmin_group)
            except Egroups.DoesNotExist:
                if not (checkEGroup(newAdmin_group)):
                    errorMessage = 'Selected Admin E-Group ' + newAdmin_group + ' does not exists'
                    return HttpResponseRedirect(redirectURL + errorMessage)
                egroup = Egroups(name=newAdmin_group)
                egroup.save()
            groupObject.admin_group = egroup
        ## Finally, save the changes and return a success message to the user
        groupObject.save()              
        newGroupInfo = getGroupInfo(groupObject)
        objectId = groupObject.id 
        addUpdateLog(request,newName,objectId,comment,oldGroupInfo,newGroupInfo,'group',True)
        message = 'Group ' + groupName + ' Successfully Updated'
        html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/group/list/\"></HEAD><body> %s.</body></html>" % message
        return HttpResponse(html)
    return render_to_response('group/update.html',locals(),context_instance=RequestContext(request))
Beispiel #5
0
def addnew(request):
    groups = request.META.get('ADFS_GROUP','')
    groupsList = groups.split(';') ;
    ## add operation is allowed only if user has cloudman resource manager privileges
    userIsSuperUser = isSuperUser(groupsList)
    if not userIsSuperUser:
        message = "You don't have cloudman resource manager privileges. Hence you are not authorized to add new Projects";
        html = "<html><body> %s.</body></html>" % message
        return HttpResponse(html)

    ## if the request if due to form submission, then add the project or else return to display the form for add
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        attr_name_array = request.POST.getlist('attribute_name');
        attr_value_array = request.POST.getlist('attribute_value');
        #Create dictionary of attr_name and attr_value with attr_name:attr_value as key:value pairs
        attr_list = createDictFromList(attr_name_array,attr_value_array)
        ## validate the form
        if form.is_valid():
            redirectURL = '/cloudman/message/?msg=' 
            name = form.cleaned_data['name']
            projectExists = checkNameIgnoreCase(name)
            if projectExists:
                msgAlreadyExists = 'Project ' + name + ' already exists. Hence Add Project Operation Stopped'
                return HttpResponseRedirect(redirectURL + msgAlreadyExists);
            description = form.cleaned_data['description']
            admin_group = form.cleaned_data['admin_group']
            comment = form.cleaned_data['comment']
            try:
                validate_attr(attr_list)
            except ValidationError as e:
                msg = 'Add Project Form  '+', '.join(e.messages)
                html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/project/list/\"></HEAD><body> %s.</body></html>" %msg
                return HttpResponse(html)
            ## check first whether the admin_group exists in the local egroup table
            ## if not, then in the remote egroup database through ldap. If exists here, then add to the local table
            egroup = None
            try:
                egroup = Egroups.objects.get(name=admin_group)
            except Egroups.DoesNotExist:
                if not (checkEGroup(admin_group)):
                    errorMessage = 'Admin E-Group Entered ' + admin_group + ' does not exists'
                    return HttpResponseRedirect(redirectURL + errorMessage)
                egroup = Egroups(name=admin_group)
                egroup.save()
            #Make Sure no attribute_name or attribute_value is empty
            ##Check if all the attribute name are distinct for this first convert all the attribute name to uppercase and 
            ## After converting to uppercase check for duplicate in the array
            if checkForEmptyStrInList(attr_name_array):
                errorMessage = 'Attribute Name Cannot be Empty. Hence Add Project Operation Stopped'
                return HttpResponseRedirect(redirectURL + errorMessage)
            ##Check if all the attribute name are distinct for this first convert all the attribute name to uppercase and 
            ## After converting to uppercase check for duplicate in the array
            new_attr_name_array = [x.upper() for x in attr_name_array];
            if len(new_attr_name_array) != len( set(new_attr_name_array) ):
                errorMessage = 'Duplicate values for the Attribute Name. Hence Add Project Operation Stopped#'
                return HttpResponseRedirect(redirectURL + errorMessage)
            ## add the project and return a success message to the user
            ##Also add the project_metadata
            try:
                projectObj = Project(name=name, description=description, admin_group=admin_group)			
                projectObj.save()
                proj=Project.objects.get(name=name)
                for attr_name,attr_value  in attr_list.items():
                    project_metadata = ProjectMetadata(attribute = attr_name,value = attr_value,project = proj)
                    project_metadata.save()
                    #Write the LOg               
                projectObj = Project.objects.get(name=name)
                if addLog(request,name,comment,projectObj,None,'project','add',True):
                    transaction.commit()          
                    msgSuccess = 'New Project ' +name  + ' added successfully'
                else:
                    transaction.rollback()
                    msgSuccess = 'Error in creating the Project ' + name
            except Exception:
                print traceback.format_exc()
                transaction.rollback()
                msgSuccess = 'Error in creating the Project ' + name

            html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/project/list/\"></HEAD><body> %s.</body></html>" % msgSuccess
            return HttpResponse(html)
    else:
        form = ProjectForm()
    return render_to_response('project/addnew.html',locals(),context_instance=RequestContext(request))
Beispiel #6
0
def update(request):
    projectName = request.REQUEST.get("name", "")
    redirectURL = '/cloudman/message/?msg='
    groups = request.META.get('ADFS_GROUP','')
    groupsList = groups.split(';')
    userIsSuperUser = isSuperUser(groupsList)
    ## update operation is allowed only if user has either cloudman resource manager privileges
    ## or user has membership of the administrative egroup selected for this project
    if not isUserAllowedToUpdateOrDeleteProject(projectName,groupsList):
        message = "You neither have membership of administrative group of Project " + projectName + " nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to Edit Project";
        html = "<html><body> %s.</body></html>" % message
        return HttpResponse(html)
    ## Get the Project Object
    projectObject = None
    try:
        projectObject = Project.objects.get(name=projectName)       
    except Project.DoesNotExist:
        failureMessage = "Project with Name " + projectName + " could not be found"
        return HttpResponseRedirect(redirectURL+failureMessage)
    oldProjectInfo = getProjectInfo(projectObject)
    ##Get the Project Attribute
    Metadata = ProjectMetadata.objects.filter(project__name__iexact = projectName).values('attribute','value').order_by('attribute')
    ## if the request is through form submission, then update the values or else present a form for update
    if request.method == 'POST':
        ## Existing values 
        currName = projectObject.name
        currDescription = projectObject.description
        currAdmin_group = projectObject.admin_group
        ## New values
        newName = request.POST['newname']
        newDescription = request.POST['description']
        newAdmin_group = request.POST['admin_group']
        comment = request.POST['comment']
        ## New values for Project metadata
        new_attr_name_list = request.POST.getlist('attribute_name');
        new_attr_value_list = request.POST.getlist('attribute_value');
        #Create dictionary of attr_name and attr_value with attr_name:attr_value as key:value pairs
        attr_list = createDictFromList(new_attr_name_list,new_attr_value_list) 
        
        try:
            validate_name(newName)
            validate_descr(newDescription)
            validate_name(newAdmin_group)
            validate_comment(comment)
            validate_attr(attr_list)
        except ValidationError as e:
            msg = 'Edit Project Form  '+', '.join(e.messages)
            html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/project/list/\"></HEAD><body> %s.</body></html>" %msg
            return HttpResponse(html)
        #Make Sure no attribute_name or attribute_value is empty
        if checkForEmptyStrInList(new_attr_name_list):
            errorMessage = 'Attribute Name Cannot be Empty. Hence Update Project Operation Stopped'
            return HttpResponseRedirect(redirectURL + errorMessage)
        ##Make Sure that all the attribute_name are distinct
        if checkForDuplicateStrInList(new_attr_name_list): 
            errorMessage = 'Duplicate values for the Attribute Name. Hence Update Project Operation Stopped'
            return HttpResponseRedirect(redirectURL + errorMessage)
        ## if name has been changed, validate it, then assign the new name
        if (currName != newName):
            if (newName == ''):
                errorMsg = 'Project name field cannot be left blank. So Edit Project operation stopped'
                return HttpResponseRedirect(redirectURL + errorMsg)
            projectExists = checkNameIgnoreCase(newName)
            if projectExists:
                msgAlreadyExists = 'Project ' + newName + ' already exists. Hence Edit Project Operation Stopped'
                return HttpResponseRedirect(redirectURL + msgAlreadyExists);
            projectObject.name = newName       
        ## if description has been changed, assign the new value
        if (currDescription != newDescription):
            projectObject.description = newDescription        
        ## if admin_group value changed, check first whether the new admin_group exists in the local egroup table
        ## if not, then in the remote egroup database through ldap. If exists here, then add to the local table   
        egroup = None
        if (currAdmin_group != newAdmin_group):
            if (newAdmin_group == ''):
                errorMsg = 'Admin E-Group field cannot be left blank. So Edit Project operation stopped'
                return HttpResponseRedirect(redirectURL + errorMsg)
            try:
                egroup = Egroups.objects.get(name=newAdmin_group)
            except Egroups.DoesNotExist:
                if not (checkEGroup(newAdmin_group)):
                    errorMessage = 'Selected Admin E-Group ' + newAdmin_group + ' does not exists'
                    return HttpResponseRedirect(redirectURL + errorMessage)
                egroup = Egroups(name=newAdmin_group)
                egroup.save()
            projectObject.admin_group = egroup
        ## finally save all the changes and return a success message to the user
        projectObject.save()
        old_attr_name_list =[]
        oldprMetaObj = ProjectMetadata.objects.filter(project = projectObject).values('attribute')
        for item in oldprMetaObj:
            old_attr_name_list.append(item['attribute'])
        ProjectMetadata.objects.filter(project = projectObject).delete()
        new_attr_list =[]
        for attr_name,attr_value  in attr_list.items(): 
            project_metadata = ProjectMetadata(attribute = attr_name,value = attr_value,project = projectObject)
            new_attr_list.append(attr_name)
            project_metadata.save()
        ##delete the obselete Atribute Name:value pair from projectAllocatioNMetadata
        obsolete_attr_list = set(old_attr_name_list) - set(new_attr_list) 
        #delete the Attribute from the ProjectAllocationMetadata
        ProjectAllocationMetadata.objects.filter(project = projectObject, attribute__in=list(obsolete_attr_list)).delete() 
        newProjectInfo = getProjectInfo(projectObject)
        objectId = projectObject.id 
        if addUpdateLog(request,newName,objectId,comment,oldProjectInfo,newProjectInfo,'project',True):
            message = 'Project ' + projectName + ' Successfully Updated'
            transaction.commit()
        else:
            transaction.rollback() 
            message = 'Error while updating Project ' + projectName
        html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/project/list/\"></HEAD><body> %s.</body></html>" % message
        return HttpResponse(html)    
    return render_to_response('project/update.html',locals(),context_instance=RequestContext(request))