def MoveConfig(self, frset, frnode, toset, tonode): """ Move/rename node configuration on gateway server """ if frset == toset and frnode == tonode: return self.wbConfigError("Cannot move node configuration to itself") # Check target node, and ensure it is a 3-digit string if not WebBrickCfgEdit.NodeNumRegex.match(tonode): return self.wbConfigError( "Invalid target node %s (must be a number)"%(tonode)) n = int(tonode) if n <= 0 or n > 255: return self.wbConfigError( "Invalid target node %n (must be in range 1-255)"%(n)) tonode = formatInt("%03d")(n) if Config.exists(toset, tonode): return self.wbConfigError( "Invalid target node %s/%s already exists"%(toset,tonode)) # Now copy err = Config.move(frset, frnode, toset, tonode) if err: return self.wbConfigError(err) return self.wbConfigMessage( "Moved WebBrick configuration %s/%s to %s/%s" % (frset, frnode, toset, tonode))
def UploadConfigData(self, toset, data): """ Save configuration for a single WebBrick 'toset' is the target configuration set 'data' is a the WebBrick configuration data to be saved. """ Trace( "%s"%(toset), "WbCfgManagerForm.UploadConfigData") if not data: return (toset, "Empty configuration data supplied") wbcfg = Wb6Config(cnfxml=data) tonode = formatInt("%03d")(wbcfg.getNodeNumber()) return (tonode,Config.write(toset, tonode, wbcfg.getConfigXml()))
def create(configsetname, node, cnfxml): """ Create new configuration file with supplied XML content Return None if create succeeds, otherwise a string describing the reason for failure. """ node = formatInt("%03d")(int(node)) config = configPath(configsetname, node) if not config: return ( "Create config: config path name problem (%s, %s) - missing directory or bad name?" % (configsetname, node) ) if os.path.exists(config): return ( "Create config: file already exists (%s, %s)" % (configsetname, node) ) f = open(config, mode="w") f.write(cnfxml) f.close() return None