source: vanHelsing/trunk/src/VanHelsingSOAP.py@ 830

Last change on this file since 830 was 824, checked in by slederer, on Feb 17, 2010 at 5:49:19 PM

Generierter Server-Code

File size: 2.6 KB
Line 
1#!/usr/bin/python
2
3from bcfg import *
4import resource
5import directive
6import ResourceInfo
7
8import ZSI
9import ZSI.dispatch
10
11import sys
12import random
13
14def 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
22def 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
36def 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
56def getDirectors():
57 return [ "bacula-dir" ];
58
59def loadDirectorConfig(filename):
60 global currentConfig
61 currentConfig=DirdConfig(filename)
62 currentConfig.read()
63
64def getDirectorConfig(directorName):
65 global currentConfig
66 return currentConfig
67
68def getClients(directorName):
69 return getResources(directorName,"Client")
70
71def 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
79def getResourceById(directorName,resId):
80 dirdcfg=getDirectorConfig(directorName)
81 return dirdcfg.getRoot().getById(resId)
82
83def getResourceByName(directorName,resType,name):
84 dirdcfg=getDirectorConfig(directorName)
85 return dirdcfg.getRoot().getByName(name,resType)[0]
86
87def listResources(listResourcesType):
88 print listResourcesType
89 return [ r1,r2 ]
90
91# main
92if __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)
Note: See TracBrowser for help on using the repository browser.