def isUserAllowedToUpdateOrDeleteRegion(regionName,groupsList): userIsSuperUser = isSuperUser(groupsList) if userIsSuperUser: return True else: userIsAdmin = isAdminForRegion(regionName, groupsList) return userIsAdmin
def delete(request): egroup = request.REQUEST.get("name", "") comment = request.REQUEST.get("comment", "Egroup deleted in CLOUDMAN") #redirectURL = '/cloudman/message/?msg=' groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ## delete egroup from cloudman only if he has cloudman resource manager privileges userIsSuperUser = isSuperUser(groupsList) if not userIsSuperUser: message = "You does't possess Cloudman Resource Manager Privileges. Hence you are not authorized to delete egroup "%egroup html = "<html><body> %s.</body></html>" % message return HttpResponse(html) # check if any zone/project/group has this egroup grpList = Groups.objects.filter(admin_group=egroup).values_list('name',flat=True) prjList = Project.objects.filter(admin_group=egroup).values_list('name',flat=True) regionList = Region.objects.filter(admin_group=egroup).values_list('name',flat=True) if grpList or prjList or regionList: finalMessage = "Egroup with Name " + egroup + " Could not be deleted because it is being used in Some Group/Project/Region" + "<br/>" html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/log/issuelist/\"></HEAD><body> %s.</body></html>" % finalMessage else: try: Egroups.objects.get(name=egroup).delete() addEgroupLog(request,egroup,'egroup','deleteCLOUDMAN',comment,False) ## return a success message to the user message = "Egroup with Name " + egroup + " deleted successfully in CLOUDMAN" html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/log/issuelist/\"></HEAD><body> %s.</body></html>" % message except Exception: printStackTrace() message = "Erssssror while deleting Egroup " + egroup html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/log/issuelist/\"></HEAD><body> %s.</body></html>" % message return HttpResponse(html)
def isUserAllowedToUpdateOrDeleteProject(projectName,groupsList): userIsSuperUser = isSuperUser(groupsList) if userIsSuperUser: return True else: userIsAdmin = isAdminOfProject(groupsList,projectName) return userIsAdmin
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)
def delete(request): zoneName = request.REQUEST.get("zonename", "") regionName = request.REQUEST.get("regionname", "") comment = request.REQUEST.get("comment", "deleting") redirectURL = '/cloudman/message/?msg=' groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ## update operation is allowed for a user if he/she has any one of the following rights ## cloudman resource manager privileges ## or has membership of the admin_group of the region to which this zone belongs to userIsSuperUser = isSuperUser(groupsList) if not userIsSuperUser: userIsAdmin = isAdminForRegion(regionName, groupsList) if not userIsAdmin: message = "You neither have membership of administrative group of region " + regionName + " nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to delete Zone"; html = "<html><body> %s.</body></html>" % message return HttpResponse(html) ## Get the Zone Object zoneObject = None try: zoneObject = Zone.objects.get(name=zoneName, region__name=regionName) except Zone.DoesNotExist: failureMessage = "Zone with Name " + zoneName + " in Region " + regionName + " could not be found" return HttpResponseRedirect(redirectURL+failureMessage) ## check if any top level allocations have been made using this zone tpAllocNames = TopLevelAllocationByZone.objects.filter(zone__name__iexact = zoneName, zone__region__name__iexact=regionName).values_list('top_level_allocation__name', flat=True).order_by('top_level_allocation__name') ## if yes, alert the user and stop delete operation finalMessage = '' tpAllocNamesList = list(tpAllocNames) if len(tpAllocNamesList) > 0: finalMessage = finalMessage + "Top Level Allocation Names: " + (', '.join(tpAllocNamesList)) + "<br/>" if not finalMessage == '': finalMessage = "Zone with Name " + zoneName + " in Region " + regionName + " Could not be deleted because it is being used in " + "<br/>" + finalMessage html = "<html><body> %s</body></html>" % finalMessage return HttpResponse(html) ## finally delete the zone status = addLog(request,zoneName,comment,zoneObject,None,'zone','delete',False) ## If no allocations are present, then first delete the allowed resource types for this zone ZoneAllowedResourceType.objects.filter(zone__name__iexact = zoneName, zone__region__name__iexact=regionName).delete() zoneObject.delete() if status: transaction.commit() message = "Zone with Name " + zoneName + " in Region " + regionName + " deleted successfully " else: transaction.rollback() message = "Error in deleting Zone with Name " + zoneName + " in Region " + regionName ## return a success message to the user html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/zone/list/\"></HEAD><body> %s.</body></html>" % message return HttpResponse(html)
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))
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))
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))
def listall(request): groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ; userIsSuperUser = isSuperUser(groupsList) projectsList = Project.objects.all().order_by('name') deleteDict = {} showMultiDeleteOption = False numManaged=0 for prjObj in projectsList: deleteItem = isUserAllowedToUpdateOrDeleteProject(prjObj.name,groupsList) if deleteItem : showMultiDeleteOption = True numManaged +=1 deleteDict[prjObj.name] = deleteItem return render_to_response('project/listall.html',locals(),context_instance=RequestContext(request))
def listall(request): groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ; userIsSuperUser = isSuperUser(groupsList) zoneInfo = Zone.objects.values('region_id').annotate(hepspec=Sum('hepspecs'),memory=Sum('memory'),storage=Sum('storage'),bandwidth=Sum('bandwidth')) region_capacity = {} for item in zoneInfo: region_capacity[item['region_id']] = {'hepspec':item['hepspec'],'memory':item['memory'],'storage':item['storage'],'bandwidth':item['bandwidth']} regionInfoList = [] regionsList = Region.objects.all().order_by('name').select_related('admin_group__name') for region in regionsList: if region.id in region_capacity: regionInfoList.append({'name':region.name,'egroup':region.admin_group.name,'description':region.description,'capacity':region_capacity[region.id]}) else: regionInfoList.append({'name':region.name,'egroup':region.admin_group.name,'description':region.description,'capacity':{'hepspec':None,'memory':None,'storage':None,'bandwidth':None}}) return render_to_response('region/listall.html',locals(),context_instance=RequestContext(request))
def homepanel(request): anyRolePresent = False groupUserRolePresent = False groupManagerRolePresent = False projectManagerRolePresent = False regionManagerRolePresent = False fullName = request.META.get('ADFS_FULLNAME','') groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ; rolesList = getUserRoles(groupsList) for entry in rolesList: if entry[0] == 'group' and entry[1] == 'user': groupUserRoles = entry[2] if len(groupUserRoles) > 0: groupUserRolePresent = True if entry[0] == 'group' and entry[1] == 'manager': groupManagerRoles = entry[2] if len(groupManagerRoles) > 0: groupManagerRolePresent = True if entry[0] == 'project' and entry[1] == 'manager': projectManagerRoles = entry[2] if len(projectManagerRoles) > 0: projectManagerRolePresent = True if entry[0] == 'region' and entry[1] == 'manager': regionManagerRoles = entry[2] if len(regionManagerRoles) > 0: regionManagerRolePresent = True if groupUserRolePresent or groupManagerRolePresent or projectManagerRolePresent or regionManagerRolePresent: anyRolePresent = True egroupsList = getAllEGroups() userIsSuperUser = isSuperUser(groupsList) usersGroupsSet = set(groupsList) SUSet = set(SUPER_USER_GROUPS) intersectionValue = usersGroupsSet.isdisjoint(SUSet) intersectionSet = usersGroupsSet.intersection(SUSet) regionsCount = getRegionCount() zonesCount = getZoneCount() groupsCount = getGroupsCount() return render_to_response('homepanel.html',locals(),context_instance=RequestContext(request))
def listall(request): groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ; userIsSuperUser = isSuperUser(groupsList) zonesList = Zone.objects.all().order_by('name') ## form an object for each region with its zones, top level allocation hepspec value and the total zone hepspecs regionsInfo = {} for oneZone in zonesList: hepspec = oneZone.hepspecs memory = oneZone.memory storage = oneZone.storage bandwidth = oneZone.bandwidth hepspec_overcommit = oneZone.hepspec_overcommit memory_overcommit = oneZone.memory_overcommit zoneName = oneZone.name regionName = oneZone.region.name if hepspec != None: hepspec = hepspec * hepspec_overcommit else: hepspec = 0 if memory != None: memory = memory * memory_overcommit else: memory = 0 if storage == None: storage = 0 if bandwidth == None: bandwidth = 0 if not (regionName in regionsInfo): regionsInfo[regionName] = {'name': regionName, 'zones': [], 'hepspec': [], 'memory': [], 'storage': [], 'bandwidth': [], 'totalhepspec': 0, 'totalmemory': 0, 'totalstorage': 0, 'totalbandwidth': 0} regionsInfo[regionName]['zones'].append(zoneName) regionsInfo[regionName]['hepspec'].append(hepspec) regionsInfo[regionName]['memory'].append(memory) regionsInfo[regionName]['storage'].append(storage) regionsInfo[regionName]['bandwidth'].append(bandwidth) regionsInfo[regionName]['totalhepspec'] = regionsInfo[regionName]['totalhepspec'] + hepspec regionsInfo[regionName]['totalmemory'] = regionsInfo[regionName]['totalmemory'] + memory regionsInfo[regionName]['totalstorage'] = regionsInfo[regionName]['totalstorage'] + storage regionsInfo[regionName]['totalbandwidth'] = regionsInfo[regionName]['totalbandwidth'] + bandwidth return render_to_response('zone/listall.html',locals(),context_instance=RequestContext(request))
def listall(request): groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ; userIsSuperUser = isSuperUser(groupsList) resourceTypesList = ResourceType.objects.all().order_by('name') return render_to_response('resourcetype/listall.html',locals(),context_instance=RequestContext(request))
def addnew(request): ## The add zone function can be used in two ways. ## one way, is to click add new zone from the zone list page..... ## which will display all the regions and create a zone by selecting a region from the list ## second way, is to click add new zone from the region detailed page... ## which means you already selected the region and adding a zone in that region ## that's why the following variable says whether you already selected region or not selRegionName = request.REQUEST.get("regionname", "") ## Check if there are any regions defined. If not, then zones cannot be added regionsCount = getRegionCount() if (regionsCount == 0): message = "No Regions Defined. First create Region and then try to add Zone" html = "<html><body> %s.</body></html>" % message return HttpResponse(html) ## Check if there are any resource types defined. If not, then zones cannot be added resourceTypesCount = getResourceTypesCount() if (resourceTypesCount == 0): message = "No Resource Types Defined. First create Resource Types and then try to add Zone" html = "<html><body> %s. </body></html>" % message return HttpResponse(html) groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') userIsSuperUser = isSuperUser(groupsList) ## If the request is through form submission, then try to add the region or else display the add form if request.method == 'POST': redirectURL = '/cloudman/message/?msg=' regionName = request.POST['region'] zoneName = request.POST['name'] description = request.POST['description'] hepSpecs = request.POST['hepspecs'] memory = request.POST['memory'] storage = request.POST['storage'] bandwidth = request.POST['bandwidth'] hepSpec_overcommit = request.POST['hepspec_overcommit'] memory_overcommit = request.POST['memory_overcommit'] comment = request.POST['comment'] try: validate_name(regionName) validate_name(zoneName) validate_descr(description) validate_float(hepSpecs) validate_int(memory) validate_int(storage) validate_float(bandwidth) validate_comment(comment) validate_float(hepSpec_overcommit) validate_float(memory_overcommit) except ValidationError as e: message ='Add Zone Form '+', '.join(e.messages) html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/zone/list/\"></HEAD><body> %s.</body></html>" % message return HttpResponse(html) ## check for uniqueness of this zone name in the region nameExists = checkNameIgnoreCase(regionName, zoneName) if nameExists: msgAlreadyExists = 'Zone Name ' + zoneName + ' in Region ' + regionName + ' already exists. Hence Add New Zone Operation Stopped' transaction.rollback() return HttpResponseRedirect(redirectURL + msgAlreadyExists) ## check whether user has any of the following rights ## cloudman resource manager privileges ## If not, then has membership of region admin_group if not userIsSuperUser: userIsAdminOfRegion = isAdminForRegion(regionName, groupsList) if not userIsAdminOfRegion: message = "You neither have membership of administrative group of region " + regionName + " nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to add new Zone"; return HttpResponseRedirect(redirectURL + message) ## Get the Region Object try: region = Region.objects.get(name=regionName) except Region.DoesNotExist: errorMessage = 'No Record Found for Region ' + regionName + '. Hence Add New Zone Operation Stopped' return HttpResponseRedirect(redirectURL + errorMessage) ## validate hepspec, memory, storage and bandwidth values errorMsg = checkAttributeValues(hepSpecs, memory, storage, bandwidth) if (errorMsg != ''): return HttpResponseRedirect(redirectURL + errorMsg) ## validate hepspec over commit and memory over commit values if hepSpec_overcommit < 1: msgFailure = "Hepspec Over Commit value should be greater than or equal to 1. Hence Add Zone Operation Stopped" return HttpResponseRedirect(redirectURL + msgFailure) if memory_overcommit < 1: msgFailure = "Memory Over Commit value should be greater than or equal to 1. Hence Add Zone Operation Stopped" return HttpResponseRedirect(redirectURL + msgFailure) ## get all the resource types check boxes values (resource type name), ## the allowed resource types for this zone will be the ones whose checkbox is selected totalResourceTypes = request.POST['totalresourcetypes'] index = 1 atleastOneRTsel = False resourceTypesList = [] while index <= int(totalResourceTypes): if ('resourcetype'+str(index)) in request.POST.keys() : ## if checkbox selected resourceTypesList.append(request.POST['resourcetype'+str(index)]) atleastOneRTsel = True index = index + 1 if not atleastOneRTsel: message = "No Resource Types selected that are allowed for this Zone. Hence Zone Add Operation Stopped" return HttpResponseRedirect(redirectURL + message) ## get the resource type objects for all those that are selected resourceTypesFullInfoList = [] msgSuccess = '' for oneRT in resourceTypesList: try: resourceType = ResourceType.objects.get(name=oneRT) resourceTypesFullInfoList.append(resourceType) msgSuccess = msgSuccess + ' ' + oneRT; except ResourceType.DoesNotExist: errorMessage = 'No Record Found for Resource Type ' + oneRT + '. Hence Add New Zone Operation Stopped' return HttpResponseRedirect(redirectURL + errorMessage) msgSuccess = 'New Zone ' + zoneName + ' added successfully ' + ' to Region ' + regionName + '. The allowed Resource Types are ' + msgSuccess if hepSpecs == '': hepSpecs = None else: hepSpecs = round((float(hepSpecs)), 3) if memory == '': memory = None else: memory = round((float(memory)), 3) if storage == '': storage = None else: storage = round((float(storage)), 3) if bandwidth == '': bandwidth = None else: bandwidth = round((float(bandwidth)), 3) ## create the zone object and save it newzone = Zone(name=zoneName, description=description, region=region, hepspecs=hepSpecs, memory=memory, storage=storage, bandwidth=bandwidth, hepspec_overcommit=hepSpec_overcommit, memory_overcommit=memory_overcommit) newzone.save() ## get the newly added zone object ## add the allowed resource types for this zone addedZone = Zone.objects.get(name=zoneName, region=region) for oneRT in resourceTypesFullInfoList: zrt = ZoneAllowedResourceType(zone=addedZone, resource_type=oneRT) zrt.save() ##Add the Log for Zone if addLog(request,zoneName,comment,addedZone,None,'zone','add',True): transaction.commit() else: transaction.rollback() msgSuccess = 'Error in creating new zone' + zoneName ## return the success message to the user html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/zone/list/\"></HEAD><body> %s.</body></html>" % msgSuccess return HttpResponse(html) else: ## Zone can be added provided you have any of the following privileges ## cloudman resource manager privileges ## only to regions for which user has membership of its admin_group if not userIsSuperUser: userIsAdmin = True ## if region is not already selected, then check user has membership of atleast one region admin_group if selRegionName == '': userIsAdmin = isAdminOfAnyRegion(groupsList) if not userIsAdmin: message = "You neither have membership of administrative groups of any region nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to add new Zone"; html = "<html><body> %s.</body></html>" % message return HttpResponse(html) else: userIsAdmin = isAdminForRegion(selRegionName, groupsList) if not userIsAdmin: message = "You neither have membership of administrative group of region " + selRegionName + " nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to add new Zone"; html = "<html><body> %s.</body></html>" % message return HttpResponse(html) form = ZoneForm(userGroups=groupsList, superUserRights=userIsSuperUser) resourceForm=ResourceForm resourceType = ResourceType.objects.all() return render_to_response('zone/addnew.html',locals(),context_instance=RequestContext(request))
def update(request): rtName = request.REQUEST.get("name", "") redirectURL = '/cloudman/message/?msg=' 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 update 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) oldRTInfo = getResourceTypeInfo(resourceTypeObject) ## if this is a form submission, then do the update or else display the form for update if request.method == 'POST': ## Existing values currName = resourceTypeObject.name currResourceClass = resourceTypeObject.resource_class currHepSpecs = resourceTypeObject.hepspecs currMemory = resourceTypeObject.memory currStorage = resourceTypeObject.storage currBandwidth = resourceTypeObject.bandwidth ## Get the new values newName = request.POST['name'] newResourceClass = request.POST['resource_class'] newHepSpecs = request.POST['hepspecs'] newMemory = request.POST['memory'] newStorage = request.POST['storage'] newBandwidth = request.POST['bandwidth'] comment = request.POST['comment'] try: validate_name(newName) validate_name(newResourceClass) validate_float(newHepSpecs) validate_float(newMemory) validate_float(newStorage) validate_float(newBandwidth) validate_comment(comment) except ValidationError as e: message ='Edit Resource Type Form '+', '.join(e.messages) html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/resourcetype/list/\"></HEAD><body> %s.</body></html>" % message return HttpResponse(html) ## If resource parameters are changed, then validate them errorMsg = checkAttributeValues(newHepSpecs, newMemory, newStorage, newBandwidth) if (errorMsg != ''): return HttpResponseRedirect(redirectURL + errorMsg) ## convert empty values for the following fields into None i.e NULL and if not empty, then round off to 3 decimals if (newHepSpecs == ''): newHepSpecs = None else: newHepSpecs = round((float(newHepSpecs)), 3) if (newMemory == ''): newMemory = None else: newMemory = round((float(newMemory)), 3) if (newStorage == ''): newStorage = None else: newStorage = round((float(newStorage)), 3) if (newBandwidth == ''): newBandwidth = None else: newBandwidth = round((float(newBandwidth)), 3) ## Check atleast one parameter is changed from its existing value if ( (currName == newName) and (currResourceClass == newResourceClass) and (currHepSpecs== newHepSpecs) and (currMemory == newMemory) and (currStorage == newStorage) and (currBandwidth == newBandwidth) ): message = 'No New Value provided for any field to perform Edit Operation. Hence Edit Resource Type ' + rtName + ' aborted' return HttpResponseRedirect(redirectURL + message) ## If name is changed, then validate it and if success, then assign the new name to the object if (currName != newName): if (newName == ''): errorMsg = 'Name field cannot be left blank. So Edit Resource Type operation stopped' return HttpResponseRedirect(redirectURL + errorMsg) nameExists = checkNameIgnoreCase(newName) if nameExists: msgAlreadyExists = 'Resource Type ' + newName + ' already exists. Hence Edit Resource Type Operation Stopped' return HttpResponseRedirect(redirectURL + msgAlreadyExists); resourceTypeObject.name = newName ## check the remaining parameters and if changed, then assign to the object if (currResourceClass != newResourceClass): resourceTypeObject.resource_class = newResourceClass if (currHepSpecs != newHepSpecs): resourceTypeObject.hepspecs = newHepSpecs if (currMemory != newMemory): resourceTypeObject.memory = newMemory if (currStorage != newStorage): resourceTypeObject.storage = newStorage if (currBandwidth != newBandwidth): resourceTypeObject.bandwidth = newBandwidth ## update the object and return the success message to the user resourceTypeObject.save() newRTInfo = getResourceTypeInfo(resourceTypeObject) objectId = resourceTypeObject.id if addUpdateLog(request,newName,objectId,comment,oldRTInfo,newRTInfo,'resourcetype',True): message = 'Resource Type ' + rtName + ' Successfully Updated' transaction.commit() else: transaction.rollback() message = 'Error in Updating Resource Type ' + rtName html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/resourcetype/list/\"></HEAD><body> %s.</body></html>" % message return HttpResponse(html) ## if it is not form submission, then call the template to display the update form else: form = ResourceTypeForm() #resourceTypeList=list(resourceTypeObject) #json_object=simplejson.dumps(resourceTypeObject) return render_to_response('resourcetype/update.html',locals(),context_instance=RequestContext(request))
def update(request): regionName = request.REQUEST.get("regionname", "") zoneName = request.REQUEST.get("zonename", "") redirectURL = '/cloudman/message/?msg=' groups = request.META.get('ADFS_GROUP','') groupsList = groups.split(';') ## update operation is allowed for a user if he/she has any one of the following rights ## cloudman resource manager privileges ## or has membership of the admin_group of the region to which this zone belongs to userIsSuperUser = isSuperUser(groupsList) if not userIsSuperUser: userIsAdmin = isAdminForRegion(regionName, groupsList) if not userIsAdmin: message = "You neither have membership of administrative group of region " + regionName + " nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to Edit Zone"; html = "<html><body> %s.</body></html>" % message return HttpResponse(html) ## Get the Zone Object zoneObject = None try: zoneObject = Zone.objects.get(name=zoneName, region__name=regionName) except Zone.DoesNotExist: failureMessage = "Zone with Name " + zoneName + " in Region " + regionName + " could not be found" return HttpResponseRedirect(redirectURL+failureMessage) oldZoneInfo = getZoneInfo(zoneObject) ## if the request is from a update form submission, then try to update the values or else return to ## display the form if request.method == 'POST': ## Existing values currRegionName = zoneObject.region.name currName = zoneObject.name currDescription = zoneObject.description currHepSpec = zoneObject.hepspecs currMemory = zoneObject.memory currStorage = zoneObject.storage currBandwidth = zoneObject.bandwidth currHepspec_overcommit = zoneObject.hepspec_overcommit currMemory_overcommit = zoneObject.memory_overcommit currRTList = ZoneAllowedResourceType.objects.filter(zone__name=zoneName, zone__region__name=regionName).values_list('resource_type__name', flat=True) ## new values newRegionName = request.POST['region'] newName = request.POST['name'] newDescription = request.POST['description'] newHepSpec = request.POST['hepspecs'] newMemory = request.POST['memory'] newStorage = request.POST['storage'] newBandwidth = request.POST['bandwidth'] newHepspec_overcommit = request.POST['hepspec_overcommit'] newMemory_overcommit = request.POST['memory_overcommit'] newRTList = request.POST.getlist('zoneallowedrt') comment = request.POST['comment'] try: validate_name(newRegionName) validate_name(newName) validate_descr(newDescription) validate_float(newHepSpec) validate_float(newMemory) validate_float(newStorage) validate_float(newBandwidth) validate_comment(comment) except ValidationError as e: message ='Edit Zone Form '+', '.join(e.messages) html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/zone/list/\"></HEAD><body> %s.</body></html>" % message return HttpResponse(html) ## validate the new resource parameter values errorMsg = checkAttributeValues(newHepSpec, newMemory, newStorage, newBandwidth) if (errorMsg != ''): return HttpResponseRedirect(redirectURL + errorMsg) newHepspec_overcommit = float(newHepspec_overcommit) newMemory_overcommit = float(newMemory_overcommit) if newHepspec_overcommit < 1: msgFailure = "Hepspec Over Commit value should be greater than or equal to 1. Hence Edit Zone Operation Stopped" return HttpResponseRedirect(redirectURL + msgFailure) if newMemory_overcommit < 1: msgFailure = "Memory Over Commit value should be greater than or equal to 1. Hence Edit Zone Operation Stopped" return HttpResponseRedirect(redirectURL + msgFailure) ## check whether any new resource type has been selected or existing resource type is de-selected rtNotChanged = True; for newRt in newRTList: if not newRt in currRTList: rtNotChanged = False for oldRt in currRTList: if not oldRt in newRTList: rtNotChanged = False if (newHepSpec == ''): newHepSpec = None else: newHepSpec = round((float(newHepSpec)), 3) if (newMemory == ''): newMemory = None else: newMemory = round((float(newMemory)), 3) if (newStorage == ''): newStorage = None else: newStorage = round((float(newStorage)), 3) if (newBandwidth == ''): newBandwidth = None else: newBandwidth = round((float(newBandwidth)), 3) ## check if atleast one field value has been changed if ( (currRegionName == newRegionName) and (currName == newName) and (currDescription == newDescription) and (currHepSpec == newHepSpec) and (currMemory == newMemory) and (currStorage == newStorage) and (currBandwidth == newBandwidth) and (currHepspec_overcommit == newHepspec_overcommit) and (currMemory_overcommit == newMemory_overcommit) and (rtNotChanged) ): message = 'No New Value provided for any field to perform Edit Operation. Hence Edit Zone ' + zoneName + ' in Region ' + regionName + ' aborted' return HttpResponseRedirect(redirectURL + message) ## if region is changed, then validate it, check if user has either cloudman resource manager privileges ## or new region admin_group membership ## if all is fine, then assign the new region name and get the new Region Object if (currRegionName != newRegionName): if newRegionName == '': errorMsg = 'Region name field cannot be left blank. So Edit Zone operation stopped' return HttpResponseRedirect(redirectURL + errorMsg) # do for region if not userIsSuperUser: userIsAdmin = isAdminForRegion(newRegionName, groupsList) if not userIsAdmin: message = "You neither have membership of administrative group of region " + newRegionName + " nor possess Cloudman Resource Manager Privileges. Hence you are not authorized to shift Zone from Region " + currRegionName + " to Region " + newRegionName; html = "<html><body> %s.</body></html>" % message return HttpResponse(html) regionName = newRegionName regionObject = None try: regionObject = Region.objects.get(name=newRegionName) except Region.DoesNotExist: errorMessage = 'No record found for Region with name ' + newRegionName + '. Hence Edit Zone operation stopped' return HttpResponseRedirect(redirectURL + errorMessage) zoneObject.region = regionObject ## if zone name is changed, then validate it and assign the new name if (currName != newName): if (newName == ''): errorMsg = 'Name name field cannot be left blank. So Edit Zone operation stopped' return HttpResponseRedirect(redirectURL + errorMsg) if (currRegionName != newRegionName): nameExists = checkNameIgnoreCase(newRegionName, newName) if nameExists: msgAlreadyExists = 'Zone ' + newName + ' in Region ' + newRegionName + ' already exists. Hence Edit Zone Operation Stopped' return HttpResponseRedirect(redirectURL + msgAlreadyExists); else: nameExists = checkNameIgnoreCase(currRegionName, newName) if nameExists: msgAlreadyExists = 'Zone ' + newName + ' in Region ' + currRegionName + ' already exists. Hence Edit Zone Operation Stopped' return HttpResponseRedirect(redirectURL + msgAlreadyExists); zoneObject.name = newName ## check if description is changed and if so, assign the new value if (currDescription != newDescription): zoneObject.description = newDescription if ( (currHepSpec != newHepSpec) or (currMemory != newMemory) or (currStorage != newStorage) or (currBandwidth != newBandwidth) ): newResourceValues = {'hepspecs': newHepSpec, 'memory': newMemory, 'storage': newStorage, 'bandwidth': newBandwidth, 'hepspec_overcommit': newHepspec_overcommit, 'memory_overcommit': newMemory_overcommit} ## check whether top level allocations of this zone can be met with the new resource values errorMessage = checkTpLevelAllocations(currName, currRegionName, newResourceValues) if errorMessage != '': return HttpResponseRedirect(redirectURL + errorMessage) ## Assign the new resource values if changed if (currHepSpec != newHepSpec): zoneObject.hepspecs = newHepSpec if (currMemory != newMemory): zoneObject.memory = newMemory if (currStorage != newStorage): zoneObject.storage = newStorage if (currBandwidth != newBandwidth): zoneObject.bandwidth = newBandwidth if (currHepspec_overcommit != newHepspec_overcommit): zoneObject.hepspec_overcommit = newHepspec_overcommit if (currMemory_overcommit != newMemory_overcommit): zoneObject.memory_overcommit = newMemory_overcommit ## delete the resouce types which are de-selected if not rtNotChanged: for oldRt in currRTList: if not oldRt in newRTList: try: #rtObject = ResourceType.objects.get(name=oldRt) zrt = ZoneAllowedResourceType.objects.get(resource_type__name=oldRt, zone__name=currName, zone__region__name=currRegionName) zrt.delete() except ZoneAllowedResourceType.DoesNotExist: errorMessage = 'No Record Found for Resource Type ' + oldRt + '. Hence Edit Zone Operation Stopped' return HttpResponseRedirect(redirectURL + errorMessage) ## Finally save all the zone object changes zoneObject.save() # newZoneObj = copy.copy(zoneObject) ## if a new resource type is selected, then add it to the zone allowed resource type table if not rtNotChanged: for newRt in newRTList: if not newRt in currRTList: try: rtObject = ResourceType.objects.get(name=newRt) zrt = ZoneAllowedResourceType(zone=zoneObject, resource_type=rtObject) zrt.save() except Exception, err: errorMessage = "Error in Creating Zone Allowed Resource Type , reason : %s" % str(err) return HttpResponseRedirect(redirectURL + errorMessage) #Write The Log newZoneInfo = getZoneInfo(zoneObject) objectId = zoneObject.id if addUpdateLog(request,newName,objectId,comment,oldZoneInfo,newZoneInfo,'zone',True): transaction.commit() message = 'Zone ' + zoneName + ' in Region ' + currRegionName + ' Successfully Updated' else: transaction.rollback() message = 'Error in updating Zone ' + zoneName + ' in Region ' + currRegionName ## Finally display a success message to the user html = "<html><HEAD><meta HTTP-EQUIV=\"REFRESH\" content=\"4; url=/cloudman/zone/list/\"></HEAD><body> %s.</body></html>" % message return HttpResponse(html)
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))
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))