def __init__(self): 
		"""
			Instanciates the validate operation
		"""
		self.datastoreManager = DatastoreManager.getInstance()
		self.moduleManager = ModuleManager.getInstance()
		self.rbacManager = rbacManager.getInstance()
		self.config = None
    def __init__(self):
        """
			Instanciates the validate operation
		"""
        self.datastoreManager = DatastoreManager.getInstance()
        self.moduleManager = ModuleManager.getInstance()
        self.rbacManager = rbacManager.getInstance()
        self.config = None
    def exchangeCapabilities(self, clientsock):
        """
		Exchange the capabilities with the manager.
		First sends the agent capabilities.
		Then waits for the remote manager capabilities.
		Creates a Netconf session and returns it.
		
		@type  clientsock: socket
		@param clientsock: The socket for the current client
		@rtype: session
		@return: The session created by the SessionManager.
		"""

        # Loading hello element along with static capabilities from hello.xml file
        helloRoot = NonvalidatingReader.parseUri(C.HELLO_URI)
        helloNode = helloRoot.documentElement

        # Finding a unique session-id for that session
        self.session = sessionManager.getInstance().createSession(
            clientsock, self.username)
        sessionId = self.session.getSessionId()
        LogManager.getInstance().logInfo(
            "opening Netconf session: (sessionId=%s)" %
            (self.session.getSessionId()))

        # Setup the session-id value within session-id node
        sessionIdNode = helloRoot.createElementNS(C.NETCONF_XMLNS,
                                                  C.SESSION_ID)
        helloNode.appendChild(sessionIdNode)
        sessionIdNode.appendChild(helloRoot.createTextNode(str(sessionId)))

        # Get the unique instance of the singleton ModuleManager:
        moduleManager = ModuleManager.getInstance()
        # Add the capabilities related to the modules to the hello message:
        for node in helloNode.childNodes:
            if (node.nodeType == Node.ELEMENT_NODE
                    and node.tagName == C.CAPABILITIES):
                for module in moduleManager.getModules():
                    capabNode = helloRoot.createElementNS(
                        C.NETCONF_XMLNS, C.CAPABILITY)
                    capabText = helloRoot.createTextNode(module.namespace)
                    capabNode.appendChild(capabText)
                    node.appendChild(capabNode)

        # Convert the hello element to String before sending
        hellostr = util.convertNodeToString(helloNode)

        # Sending capabilities along with a new session-id
        self.send(hellostr)

        # Receiving capabilities of the manager
        data = self.receive()

        # Printing Manager capabilities
        LogManager.getInstance().logInfo(
            "Manager capabilities received: (sessionId=%s)" %
            (self.session.getSessionId()))
