Changeset 1095 for opsi/products


Ignore:
Timestamp:
Sep 21, 2012, 12:29:22 PM (12 years ago)
Author:
joergs
Message:

write to file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • opsi/products/opsi-bacula-server-conf.py

    r1094 r1095  
    55import logging
    66import subprocess
     7import time
    78import json
    89from pprint import pprint
     
    2223
    2324
    24 def write_client_conf( client, properties ):
     25def write_client_conf( fd, client, properties ):
    2526    #Client {
    2627    #Name = ting-fd
     
    3435    #}
    3536    params = [ "FDPort", "Catalog", "FileRetention", "JobRetention", "AutoPrune" ]
    36     print "Client {"
    37     print "  Name     =", properties['filedaemon_full_name']
    38     print "  Address  =", client['clientId']
     37    fd.write( "Client {\n" )
     38    fd.write( "  Name     = " + properties['filedaemon_full_name'] + "\n" )
     39    fd.write( "  Address  = " + client['clientId'] + "\n" )
    3940    # ipAddress: method host_getObjects [] '{"id":client['clientId']}'
    4041    #print "  # Address =", ipAddress
    41     print "  Password =", properties['filedaemon_full_password']
     42    fd.write( "  Password = " + properties['filedaemon_full_password'] + "\n" )
    4243    for i in params:
    4344        try:
    44             print " " + i + " = " + properties[i.lower()]
     45            fd.write( " " + i + " = " + properties[i.lower()] + "\n" )
    4546        except KeyError:
    46             print "  # " + i + " = "
    47     print "}"
    48     print
     47            fd.write( "  # " + i + " = "  + "\n" )
     48    fd.write( "}\n")
     49    fd.write( "\n" )
    4950   
    5051   
    5152
    5253
    53 def write_job_conf( client, properties ):
     54def write_job_conf( fd, client, properties ):
    5455    #Job {
    5556    #FileSet = "tingfileset"
     
    6061    #}
    6162    params = [ "Fileset", "JobDefs" ]
    62     print "Job {"
    63     print "  Name    =", client['clientId'] + "-job"
    64     print "  Client  =", properties['filedaemon_full_name']
     63    fd.write( "Job {" + "\n" )
     64    fd.write( "  Name    = " + client['clientId'] + "-job" + "\n" )
     65    fd.write( "  Client  = " + properties['filedaemon_full_name'] + "\n" )
    6566    for i in params:
    66         print " ",
     67        fd.write( "  " )
    6768        try:
    6869            if not properties[i.lower()]:
    69                 print "#",
    70             print i + " = " + properties[i.lower()]
     70                fd.write( "# " )
     71            fd.write( i + " = " + properties[i.lower()] + "\n" )
    7172        except KeyError:
    72             print "# " + i + " = "
    73     print "}"
    74     print
    75 
    76    
     73            fd.write( "# " + i + " = " + "\n" )
     74    fd.write( "}" + "\n" )
     75    fd.write( "\n" )
    7776
    7877#
     
    9695
    9796#pprint( clientsWithBacula )
     97
     98if clientsWithBacula:
     99    try:
     100        file_opsi_clients = open('opsi-clients-generated.conf', 'w')
     101        file_opsi_clients.write( "#\n" )
     102        file_opsi_clients.write( "# automatically generated at {}\n".format( time.asctime() ) )
     103        file_opsi_clients.write( "#\n\n" )
    98104       
     105        file_opsi_jobs = open('opsi-jobs-generated.conf', 'w')
     106        file_opsi_jobs.write( "#\n" )
     107        file_opsi_jobs.write( "# automatically generated at {}\n".format( time.asctime() ) )
     108        file_opsi_jobs.write( "#\n\n" )
     109    except e:
     110        logger.exception( "failed to create files" )
     111        exit(1)
     112
    99113for client in clientsWithBacula:
    100114    clientId = client['clientId']
     
    109123    else:           
    110124        #pprint( clientBaculaProperties )
    111         write_client_conf( client, clientBaculaProperties )
    112         write_job_conf( client, clientBaculaProperties )
     125        write_client_conf( file_opsi_clients, client, clientBaculaProperties )
     126        write_job_conf( file_opsi_jobs, client, clientBaculaProperties )
    113127        logger.info( "%s: OK" % clientId )
    114128
Note: See TracChangeset for help on using the changeset viewer.