Exemple #1
0
def rule_table_view(request, TableName=None):

    if (not request.user.is_superuser):

        return simple.direct_to_template(
            request,
            template='not_admin.html',
            extra_context={'user': request.user},
        )
    else:  #Admin
        try:
            ruleTable = RuleTableManager.getInstance(
                RuleTableManager.getDefaultName())
            # If everything runs smoothly, return normal template
            return simple.direct_to_template(
                request,
                template='policyEngine/table_view.html',
                extra_context={
                    'user': request.user,
                    'table': ruleTable
                })
        # Handle each exception and pass the error to template
        except ZeroPolicyObjectsReturned:
            return HttpResponseRedirect("/policies/")
        except MultiplePolicyObjectsReturned:
            return HttpResponseRedirect(
                reverse('policy_edit',
                        args=(RuleTableManager.getDefaultName(), )))
Exemple #2
0
def policy_edit(request,table):

	if "HTTP_REFERER" in request.META:
		# Checks if the referer page is the home or this page itself
		if "/dashboard" in request.META['HTTP_REFERER'] or "/policies" in request.META['HTTP_REFERER']:
			ruleTableSet = RuleTableManager.getAllInstances(RuleTableManager.getDefaultName())
			return simple.direct_to_template(request,
                                          template = 'policyEngine/policy_edit.html',
                                          extra_context = {'user': request.user,
                                                           'CurrentTable': ruleTableSet}
                                        )
	# If the access flow is incorrect, send home
	return HttpResponseRedirect("/")
Exemple #3
0
def rule_table_view(request, TableName = None):
	
	if (not request.user.is_superuser):

               return simple.direct_to_template(request,
                                                 template = 'not_admin.html',
                                                 extra_context = {'user':request.user},
                                                )
        else: #Admin
        	try:
        		ruleTable = RuleTableManager.getInstance(RuleTableManager.getDefaultName())
                        # If everything runs smoothly, return normal template
        		return simple.direct_to_template(
        			request,
        			template = 'policyEngine/table_view.html',
        			extra_context = {'user': request.user,
        				'table': ruleTable}
        			)
        	# Handle each exception and pass the error to template
        	except ZeroPolicyObjectsReturned:
			return HttpResponseRedirect("/policies/")
        	except MultiplePolicyObjectsReturned:
			return HttpResponseRedirect(reverse('policy_edit', args=(RuleTableManager.getDefaultName(),)))
    def processProvisioning(provisioning):
		logging.debug("PROVISIONING STARTED...\n")
		for action in provisioning.action:
			actionModel = ActionController.ActionToModel(action,"provisioning")
			logging.debug("ACTION type: %s with id: %s" % (actionModel.type, actionModel.uuid))
			try:
				RuleTableManager.Evaluate(action,RuleTableManager.getDefaultName())
			except Exception as e:
				MAX_CHARS_ALLOWED = 200
				XmlRpcClient.callRPCMethod(threading.currentThread().callBackURL,"sendAsync",XmlHelper.craftXmlClass(XmlHelper.getProcessingResponse(Action.FAILED_STATUS, action,str(e)[0:MAX_CHARS_ALLOWED-1])))
				return None
			try:
				controller = VTDriver.getDriver(action.server.virtualization_type)
				#XXX:Change this when xml schema is updated
				server = VTDriver.getServerByUUID(action.server.uuid)
				#if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE:
				#	server = VTDriver.getServerByUUID(action.virtual_machine.server_id)
				#else:
				#	server = VTDriver.getVMbyUUID(action.virtual_machine.uuid).Server.get()
			except Exception as e:
				logging.error(e)
				raise e
			try:	
				#PROVISIONING CREATE
				if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE:
					try:
						vm = ProvisioningDispatcher.__createVM(controller, actionModel, action)
					except:
						vm = None
						raise
				#PROVISIONING DELETE, START, STOP, REBOOT
				else :
					ProvisioningDispatcher.__deleteStartStopRebootVM(controller, actionModel, action)
				XmlRpcClient.callRPCMethod(server.getAgentURL() ,"send", UrlUtils.getOwnCallbackURL(), 1, server.getAgentPassword(),XmlHelper.craftXmlClass(XmlHelper.getSimpleActionQuery(action)) )
				return
			except Exception as e:
				if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE:
					# If the VM creation was interrupted in the network
					# configuration, the created VM won't be returned
					try:
						if not vm:
							vm = controller.getVMbyUUID(action.server.virtual_machines[0].uuid)
						controller.deleteVM(vm)
						# Keep actions table up-to-date after each deletion
						actionModel.delete()
					except Exception as e:
						print "Could not delete VM. Exception: %s" % str(e)
				#XmlRpcClient.callRPCMethod(threading.currentThread().callBackURL,"sendAsync",XmlHelper.craftXmlClass(XmlHelper.getProcessingResponse(Action.FAILED_STATUS, action, str(e))))
		logging.debug("PROVISIONING FINISHED...")
    def processProvisioning(provisioning):
		logging.debug("PROVISIONING STARTED...\n")
		for action in provisioning.action:
			actionModel = ActionController.ActionToModel(action,"provisioning")
			logging.debug("ACTION type: %s with id: %s" % (actionModel.type, actionModel.uuid))
			try:
				RuleTableManager.Evaluate(action,RuleTableManager.getDefaultName())
			except Exception as e:
				MAX_CHARS_ALLOWED = 200
				XmlRpcClient.callRPCMethod(threading.currentThread().callBackURL,"sendAsync",XmlHelper.craftXmlClass(XmlHelper.getProcessingResponse(Action.FAILED_STATUS, action,str(e)[0:MAX_CHARS_ALLOWED-1])))
				return None
			try:
				controller = VTDriver.getDriver(action.server.virtualization_type)
				#XXX:Change this when xml schema is updated
				server = VTDriver.getServerByUUID(action.server.uuid)
				#if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE:
				#	server = VTDriver.getServerByUUID(action.virtual_machine.server_id)
				#else:
				#	server = VTDriver.getVMbyUUID(action.virtual_machine.uuid).Server.get()
			except Exception as e:
				logging.error(e)
				raise e
			try:	
				#PROVISIONING CREATE
				if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE:
					try:
						vm = ProvisioningDispatcher.__createVM(controller, actionModel, action)
					except:
						vm = None
						raise
				#PROVISIONING DELETE, START, STOP, REBOOT
				else :
					ProvisioningDispatcher.__deleteStartStopRebootVM(controller, actionModel, action)
				XmlRpcClient.callRPCMethod(server.getAgentURL() ,"send", UrlUtils.getOwnCallbackURL(), 1, server.getAgentPassword(),XmlHelper.craftXmlClass(XmlHelper.getSimpleActionQuery(action)) )
				return
			except Exception as e:
				if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE:
					# If the VM creation was interrupted in the network
					# configuration, the created VM won't be returned
					try:
						if not vm:
							vm = controller.getVMbyUUID(action.server.virtual_machines[0].uuid)
						controller.deleteVM(vm)
						# Keep actions table up-to-date after each deletion
						actionModel.delete()
					except Exception as e:
						print "Could not delete VM. Exception: %s" % str(e)
				#XmlRpcClient.callRPCMethod(threading.currentThread().callBackURL,"sendAsync",XmlHelper.craftXmlClass(XmlHelper.getProcessingResponse(Action.FAILED_STATUS, action, str(e))))
		logging.debug("PROVISIONING FINISHED...")