示例#4
0
    def __init__(self):
        """
			Instanciates the edit-config operation
		"""
        self.datastoreManager = DatastoreManager.getInstance()
        self.moduleManager = ModuleManager.getInstance()
        self.rbacManager = rbacManager.getInstance()

        # Set default values
        self.defaultOperation = C.MERGE
        self.testOption = C.SET
        self.errorOption = C.STOP_ON_ERROR
	def __init__(self): 
		"""
			Instanciates the edit-config operation
		"""
		self.datastoreManager = DatastoreManager.getInstance()
		self.moduleManager = ModuleManager.getInstance()
		self.rbacManager = rbacManager.getInstance()

		# Set default values
		self.defaultOperation = C.MERGE
		self.testOption = C.SET
		self.errorOption = C.STOP_ON_ERROR
	def exchangeCapabilities(self, clientsock):
		"""
		Exchange the capabilities with the manager.
		First sends the agent capabilities.
		Then waits for the remote manager capabilities.
		Creates a Netconf session and returns it.
		
		@type  clientsock: socket
		@param clientsock: The socket for the current client
		@rtype: session
		@return: The session created by the SessionManager.
		"""

		# Loading hello element along with static capabilities from hello.xml file
		helloRoot = NonvalidatingReader.parseUri(C.HELLO_URI)
		helloNode = helloRoot.documentElement

		# Finding a unique session-id for that session
		self.session = sessionManager.getInstance().createSession(clientsock, self.username)
		sessionId = self.session.getSessionId()
		LogManager.getInstance().logInfo("opening Netconf session: (sessionId=%s)" % (self.session.getSessionId()))
		
		# Setup the session-id value within session-id node
		sessionIdNode = helloRoot.createElementNS(C.NETCONF_XMLNS, C.SESSION_ID)
		helloNode.appendChild(sessionIdNode)
		sessionIdNode.appendChild(helloRoot.createTextNode(str(sessionId)))
		
		# Get the unique instance of the singleton ModuleManager:
		moduleManager = ModuleManager.getInstance()
		# Add the capabilities related to the modules to the hello message:
		for node in helloNode.childNodes:
			if (node.nodeType== Node.ELEMENT_NODE and node.tagName == C.CAPABILITIES):
				for module in moduleManager.getModules():
					capabNode = helloRoot.createElementNS(C.NETCONF_XMLNS, C.CAPABILITY)
					capabText = helloRoot.createTextNode(module.namespace)
					capabNode.appendChild(capabText)
					node.appendChild(capabNode)

		# Convert the hello element to String before sending
		hellostr = util.convertNodeToString(helloNode)

		# Sending capabilities along with a new session-id
		self.send(hellostr)

		# Receiving capabilities of the manager
		data = self.receive()

		# Printing Manager capabilities
		LogManager.getInstance().logInfo("Manager capabilities received: (sessionId=%s)" % (self.session.getSessionId()))
	def __init__(self): 
		"""
			Constructor of a Copy_config_operation command.
		"""
		self.datastoreManager = DatastoreManager.getInstance()
		self.moduleManager = ModuleManager.getInstance()
		self.rbacManager = rbacManager.getInstance()

		# "running", "startup", "candidate", "url"
		self.source = None
		# "running", "startup", "candidate", "url"
		self.target = None
		# source url text value (e.g.: ftp://madynes.loria.fr/config.txt)
		self.urlSource = None
		# target url text value (e.g.: ftp://madynes.loria.fr/config.txt)
		self.urlTarget = None
	def __init__(self): 
		"""
			Constructor of a Copy_config_operation command.
		"""
		self.datastoreManager = DatastoreManager.getInstance()
		self.moduleManager = ModuleManager.getInstance()
		self.rbacManager = rbacManager.getInstance()

		# "running", "startup", "candidate", "url"
		self.source = None
		# "running", "startup", "candidate", "url"
		self.target = None
		# source url text value (e.g.: ftp://madynes.loria.fr/config.txt)
		self.urlSource = None
		# target url text value (e.g.: ftp://madynes.loria.fr/config.txt)
		self.urlTarget = None
		
		self.sourceInbound = None
    def execute(self):
        """
			Execute the Manage_modules operation.
		"""

        moduleReply = ModuleReply()

        operationType = self.operationItem["operation"]
        name = self.operationItem["name"]
        moduleManager = ModuleManager.getInstance()

        if operationType == "deploy":

            if moduleManager.getModuleFromName(name) != None:
                moduleReply = ModuleReply(
                    error_type=ModuleReply.PROTOCOL,
                    error_tag=ModuleReply.BAD_ELEMENT,
                    error_severity=ModuleReply.ERROR,
                    error_message=
                    "Module %s is loaded and therefore can not be deployed again."
                    % name)

            else:

                # Decode the Foo_Module.zip
                fileContent = self.operationItem["file"]
                fileContent = fileContent.decode("string_escape")

                # Save it in tmp dir:
                f = open("/tmp/toto.zip", 'wb')
                f.write(fileContent)
                f.close()

                # Install it in YencaP modules directory:
                os.popen3("unzip /tmp/toto.zip " + '-d ' + C.YENCAP_HOME +
                          '/Modules')
                #self.extract('/tmp/toto.zip', '/tmp/' + name + '_Module')

                # Update modules.xml
                moduleReader = ModuleReader.getInstance()
                moduleReader.addModule(name, self.operationItem["xpath"],
                                       self.operationItem["namespace"],
                                       self.operationItem["pref"],
                                       self.operationItem["cachelifetime"],
                                       self.operationItem["dictionnary"])
                moduleReader.writeModules()

                # Update hello.xml: No. This is done automatically after loading the deployed module. See Server.py

        elif operationType == "undeploy":

            if moduleManager.getModuleFromName(name) != None:
                moduleReply = ModuleReply(
                    error_type=ModuleReply.PROTOCOL,
                    error_tag=ModuleReply.BAD_ELEMENT,
                    error_severity=ModuleReply.ERROR,
                    error_message=
                    "Module %s is loaded and therefore can not be undeployed. Unload it first."
                    % name)
            else:
                # Remove the module from the file system
                modulepath = C.YENCAP_HOME + '/Modules/' + name + "_Module"
                # Remove the content of the module directory (os.rmdir works only if the dir is empty !!!)
                self.removeall(modulepath)
                # Remove the directory itself
                os.rmdir(modulepath)

                # Update modules.xml
                moduleReader = ModuleReader.getInstance()
                moduleReader.removeModule(name)
                moduleReader.writeModules()

                # Update hello.xml: No. This is done automatically. See Server.py

        elif operationType == "load":

            res = moduleManager.loadModule(name)

            if res == 0:
                moduleReply = ModuleReply(
                    error_type=ModuleReply.PROTOCOL,
                    error_tag=ModuleReply.BAD_ELEMENT,
                    error_severity=ModuleReply.ERROR,
                    error_message="Module %s could not be loaded." % name)
            elif res == 2:
                moduleReply = ModuleReply(
                    error_type=ModuleReply.PROTOCOL,
                    error_tag=ModuleReply.BAD_ELEMENT,
                    error_severity=ModuleReply.ERROR,
                    error_message="Module %s is already loaded." % name)
            elif res == 3:
                moduleReply = ModuleReply(
                    error_type=ModuleReply.PROTOCOL,
                    error_tag=ModuleReply.BAD_ELEMENT,
                    error_severity=ModuleReply.ERROR,
                    error_message=
                    "Module %s does not exist and therefore can not be loaded."
                    % name)
            elif res == 1:
                moduleReply = ModuleReply()

        elif operationType == "unload":

            res = moduleManager.unloadModule(name)

            if res == 0:
                moduleReply = ModuleReply(
                    error_type=ModuleReply.PROTOCOL,
                    error_tag=ModuleReply.BAD_ELEMENT,
                    error_severity=ModuleReply.ERROR,
                    error_message=
                    "Module %s is not loaded and therefore could not be unloaded."
                    % name)
            elif res == 1:
                moduleReply = ModuleReply()

        self.operationReply.setNode(moduleReply.getXMLNodeReply())
        return self.operationReply
