Ignore:
Timestamp:
Feb 17, 2010, 5:49:19 PM (15 years ago)
Author:
slederer
Message:

Generierter Server-Code

File:
1 edited

Legend:

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

    r823 r824  
    88import resource
    99import directive
    10 import random
     10
    1111
    1212RESOURCE_TYPES = ('dird', 'console', 'filed', 'stored')
     
    157157    pass
    158158
    159 def genpasswd(len=32):
    160     charset="01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!/%()=?@"
    161     password=""
    162     for a in xrange(0,len):
    163        password += random.choice(charset)
    164     return password
    165 
    166 
    167 def createClientConfig(dirdcfg,clientName,clientPassword=genpasswd()):
    168     director=dirdcfg.getRoot().getByType("Director")[0]
    169     dirdName=director.getName()
    170     r=dirdcfg.getRoot().getByName(clientName)
    171     if len(r)==1:
    172         client=r[0]
    173     else:
    174         return
    175    
    176     filename=clientName+".conf"
    177     fdcfg=FiledConfig(filename)
    178     fdcfg.setDefaults(dirdName,clientPassword,clientName)
    179     fdcfg.write()
    180 
    181 def createAllClientConfigs(dirdcfg):
    182     clients=dirdcfg.getRoot().getByType("Client",1)
    183     director=dirdcfg.getRoot().getByType("Director")[0]
    184     dirdName=director.getName()
    185 
    186     for c in clients:
    187         print c
    188         clientName=c.getName()
    189         if clientName!=None:
    190             r=c.getByType("Password")
    191             if len(r)>0:
    192                 clientPassword=r[0].value
    193                 clientPassword=clientPassword.replace('"','')
    194             else:
    195                 clientPassword=""
    196             filename=clientName+".conf"
    197             fdcfg=FiledConfig(filename)
    198             fdcfg.setDefaults(dirdName,clientPassword,clientName)
    199             fdcfg.write()
    200 
    201 def getDirectors():
    202     return [ "bacula-dir" ];
    203 
    204 def loadDirectorConfig(filename):
    205     global currentConfig
    206     currentConfig=DirdConfig(filename)
    207     currentConfig.read()
    208 
    209 def getDirectorConfig(directorName):
    210     global currentConfig
    211     return currentConfig
    212 
    213 def getClients(directorName):
    214     return getResources(directorName,"Client")
    215 
    216 def getResources(directorName,resType):
    217     dirdcfg=getDirectorConfig(directorName)
    218     resources=dirdcfg.getRoot().getByType(resType,1)
    219     result=[]
    220     for r in resources:
    221         result.append((r.id,r.getName()))
    222     return result
    223 
    224 def getResourceById(directorName,resId):
    225     dirdcfg=getDirectorConfig(directorName)
    226     return dirdcfg.getRoot().getById(resId)   
    227 
    228 def getResourceByName(directorName,resType,name):
    229     dirdcfg=getDirectorConfig(directorName)
    230     return dirdcfg.getRoot().getByName(name,resType)[0]   
    231 
    232 
    233159if __name__ == "__main__":
    234160    if len(sys.argv) < 2:
Note: See TracChangeset for help on using the changeset viewer.