Changeset 813 for vanHelsing/trunk/src


Ignore:
Timestamp:
Jan 13, 2010, 12:39:46 PM (15 years ago)
Author:
slederer
Message:

FileDaemon-Konfiguration erzeugen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vanHelsing/trunk/src/bcfg.py

    r812 r813  
    88import resource
    99import directive
     10import random
    1011
    1112RESOURCE_TYPES = ('dird', 'console', 'filed', 'stored')
     
    6566                #curRes.add_comment(inlinecomment)
    6667
    67             if len(line)>0 and line[0]=='@':
    68                 includepath=line[1:].strip()
    69                 print "include " +includepath
    70                 self.parse(self.resources,open(includepath,"r"),0)
     68            include=line.strip()
     69            if include.startswith("@"):
     70                includepath=include[1:].strip()
     71                print "include " +includepath
     72                self.parse(curRes,open(includepath,"r"),level)
    7173
    7274            if rxp_closebrace.match(line):
     
    124126
    125127class FiledConfig(Config):
    126     pass
     128    def __init__(self, filename=""):
     129        Config.__init__(self, 'fd', filename)
    127130
     131    def setDefaults(self,directorName,directorPassword,myName):
     132        director=resource.Director(1,"Director")
     133        director.add("Name",directorName)
     134        director.add("Password",'"'+directorPassword+'"')
     135        self.getRoot().add_item(director)
     136       
     137        fileDaemon=resource.FileDaemon(1,"FileDaemon")
     138        fileDaemon.add("Name",myName)
     139        #fileDaemon.add("FDport","9102")
     140        fileDaemon.add("WorkingDirectory","/var/lib/bacula")
     141        fileDaemon.add("Pid Directory","/var/run")
     142        fileDaemon.add("Maximum Concurrent Jobs","20")
     143        self.getRoot().add_item(fileDaemon)
     144
     145        messages=resource.Messages(1,"Messages")
     146        messages.add("Name","Standard")
     147        messages.add("director",directorName+" = all, !skipped, !restored")
     148        self.getRoot().add_item(messages)
     149       
    128150class StoredConfig(Config):
    129151    pass
     
    135157    #newclient.add("FDPort",fdport)
    136158    newclient.add("Catalog",catalog)
    137     newclient.add("Password",password)
     159    newclient.add("Password",'"'+password+'"')
    138160    return newclient
    139161
     162def genpasswd(len=32):
     163    charset="01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!/%()=?@"
     164    password=""
     165    for a in xrange(0,len):
     166       password += random.choice(charset)
     167    return password
     168 
    140169if __name__ == "__main__":
    141    
    142     dirdcfg = DirdConfig("test.conf")
     170
     171    if len(sys.argv) < 2:
     172        filename="test.conf"
     173    else:
     174        filename=sys.argv[1]   
     175 
     176    dirdcfg = DirdConfig(filename)
    143177    dirdcfg.read()
    144178
     
    152186    root.add_item(job)
    153187
    154     newclient=createClient("testclient-fd","testclient","MyCatalog","testpassword")
     188    pwd=genpasswd()
     189    newclient=createClient("test-fd","testclient","MyCatalog",pwd)
    155190    root.add_item(newclient)
    156191
    157192    dirdcfg.write("test.conf.out")
     193
     194    fdcfg=FiledConfig("test-fd.conf")
     195    fdcfg.setDefaults("bacula-dird",pwd,"test-fd")
     196    fdcfg.write()
     197
    158198    sys.exit(0)
Note: See TracChangeset for help on using the changeset viewer.