[824] | 1 | #!/usr/bin/python
|
---|
| 2 |
|
---|
| 3 | from bcfg import *
|
---|
| 4 | import resource
|
---|
| 5 | import directive
|
---|
| 6 | import ResourceInfo
|
---|
| 7 |
|
---|
| 8 | import ZSI
|
---|
| 9 | import ZSI.dispatch
|
---|
| 10 |
|
---|
| 11 | import sys
|
---|
| 12 | import random
|
---|
| 13 |
|
---|
| 14 | def genpasswd(len=32):
|
---|
| 15 | charset="01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!/%()=?@"
|
---|
| 16 | password=""
|
---|
| 17 | for a in xrange(0,len):
|
---|
| 18 | password += random.choice(charset)
|
---|
| 19 | return password
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | def createClientConfig(dirdcfg,clientName,clientPassword=genpasswd()):
|
---|
| 23 | director=dirdcfg.getRoot().getByType("Director")[0]
|
---|
| 24 | dirdName=director.getName()
|
---|
| 25 | r=dirdcfg.getRoot().getByName(clientName)
|
---|
| 26 | if len(r)==1:
|
---|
| 27 | client=r[0]
|
---|
| 28 | else:
|
---|
| 29 | return
|
---|
| 30 |
|
---|
| 31 | filename=clientName+".conf"
|
---|
| 32 | fdcfg=FiledConfig(filename)
|
---|
| 33 | fdcfg.setDefaults(dirdName,clientPassword,clientName)
|
---|
| 34 | fdcfg.write()
|
---|
| 35 |
|
---|
| 36 | def createAllClientConfigs(dirdcfg):
|
---|
| 37 | clients=dirdcfg.getRoot().getByType("Client",1)
|
---|
| 38 | director=dirdcfg.getRoot().getByType("Director")[0]
|
---|
| 39 | dirdName=director.getName()
|
---|
| 40 |
|
---|
| 41 | for c in clients:
|
---|
| 42 | print c
|
---|
| 43 | clientName=c.getName()
|
---|
| 44 | if clientName!=None:
|
---|
| 45 | r=c.getByType("Password")
|
---|
| 46 | if len(r)>0:
|
---|
| 47 | clientPassword=r[0].value
|
---|
| 48 | clientPassword=clientPassword.replace('"','')
|
---|
| 49 | else:
|
---|
| 50 | clientPassword=""
|
---|
| 51 | filename=clientName+".conf"
|
---|
| 52 | fdcfg=FiledConfig(filename)
|
---|
| 53 | fdcfg.setDefaults(dirdName,clientPassword,clientName)
|
---|
| 54 | fdcfg.write()
|
---|
| 55 |
|
---|
| 56 | def getDirectors():
|
---|
| 57 | return [ "bacula-dir" ];
|
---|
| 58 |
|
---|
| 59 | def loadDirectorConfig(filename):
|
---|
| 60 | global currentConfig
|
---|
| 61 | currentConfig=DirdConfig(filename)
|
---|
| 62 | currentConfig.read()
|
---|
| 63 |
|
---|
| 64 | def getDirectorConfig(directorName):
|
---|
| 65 | global currentConfig
|
---|
| 66 | return currentConfig
|
---|
| 67 |
|
---|
| 68 | def getClients(directorName):
|
---|
| 69 | return getResources(directorName,"Client")
|
---|
| 70 |
|
---|
| 71 | def getResources(directorName,resType):
|
---|
| 72 | dirdcfg=getDirectorConfig(directorName)
|
---|
| 73 | resources=dirdcfg.getRoot().getByType(resType,1)
|
---|
| 74 | result=[]
|
---|
| 75 | for r in resources:
|
---|
| 76 | result.append((r.id,r.getName()))
|
---|
| 77 | return result
|
---|
| 78 |
|
---|
| 79 | def getResourceById(directorName,resId):
|
---|
| 80 | dirdcfg=getDirectorConfig(directorName)
|
---|
| 81 | return dirdcfg.getRoot().getById(resId)
|
---|
| 82 |
|
---|
| 83 | def getResourceByName(directorName,resType,name):
|
---|
| 84 | dirdcfg=getDirectorConfig(directorName)
|
---|
| 85 | return dirdcfg.getRoot().getByName(name,resType)[0]
|
---|
| 86 |
|
---|
| 87 | def listResources(listResourcesType):
|
---|
| 88 | print listResourcesType
|
---|
| 89 | return [ r1,r2 ]
|
---|
| 90 |
|
---|
| 91 | # main
|
---|
| 92 | if __name__ == "__main__":
|
---|
| 93 | if len(sys.argv) < 2:
|
---|
| 94 | filename="test.conf"
|
---|
| 95 | else:
|
---|
| 96 | filename=sys.argv[1]
|
---|
| 97 |
|
---|
| 98 | loadDirectorConfig(filename)
|
---|
| 99 |
|
---|
| 100 | print getResources("bacula-dir","Client")
|
---|
| 101 |
|
---|
| 102 | ZSI.dispatch.AsServer(port=8080,docstyle=True)
|
---|