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

Last change on this file since 1094 was 1094, checked in by joergs, on Sep 21, 2012 at 11:47:40 AM

cleanup output

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