示例#10
0
	def __init__(self): 
		""" Constructor of a Get_config_operation command. """ 
		self.targetModule = None
		self.moduleManager = ModuleManager.getInstance()
	def execute(self):
		"""
			Execute the Manage_modules operation.
		"""
		
		moduleReply = ModuleReply()

		operationType = self.operationItem["operation"]
		name = self.operationItem["name"]
		moduleManager = ModuleManager.getInstance()

		if operationType == "deploy":

			if moduleManager.getModuleFromName(name) != None:
				moduleReply = ModuleReply(
				error_type = ModuleReply.PROTOCOL,
				error_tag = ModuleReply.BAD_ELEMENT,
				error_severity = ModuleReply.ERROR,
				error_message = "Module %s is loaded and therefore can not be deployed again."%name)
			
			else:

				# Decode the Foo_Module.zip
				fileContent = self.operationItem["file"]
				fileContent = fileContent.decode("string_escape")

				# Save it in tmp dir:
				f = open("/tmp/toto.zip",'wb')
				f.write(fileContent)
				f.close()

				# Install it in YencaP modules directory:
				os.popen3("unzip /tmp/toto.zip " + '-d ' + C.YENCAP_HOME + '/Modules')
				#self.extract('/tmp/toto.zip', '/tmp/' + name + '_Module')

				# Update modules.xml
				moduleReader = ModuleReader.getInstance()
				moduleReader.addModule(name, self.operationItem["xpath"], self.operationItem["namespace"], self.operationItem["pref"], self.operationItem["cachelifetime"], self.operationItem["dictionnary"])
				moduleReader.writeModules()

				# Update hello.xml: No. This is done automatically after loading the deployed module. See Server.py
		
		elif operationType == "undeploy":

			if moduleManager.getModuleFromName(name) != None:
				moduleReply = ModuleReply(
				error_type = ModuleReply.PROTOCOL,
				error_tag = ModuleReply.BAD_ELEMENT,
				error_severity = ModuleReply.ERROR,
				error_message = "Module %s is loaded and therefore can not be undeployed. Unload it first."%name)
			else:
				# Remove the module from the file system
				modulepath = C.YENCAP_HOME + '/Modules/' + name + "_Module"
				# Remove the content of the module directory (os.rmdir works only if the dir is empty !!!)
				self.removeall(modulepath)
				# Remove the directory itself
				os.rmdir(modulepath)
			
				# Update modules.xml
				moduleReader = ModuleReader.getInstance()
				moduleReader.removeModule(name)
				moduleReader.writeModules()

				# Update hello.xml: No. This is done automatically. See Server.py

		elif operationType == "load":
			
			res = moduleManager.loadModule(name)

			if res == 0:
				moduleReply = ModuleReply(
				error_type = ModuleReply.PROTOCOL,
				error_tag = ModuleReply.BAD_ELEMENT,
				error_severity = ModuleReply.ERROR,
				error_message = "Module %s could not be loaded."%name)
			elif res == 2:
				moduleReply = ModuleReply(
				error_type = ModuleReply.PROTOCOL,
				error_tag = ModuleReply.BAD_ELEMENT,
				error_severity = ModuleReply.ERROR,
				error_message = "Module %s is already loaded."%name)
			elif res == 3:
				moduleReply = ModuleReply(
				error_type = ModuleReply.PROTOCOL,
				error_tag = ModuleReply.BAD_ELEMENT,
				error_severity = ModuleReply.ERROR,
				error_message = "Module %s does not exist and therefore can not be loaded."%name)
			elif res == 1:
				moduleReply = ModuleReply()

		elif operationType == "unload":
			
			res = moduleManager.unloadModule(name)
		
			if res == 0:
				moduleReply = ModuleReply(
				error_type = ModuleReply.PROTOCOL,
				error_tag = ModuleReply.BAD_ELEMENT,
				error_severity = ModuleReply.ERROR,
				error_message = "Module %s is not loaded and therefore could not be unloaded."%name)
			elif res == 1:
				moduleReply = ModuleReply()
		
		self.operationReply.setNode(moduleReply.getXMLNodeReply())
		return self.operationReply