コード例 #1
0
def delete(request):
    rtName = request.REQUEST.get("name", "")
    redirectURL = '/cloudman/message/?msg='
    comment = request.REQUEST.get("comment", "deleting")
    groups = request.META.get('ADFS_GROUP','')
    groupsList = groups.split(';') ;
    userIsSuperUser = isSuperUser(groupsList)
    ## Check - Logged in user has administrative privileges
    if not userIsSuperUser:
        message = "You don't have cloudman resource manager privileges. Hence you are not authorized to delete Resource Type " + rtName;
        html = "<html><body> %s.</body></html>" % message
        return HttpResponse(html)
    ## Get the Resource Type Object
    resourceTypeObject = None
    try:
        resourceTypeObject = ResourceType.objects.get(name=rtName)
    except ResourceType.DoesNotExist:
        failureMessage = "Resource Type with Name " + rtName + " could not be found"
        return HttpResponseRedirect(redirectURL+failureMessage)
    ## Before Deleting, check whether this resource type is used for zones, top level allocations, project allocations and group allocations
    zoneNames = ZoneAllowedResourceType.objects.filter(resource_type__name__iexact = rtName).values_list('zone__name', 'zone__region__name').order_by('zone__name')
    tpAllocNames = TopLevelAllocationAllowedResourceType.objects.filter(resource_type__name__iexact = rtName).values_list('top_level_allocation__name', flat=True).order_by('top_level_allocation__name')
    prAllocNames = ProjectAllocationAllowedResourceType.objects.filter(resource_type__name__iexact = rtName).values_list('project_allocation__name', flat=True).order_by('project_allocation__name')
    grAllocNames = GroupAllocationAllowedResourceType.objects.filter(resource_type__name__iexact = rtName).values_list('group_allocation__name', flat=True).order_by('group_allocation__name')
    ## if this resource type is used as specified above, then frame an errorMessage to alert the user
    finalMessage = ''
    zoneNamesList = list(zoneNames)
    tpAllocNamesList = list(tpAllocNames)
    prAllocNamesList = list(prAllocNames)
    grAllocNamesList = list(grAllocNames)
    if len(zoneNamesList) > 0:
        finalMessage = finalMessage + "Zone Names: "
        for i in (range(len(zoneNamesList))):
            if (i == (len(zoneNamesList)-1)):
                finalMessage = finalMessage + zoneNamesList[i][0] + "(Region: " + zoneNamesList[i][1] + ") "
            else:
                finalMessage = finalMessage + zoneNamesList[i][0] + "(Region: " + zoneNamesList[i][1] + "), "
        finalMessage = finalMessage + "<br/>"
    if len(tpAllocNamesList) > 0:
        finalMessage = finalMessage + "Top Level Allocation Names: " + (', '.join(tpAllocNamesList)) + "<br/>"
    if len(prAllocNamesList) > 0: 
        finalMessage = finalMessage + "Project Allocation Names: " + (', '.join(prAllocNamesList)) + "<br/>"
    if len(grAllocNamesList) > 0: 
        finalMessage = finalMessage + "Group Allocation Names: " + (', '.join(grAllocNamesList)) + "<br/>"
    if not finalMessage == '':
        finalMessage = "Resource Type with Name " + rtName + " Could not be deleted because it is being used in " + "<br/>" + finalMessage
        html = "<html><body> %s</body></html>" % finalMessage
        return HttpResponse(html)
    ## if this resource type is not used anywhere, then delete it and return a success message to the user
    status = addLog(request,rtName,comment,resourceTypeObject,None,'resourcetype','delete',False)   
    resourceTypeObject.delete()
    if status:
        message = "Resource Type with Name " + rtName + " deleted successfully "
        transaction.commit()
    else:
        transaction.rollback()
        message = "Error in deleting Resource Type with Name " + rtName     
    html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/resourcetype/list/\"></HEAD><body> %s.</body></html>" % message
    return HttpResponse(html)
