source: opsi/products/opsi-bacula-server-conf.py@ 1071

Last change on this file since 1071 was 1028, checked in by joergs, on Jul 10, 2012 at 6:57:18 PM

create bacula-dir.conf complaiend output

  • Property svn:executable set to *
File size: 2.7 KB
Line 
1#!/usr/bin/env python
2
3# get client properties for bacula
4
5import subprocess
6import json
7from pprint import pprint
8
9opsi={
10 'server': "https://degdepot2.joergs:4447/rpc",
11 'username': "joergs",
12 'password': "linuxlinux",
13 }
14
15# "-d"
16opsiCallPrefix=[ "opsi-admin", "-a", opsi['server'], "-u", opsi['username'], "-p", opsi['password'] ]
17
18opsiCallClientsWithBacula=[ "method", "productOnClient_getObjects", "[]", '{"productId":"bacula", "installationStatus": "installed"}']
19
20opsiCallClientBaculaProperties=[ "method", "getProductProperties_hash", "bacula" ]
21
22
23def write_client_conf( client, properties ):
24 #Client {
25 #Name = ting-fd
26 #Address = ting.dass-it
27 #FDPort = 9102
28 #Catalog = MyCatalog
29 #Password = "D5w2V5w6B8a9H5Z"
30 #File Retention = 6 months
31 #Job Retention = 6 months
32 #AutoPrune = yes
33 #}
34 params = [ "FDPort", "Catalog", "FileRetention", "JobRetention", "AutoPrune" ]
35 print "Client {"
36 print " Name =", properties['filedaemon_full_name']
37 print " Address =", client['clientId']
38 # ipAddress: method host_getObjects [] '{"id":client['clientId']}'
39 #print " # Address =", ipAddress
40 print " Password =", properties['filedaemon_full_password']
41 for i in params:
42 try:
43 print " " + i + " = " + properties[i.lower()]
44 except KeyError:
45 print " # " + i + " = "
46 print "}"
47 print
48
49
50
51
52def write_job_conf( client, properties ):
53 #Job {
54 #FileSet = "tingfileset"
55 #Name = "ting"
56 #Client = ting-fd
57 #JobDefs = "LaptopJob"
58 ## Write Bootstrap = "/var/lib/bacula/ting.bsr"
59 #}
60 params = [ "Fileset", "JobDefs" ]
61 print "Job {"
62 print " Name =", client['clientId'] + "-job"
63 print " Client =", properties['filedaemon_full_name']
64 for i in params:
65 print " ",
66 try:
67 if not properties[i.lower()]:
68 print "#",
69 print i + " = " + properties[i.lower()]
70 except KeyError:
71 print "# " + i + " = "
72 print "}"
73 print
74
75
76
77#
78# main
79#
80
81try:
82 clientsWithBacula=json.loads( subprocess.check_output( opsiCallPrefix + opsiCallClientsWithBacula ) )
83except subprocess.CalledProcessError:
84 print "failed"
85 exit( 1 )
86
87pprint( clientsWithBacula )
88
89for client in clientsWithBacula:
90 clientId = client['clientId']
91 print clientId
92
93 try:
94 clientBaculaProperties=json.loads( subprocess.check_output( opsiCallPrefix + opsiCallClientBaculaProperties + [ client['clientId'] ] ) )
95 except subprocess.CalledProcessError:
96 print "failed"
97 exit( 1 )
98
99 pprint( clientBaculaProperties )
100 write_client_conf( client, clientBaculaProperties )
101 write_job_conf( client, clientBaculaProperties )
Note: See TracBrowser for help on using the repository browser.