Esempio n. 1
0
def networkingDashboard(request):#,rangeId):
	
	extra_context = {"section": "networking","subsection":"None"}
	extra_context["macRanges"] = EthernetController.listRanges()
	extra_context["MacRange"] = MacRange
	extra_context["ip4Ranges"] = Ip4Controller.listRanges()
	extra_context["Ip4Range"] = Ip4Range
	
	template = "networking/index.html"
	return simple.direct_to_template(
		request,
		extra_context=extra_context,
		template=template,
	)
Esempio n. 2
0
def manageIp4(request,rangeId=None,action=None,ip4Id=None):
	if not action in NETWORKING_POSSIBLE_ACTIONS:
		raise Exception("Unknown action") 
	
	#Define context
	extra_context = {"section": "networking","subsection":"ip4"+str(action),}	
	
	#Add process	
	if (action == NETWORKING_ACTION_ADD):
		if request.method == "GET":
			#Show form
			extra_context["form"] = HttpUtils.getFormFromModel(Ip4Range)
			return simple.direct_to_template(
				request,
				extra_context = extra_context, 
				template="networking/ip4/rangeCrud.html",
			)
			return 
	               # return HttpResponseRedirect("/networking/ip4/")
		elif request.method == "POST":
			try:
				instance = HttpUtils.getInstanceFromForm(request,Ip4Range)
				#Create Range
				Ip4Controller.createRange(instance)
				return HttpResponseRedirect("/networking/ip4/")
			except Exception as e:
				print e
				extra_context["form"] = HttpUtils.processExceptionForm(e,request,Ip4Range)
				#Process creation query
		                #return HttpResponseRedirect("/networking/ip4/")
				return simple.direct_to_template(
					request,
					extra_context = extra_context, 
					template="networking/ip4/rangeCrud.html",
				)
			
			
	#Show
	if ((action == None) or (action==NETWORKING_ACTION_SHOW)) and (not rangeId==None):

		instance = Ip4Controller.getRange(rangeId)
		extra_context["range"] = instance 

		#return HttpResponseRedirect("/networking/ip4/")
		return simple.direct_to_template(
			request,
			extra_context = extra_context, 
			template="networking/ip4/rangeDetail.html",
		)
		
			
	#Edit
	#TODO

	#Add excluded Ip
	if (action == NETWORKING_ACTION_ADDEXCLUDED) and (request.method == "POST"):
		if not request.method == "POST":
			raise Exception("Invalid method")
		try:	
			instance = Ip4Controller.getRange(rangeId)
			extra_context["range"] = instance 
		
			#Create excluded
			Ip4Controller.addExcludedIp4(instance,request)
			return HttpResponseRedirect("/networking/ip4/"+rangeId)
		except Exception as e:
			print e
			extra_context["errors"] = HttpUtils.processException(e)
			pass
		return simple.direct_to_template(
			request,
			extra_context = extra_context, 
			template="networking/ip4/rangeDetail.html",
		)
		
	#Release excluded Ip
	if (action == NETWORKING_ACTION_REMOVEXCLUDED) and (request.method == "POST"):

		try:	
			instance = Ip4Controller.getRange(rangeId)
		
			#Create excluded
			Ip4Controller.removeExcludedIp4(instance,ip4Id)
			#FIXME: Why initial instance is not refreshed?
			instance = Ip4Controller.getRange(rangeId)
			extra_context["range"] = instance
			return HttpResponseRedirect("/networking/ip4/"+rangeId) 
		except Exception as e:
			print e
			extra_context["errors"] = HttpUtils.processException(e)
			pass	

			
		return simple.direct_to_template(
			request,
			extra_context = extra_context, 
			template="networking/ip4/rangeDetail.html",
		)
	
	#Delete
	if (action == NETWORKING_ACTION_DELETE) and (request.method == "POST"):

		try:	
			Ip4Controller.deleteRange(rangeId)
			return HttpResponseRedirect("/networking/ip4/")
		except Exception as e:
			print e
			extra_context["errors"] = HttpUtils.processException(e)
			pass
	extra_context["ranges"] = Ip4Controller.listRanges()	
	template = "networking/ip4/index.html"
	return simple.direct_to_template(
			request,
			extra_context = extra_context, 
			template=template,
		)