コード例 #2
0
def addnew(request):
    groups = request.META.get('ADFS_GROUP','')
    groupsList = groups.split(';') ;
    userIsSuperUser = isSuperUser(groupsList)
    ## Check if the User has cloudman resource manager privileges
    if not userIsSuperUser:
        message = "You don't have cloudman resource manager privileges. Hence you are not authorized to add new Resource Type";
        html = "<html><body> %s.</body></html>" % message
        return HttpResponse(html)
    ## If the call is due to form submission, then get all the values and add the new resource type, else display the form
    if request.method == 'POST': 
        form = ResourceTypeForm(request.POST)
        if form.is_valid():
            redirectURL = '/cloudman/message/?msg=' 
            ## Get all the values of the form submitted through POST method 
            rtName = form.cleaned_data['name']
            resourceClass = form.cleaned_data['resource_class']
            hepspecs= form.cleaned_data['hepspecs']
            memory = form.cleaned_data['memory']
            storage = form.cleaned_data['storage']
            bandwidth = form.cleaned_data['bandwidth']
            comment = form.cleaned_data['comment']
            reqParam = False
            ## check if name exists
            nameExists = checkNameIgnoreCase(rtName)
            if nameExists:
                msgAlreadyExists = 'Resource Type ' + rtName + ' already exists. Hence Add Resource Type Operation Stopped'
                return HttpResponseRedirect(redirectURL + msgAlreadyExists)
            if hepspecs :
                hepspecs = round((float(hepspecs)), 3)
                reqParam = True
            if memory :
                memory = round((float(memory)), 3)
            if storage :
                storage = round((float(storage)), 3)
                reqParam = True
            if bandwidth :
                bandwidth = round((float(bandwidth)), 3)
            if (not reqParam):
                errorMsg = 'Either of CPU or Storage Capacity needs to be defined. Hence Add Resource Type Operation Stopped'
                return HttpResponseRedirect(redirectURL + errorMsg);
            rtObj = ResourceType(name=rtName, resource_class=resourceClass, hepspecs=hepspecs, memory=memory, storage=storage, bandwidth=bandwidth)
            rtObj.save()
            ## Return the success message and redirect to list template in 4 seconds
            rtObj = ResourceType.objects.get(name = rtName)
            if addLog(request,rtName,comment,rtObj,None,'resourcetype','add',True):
                transaction.commit()
                msgSuccess = 'New Resource Type ' + rtName  + ' added successfully'
            else:
                transaction.rollback()
                msgSuccess = 'Error in Adding Resource Type ' + rtName
            html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/resourcetype/list/\"></HEAD><body> %s.</body></html>" % msgSuccess
            return HttpResponse(html)
    else:
        form = ResourceTypeForm()
    return render_to_response('resourcetype/new.html',locals(),context_instance=RequestContext(request))
コード例 #3
0
ファイル: regionQueries.py プロジェクト: cernops/CloudMan
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))
コード例 #4
0
ファイル: regionQueries.py プロジェクト: cernops/CloudMan
def delete(request):
	regionName = request.REQUEST.get("name", "")
	comment = request.REQUEST.get("comment", "deleting")
	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 Delete 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)

	## Check whether any zones are defined for this region
	zoneNames = Zone.objects.filter(region__name__iexact = regionName).values_list('name', flat=True).order_by('name')
	finalMessage = ''
	zoneNamesList = list(zoneNames)

	## If zones are defined, then alert the user and do not delete the region
	if len(zoneNamesList) > 0:
	   finalMessage = finalMessage + "Zone Names: " + (', '.join(zoneNamesList)) + "<br/>"
	if not finalMessage == '':
	   finalMessage = "Region with Name " + regionName + " Could not be deleted because it is being used in " + "<br/>" + finalMessage
	   html = "<html><body> %s</body></html>" % finalMessage
	   return HttpResponse(html)
  
	## If no zones, then delete the region and return a success message to the user
	status = addLog(request,regionName,comment,regionObject,None,'region','delete',False)
	regionObject.delete()
	if status:
		transaction.commit()
		message = "Region with Name " + regionName + " deleted successfully "
	else:
		transaction.rollback()
		message = "Error in deleting Region with Name " + regionName
	html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/region/list/\"></HEAD><body> %s.</body></html>" % message
	return HttpResponse(html)