Example #1
0
	def unloadModule(self, name):
		for module in self.modules:
			if module.name == name:
				self.modules.remove(module)
				dm = DatastoreManager.getInstance()
				dm.removeModule(module, C.RUNNING, "config")
				dm.removeModule(module, C.RUNNING, "state")
				dm.removeModule(module, C.STARTUP, "config")
				dm.removeModule(module, C.STARTUP, "state")
				# Success
				return 1

		return 0
    def loadModule(self, name):

        for module in self.modules:
            if module.name == name:
                # Should return an error, saying that this module is already loaded.
                return 2

        # Parse modules conf file
        moduleDescrList = ModuleReader.getInstance().readModules()

        # Create modules
        for moduleDescr in moduleDescrList:
            if moduleDescr["name"] == name:
                # Set the namespace prefix list
                self.prefixes[moduleDescr["pref"]] = moduleDescr["namespace"]
                # Create the new module from its descriptor
                newModule = ModuleFactory.getInstance().createModule(
                    moduleDescr)
                if newModule == None:
                    print moduleDescr
                    return 0
                else:
                    # Add the module to the module list
                    self.modules.append(newModule)
                    dm = DatastoreManager.getInstance()

                    # Build the parent XML nodes from the root up to the module node.
                    dm.initConfigModule(newModule, C.RUNNING, "config")
                    dm.initConfigModule(newModule, C.RUNNING, "state")
                    dm.initConfigModule(newModule, C.STARTUP, "config")
                    dm.initConfigModule(newModule, C.STARTUP, "state")

                    # Query the module to update the config.
                    dm.updateConfig(C.RUNNING, "config")
                    dm.updateConfig(C.RUNNING, "state")
                    dm.updateConfig(C.STARTUP, "config")
                    dm.updateConfig(C.STARTUP, "state")

                    # Success
                    return 1

        return 3