source: vanHelsing/trunk/src/VanHelsingWrapper.py@ 836

Last change on this file since 836 was 836, checked in by slederer, on Mar 12, 2010 at 2:28:51 PM

Funktionierender SOAP-Server mit einer Methode

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