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 manageEthernet(request,rangeId=None,action=None,macId=None):

	if not action in NETWORKING_POSSIBLE_ACTIONS:
		raise Exception("Unknown action") 

	#Define context	
	extra_context = {"section": "networking","subsection":"ethernet",}	

	
	#Add process	
	if (action == NETWORKING_ACTION_ADD):
		if request.method == "GET":
			#Show form
			extra_context["form"] = HttpUtils.getFormFromModel(MacRange)
			return simple.direct_to_template(
				request,
				extra_context = extra_context, 
				template="networking/ethernet/rangeCrud.html",
			)
			return 
		
		elif request.method == "POST":
			try:
				instance = HttpUtils.getInstanceFromForm(request,MacRange)
				#Create Range
				EthernetController.createRange(instance)
				return HttpResponseRedirect("/networking/ethernet/")
			except Exception as e:
				print e
				extra_context["form"] = HttpUtils.processExceptionForm(e,request,MacRange)
				#Process creation query
				return simple.direct_to_template(
					request,
					extra_context = extra_context, 
					template="networking/ethernet/rangeCrud.html",
				)
			
			
	#Show
	if ((action == None) or (action==NETWORKING_ACTION_SHOW)) and (not rangeId==None):

		instance = EthernetController.getRange(rangeId)
		extra_context["range"] = instance 
		#return HttpResponseRedirect("/networking/ethernet/")

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

	#Add excluded Mac 
	if (action == NETWORKING_ACTION_ADDEXCLUDED) and (request.method == "POST"):
		if not request.method == "POST":
			raise Exception("Invalid method")
		try:	
			instance = EthernetController.getRange(rangeId)
			extra_context["range"] = instance 
		
			#Create excluded
			EthernetController.addExcludedMac(instance,request)

			return HttpResponseRedirect("/networking/ethernet/"+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/ethernet/rangeDetail.html",
		)
		
	#Release excluded Mac
	if (action == NETWORKING_ACTION_REMOVEXCLUDED) and (request.method == "POST"):

		try:	
			instance = EthernetController.getRange(rangeId)
		
			#Create excluded
			#FIXME: Why initial instance is not refreshed?
			EthernetController.removeExcludedMac(instance,macId)
			instance = EthernetController.getRange(rangeId)
			extra_context["range"] = instance 
			return HttpResponseRedirect("/networking/ethernet/"+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/ethernet/rangeDetail.html",
		)
	
	#Delete
	if (action == NETWORKING_ACTION_DELETE) and (request.method == "POST"):

		try:	
			EthernetController.deleteRange(rangeId)
			return HttpResponseRedirect("/networking/ethernet/")

		except Exception as e:
			print e
			extra_context["errors"] = HttpUtils.processException(e)
			pass	
	

	#Listing ranges
	extra_context["ranges"] = EthernetController.listRanges()
	return simple.direct_to_template(
			request,
			extra_context = extra_context, 
			template = "networking/ethernet/index.html",
		)