Exemple #1
0
	def __init__(self, name, path, namespace, cacheLifetime, parameters):
		"""
		Create an instance and inicialize the structure needed by it.
		@type  parameters: dictionary
		@param parameters : Should be a dictionary containning the follow keys:
							- host : the host ip-address where the device is locate.
							- port : the port number where the Quagga software router is listen at the Telnet Connection.
							- password and enable\_pass :  The passwords to allow a connection to the device and for set root privileges for configurate it, respectibility.
							- instance : It allows to create more than one instance of the module adding an \textit {instance} attribute with the value specified by it into the root node of the XML BGP Configuration document. If it not specified it will not add anything.
							- allowxpath : It turn on or off the xpath "Looking into the Values" capability as specified by the value. If it is not specified the default value is false.
		"""

		Module.__init__(self, name, path, namespace, cacheLifetime)

		host = parameters["host"]
		port = parameters["port"]
		password = parameters["password"]
		enable_password = parameters["enable_pass"]

		self.deviceConnection = VTY_Connection(host, port, password, enable_password)

		allowxpath = False
		
		if( "allowxpath" in parameters):
			if (parameters["allowxpath"] == "true"):
				allowxpath = True
		
		if( "instance" in parameters):
			instance = parameters["instance"]
		else: 
			instance = None
		
		structXML = NonvalidatingReader.parseUri("file:"+self.PROTOCOL_STRUCTURE_FILE)
		
		self.XMLConstructor = XML_Constructor.XML_Constructor(structXML, self.namespace, instance)
		self.XMLInterpreter = XML_Interpreter.XML_Interpreter(structXML, self.namespace, allowxpath)
Exemple #2
0
class CLI_Module(Module):
	"""
		It is the main class of the CLI protocol Module implementation for the NetConf Agent.
		@type deviceConnection: VTY_Connection
		@param deviceConnection:  it provides the specific function to allow the communication with the bgp device.
		@type oldconfig : string
		@param oldconfig: It saves the last configuration before an edit-config request, if specified, in order to restablish this configuration in the device in case of a failiture of this or another node involved in the request.
		@type XMLConstructor: XML Protocol Translator.XML_Constructor 
		@param XMLConstructor:  allows to construct the XML configuration device document from the data obtained by the device.
		@type XMLInterpreter: XML_Protocol_Translator.XML_Interpreter
		@param XMLInterpreter : allows to interprete a XML request from the Agent and generates the equivalent for the Protocol specified by the device. 
	"""


	def __init__(self, name, path, namespace, cacheLifetime, parameters):
		"""
		Create an instance and inicialize the structure needed by it.
		@type  parameters: dictionary
		@param parameters : Should be a dictionary containning the follow keys:
							- host : the host ip-address where the device is locate.
							- port : the port number where the Quagga software router is listen at the Telnet Connection.
							- password and enable\_pass :  The passwords to allow a connection to the device and for set root privileges for configurate it, respectibility.
							- instance : It allows to create more than one instance of the module adding an \textit {instance} attribute with the value specified by it into the root node of the XML BGP Configuration document. If it not specified it will not add anything.
							- allowxpath : It turn on or off the xpath "Looking into the Values" capability as specified by the value. If it is not specified the default value is false.
		"""

		Module.__init__(self, name, path, namespace, cacheLifetime)

		host = parameters["host"]
		port = parameters["port"]
		password = parameters["password"]
		enable_password = parameters["enable_pass"]

		self.deviceConnection = VTY_Connection(host, port, password, enable_password)

		allowxpath = False
		
		if( "allowxpath" in parameters):
			if (parameters["allowxpath"] == "true"):
				allowxpath = True
		
		if( "instance" in parameters):
			instance = parameters["instance"]
		else: 
			instance = None
		
		structXML = NonvalidatingReader.parseUri("file:"+self.PROTOCOL_STRUCTURE_FILE)
		
		self.XMLConstructor = XML_Constructor.XML_Constructor(structXML, self.namespace, instance)
		self.XMLInterpreter = XML_Interpreter.XML_Interpreter(structXML, self.namespace, allowxpath)
		

	def getConfig(self, configName):
		"""
			Generate the BGP device's XML configuration.
			Note that for every request it opens a new connection to the device, this behaivor allows multiple request at the same time. To avoid problems of concurrency, this implementation relies over the lock provided by the device, in this case the Quagga software.
			@rtype: ModuleReply
			@return: the main node of the BGP protocol if it success or the error ocurred.
			** Relates to the netconf get-config operation
		"""
		
		if configName in [C.RUNNING, C.STARTUP]:

			try :
				id = self.deviceConnection.stablishConnection()
				id,config = self.deviceConnection.getConfiguration(id, self.protocol, configName)
				self.deviceConnection.closeConnection(id)
				parserstruct = self.parse("Parser",config)
				confdoc = self.XMLConstructor.construct_XML(parserstruct)
				modulereply = ModuleReply(replynode=confdoc.documentElement)

			except ConnectError , exp :
				modulereply = ModuleReply(
				error_type=ModuleReply.APPLICATION,
				error_tag=ModuleReply.RESOURCE_DENIED, 
				error_severity=ModuleReply.ERROR,
				error_tag_app=exp.getError(),
				error_message=str(exp))

			except Exception,exp:
				modulereply = ModuleReply(
				error_type=ModuleReply.APPLICATION,
				error_tag=ModuleReply.OPERATION_FAILED, 
				error_severity=ModuleReply.ERROR,
				error_message=str(exp))