[1027] | 1 | #!/usr/bin/env python
|
---|
| 2 |
|
---|
| 3 | # get client properties for bacula
|
---|
| 4 |
|
---|
| 5 | import subprocess
|
---|
| 6 | import json
|
---|
| 7 | from pprint import pprint
|
---|
| 8 |
|
---|
| 9 | opsi={
|
---|
| 10 | 'server': "https://degdepot2.joergs:4447/rpc",
|
---|
| 11 | 'username': "joergs",
|
---|
| 12 | 'password': "linuxlinux",
|
---|
| 13 | }
|
---|
| 14 |
|
---|
| 15 | # "-d"
|
---|
| 16 | opsiCallPrefix=[ "opsi-admin", "-a", opsi['server'], "-u", opsi['username'], "-p", opsi['password'] ]
|
---|
| 17 |
|
---|
| 18 | opsiCallClientsWithBacula=[ "method", "productOnClient_getObjects", "[]", '{"productId":"bacula", "installationStatus": "installed"}']
|
---|
| 19 |
|
---|
| 20 | opsiCallClientBaculaProperties=[ "method", "getProductProperties_hash", "bacula" ]
|
---|
| 21 |
|
---|
[1028] | 22 |
|
---|
| 23 | def 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 |
|
---|
| 52 | def 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 |
|
---|
[1027] | 81 | try:
|
---|
| 82 | clientsWithBacula=json.loads( subprocess.check_output( opsiCallPrefix + opsiCallClientsWithBacula ) )
|
---|
| 83 | except subprocess.CalledProcessError:
|
---|
| 84 | print "failed"
|
---|
| 85 | exit( 1 )
|
---|
| 86 |
|
---|
| 87 | pprint( clientsWithBacula )
|
---|
| 88 |
|
---|
| 89 | for client in clientsWithBacula:
|
---|
[1028] | 90 | clientId = client['clientId']
|
---|
| 91 | print clientId
|
---|
[1027] | 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 )
|
---|
[1028] | 100 | write_client_conf( client, clientBaculaProperties )
|
---|
| 101 | write_job_conf( client, clientBaculaProperties )
|
---|