Changeset 824 for vanHelsing/trunk/src/bcfg.py
- Timestamp:
- Feb 17, 2010, 5:49:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vanHelsing/trunk/src/bcfg.py
r823 r824 8 8 import resource 9 9 import directive 10 import random 10 11 11 12 12 RESOURCE_TYPES = ('dird', 'console', 'filed', 'stored') … … 157 157 pass 158 158 159 def genpasswd(len=32):160 charset="01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!/%()=?@"161 password=""162 for a in xrange(0,len):163 password += random.choice(charset)164 return password165 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 return175 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 c188 clientName=c.getName()189 if clientName!=None:190 r=c.getByType("Password")191 if len(r)>0:192 clientPassword=r[0].value193 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 currentConfig206 currentConfig=DirdConfig(filename)207 currentConfig.read()208 209 def getDirectorConfig(directorName):210 global currentConfig211 return currentConfig212 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 result223 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 233 159 if __name__ == "__main__": 234 160 if len(sys.argv) < 2:
Note:
See TracChangeset
for help on using the changeset viewer.