Exemple #6
0
def policy_edit(request, table):

    if "HTTP_REFERER" in request.META:
        # Checks if the referer page is the home or this page itself
        if "/dashboard" in request.META[
                'HTTP_REFERER'] or "/policies" in request.META['HTTP_REFERER']:
            ruleTableSet = RuleTableManager.getAllInstances(
                RuleTableManager.getDefaultName())
            return simple.direct_to_template(
                request,
                template='policyEngine/policy_edit.html',
                extra_context={
                    'user': request.user,
                    'CurrentTable': ruleTableSet
                })
    # If the access flow is incorrect, send home
    return HttpResponseRedirect("/")
Exemple #7
0
def rule_table_view(request, TableName=None):

    if (not request.user.is_superuser):

        return simple.direct_to_template(
            request,
            template='not_admin.html',
            extra_context={'user': request.user},
        )

    else:  #Admin
        ruleTable = RuleTableManager.getInstance(
            RuleTableManager.getDefaultName())

        return simple.direct_to_template(
            request,
            template='policyEngine/table_view.html',
            extra_context={
                'user': request.user,
                'table': ruleTable
            },
        )
Exemple #8
0
    def processProvisioning(provisioning):

        logging.debug("PROVISIONING STARTED...\n")
        for action in provisioning.action:
            actionModel = ActionController.ActionToModel(
                action, "provisioning")
            logging.debug("ACTION type: %s with id: %s" %
                          (actionModel.type, actionModel.uuid))

            try:
                RuleTableManager.Evaluate(action,
                                          RuleTableManager.getDefaultName())
            except Exception as e:
                a = str(e)
                if len(a) > 200:
                    a = a[0:199]

                XmlRpcClient.callRPCMethod(
                    threading.currentThread().callBackURL, "sendAsync",
                    XmlHelper.craftXmlClass(
                        XmlHelper.getProcessingResponse(
                            Action.FAILED_STATUS, action, a)))
                #				XmlRpcClient.callRPCMethod(threading.currentThread().callBackURL,"sendAsync",XmlHelper.craftXmlClass(XmlHelper.getProcessingResponse('FAILED', action, 'You requested more than the 128Mbytes allowed for your project')))
                return None
            try:

                controller = VTDriver.getDriver(
                    action.server.virtualization_type)

                #XXX:Change this when xml schema is updated
                server = VTDriver.getServerByUUID(action.server.uuid)
                #if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE:
                #	server = VTDriver.getServerByUUID(action.virtual_machine.server_id)
                #else:
                #	server = VTDriver.getVMbyUUID(action.virtual_machine.uuid).Server.get()
            except Exception as e:
                logging.error(e)
                raise e

            try:
                #PROVISIONING CREATE
                if actionModel.getType() == Action.PROVISIONING_VM_CREATE_TYPE:
                    try:
                        vm = ProvisioningDispatcher.__createVM(
                            controller, actionModel, action)
                    except:
                        vm = None
                        raise
                #PROVISIONING DELETE, START, STOP, REBOOT

                else:

                    ProvisioningDispatcher.__deleteStartStopRebootVM(
                        controller, actionModel, action)

                XmlRpcClient.callRPCMethod(
                    server.getAgentURL(), "send", UrlUtils.getOwnCallbackURL(),
                    1, server.getAgentPassword(),
                    XmlHelper.craftXmlClass(
                        XmlHelper.getSimpleActionQuery(action)))
            except Exception as e:
                if actionModel.getType(
                ) == Action.PROVISIONING_VM_CREATE_TYPE and vm:
                    controller.deleteVM(vm)
                XmlRpcClient.callRPCMethod(
                    threading.currentThread().callBackURL, "sendAsync",
                    XmlHelper.craftXmlClass(
                        XmlHelper.getProcessingResponse(
                            Action.FAILED_STATUS, action, str(e))))

        logging.debug("PROVISIONING FINISHED...")