- Timestamp:
- Aug 6, 2012, 5:13:08 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
opsi/server/opsi-tools-dass-it/usr/bin/opsi-client-copy.py
r1044 r1046 1 1 #!/usr/bin/env python 2 2 3 # get client properties for bacula 3 # Skript erstellen, dass ein OPSI-Rechner-Eintrag kopiert. 4 # D.h. die Produkte, Anforderung. 5 # Ggf. optional Stand und ggf. Versionsnummer 6 # Ggf. optional ProductProperties 4 7 5 import subprocess 6 import json 8 #self.command("opsi-admin -d method host_createOpsiClient "+ \ 9 #computername + " null " + "\\'"+description+"\\'" + \ 10 #" \\'created by dassadmin\\' " + mac_address + " " + \ 11 #ip_address) 12 #method host_createOpsiClient id *opsiHostKey *description *notes *hardwareAddress *ipAddress *inventoryNumber *oneTimePassword *created *lastSeen 13 #self.command("opsi-admin -d method configState_create clientconfig.depot.id " + \ 14 #computername + " " + depotName) 15 16 import jsonrpc 7 17 from pprint import pprint 8 18 9 opsi={ 10 'server': "https://degdepot2.joergs:4447/rpc", 11 'username': "joergs", 12 'password': "linuxlinux", 13 } 19 UrlJsonRpc="https://joergs:linuxlinux@opsi4.joergs.dass-it:4447/rpc" 14 20 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 class OpsiRpc: 22 def __init__(self, urlJsonRpc=UrlJsonRpc): 23 self.urlJsonRpc=urlJsonRpc 24 self.rpcProxy=jsonrpc.ServiceProxy(self.urlJsonRpc) 25 26 def dump(self): 27 print self.urlJsonRpc 28 print self.rpcProxy.getClientIds_list() 29 30 def copyClient( self, src, dst, hardwareAddress, ipAddress ): 31 32 #method host_createOpsiClient id *opsiHostKey *description *notes *hardwareAddress *ipAddress *inventoryNumber *oneTimePassword *created *lastSeen 33 id=dst 34 opsiHostKey=None 35 description="" 36 notes="copy of " + src 37 self.rpcProxy.host_createOpsiClient( id, opsiHostKey, description, notes, hardwareAddress, ipAddress ) 38 39 def productOnClient( self, client ): 40 pprint( self.rpcProxy.productOnClient_getObjects( [], { 'clientId': client } ) ) 21 41 22 42 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 43 44 if __name__ == '__main__': 45 opsi=OpsiRpc() 46 #opsi.dump() 47 opsi.copyClient( "test1.joergs.dass-it.opsi", "testnew1.joergs.dass-it.opsi", "00:00:00:00:01:01", "192.168.0.1" ) 48 opsi.productOnClient( "opsiwin1.joergs.dass-it.opsi" ) 49 opsi.dump() 50 print "end" 48 51 49 50 51 52 def write_job_conf( client, properties ):53 #Job {54 #FileSet = "tingfileset"55 #Name = "ting"56 #Client = ting-fd57 #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 print74 75 76 77 #78 # main79 #80 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:90 clientId = client['clientId']91 print clientId92 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 TracChangeset
for help on using the changeset viewer.