Changeset 1047 for opsi/server/opsi-tools-dass-it
- Timestamp:
- Aug 10, 2012, 7:44:04 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
opsi/server/opsi-tools-dass-it/usr/bin/opsi-client-copy.py
r1046 r1047 13 13 #self.command("opsi-admin -d method configState_create clientconfig.depot.id " + \ 14 14 #computername + " " + depotName) 15 15 16 import argparse 16 17 import jsonrpc 17 18 from pprint import pprint … … 20 21 21 22 class OpsiRpc: 22 def __init__(self, urlJsonRpc=UrlJsonRpc): 23 24 ProductAttributesCopy = ['actionRequest','actionResult','installationStatus','packageVersion','productVersion'] 25 26 def __init__(self, urlJsonRpc, debug=False ): 27 self.debug=debug 23 28 self.urlJsonRpc=urlJsonRpc 24 self.rpc Proxy=jsonrpc.ServiceProxy(self.urlJsonRpc)29 self.rpc=jsonrpc.ServiceProxy(self.urlJsonRpc) 25 30 26 31 def dump(self): 27 32 print self.urlJsonRpc 28 print self.rpc Proxy.getClientIds_list()33 print self.rpc.getClientIds_list() 29 34 30 def copyClient( self, src, dst, hardwareAddress, ipAddress):35 def copyClient( self, src, dst, ipAddress = None, hardwareAddress = None, depot = None ): 31 36 37 print "create/update", dst, "from template", src + ":", 32 38 #method host_createOpsiClient id *opsiHostKey *description *notes *hardwareAddress *ipAddress *inventoryNumber *oneTimePassword *created *lastSeen 33 id=dst39 #id=dst 34 40 opsiHostKey=None 35 41 description="" 36 42 notes="copy of " + src 37 self.rpcProxy.host_createOpsiClient( id, opsiHostKey, description, notes, hardwareAddress, ipAddress ) 43 self.rpc.host_createOpsiClient( dst, opsiHostKey, description, notes, hardwareAddress, ipAddress ) 44 if depot: 45 self.rpc.configState_create( "clientconfig.depot.id", dst, depot ) 46 if self.debug: 47 self.productOnClient( src ) 48 self.copyProductOnClient( src, dst ) 49 # TODO: 50 # copy product properties: 51 # opsiCallClientBaculaProperties=[ "method", "getProductProperties_hash", "bacula" ] 52 print "done" 53 38 54 39 def productOnClient( self, client ): 40 pprint( self.rpcProxy.productOnClient_getObjects( [], { 'clientId': client } ) ) 41 55 def productOnClient( self, client, attributes = ProductAttributesCopy ): 56 #pprint( self.rpc.productOnClient_getObjects( [], { 'clientId': client } ) ) 57 #pprint( self.rpc.productOnClient_getHashes( attributes, { 'clientId': client } ) ) 58 pprint( self.rpc.productOnClient_getHashes( [], { 'clientId': client } ) ) 59 60 def copyProductOnClient( self, src, dst, attributes = ProductAttributesCopy ): 61 products = self.rpc.productOnClient_getHashes( attributes, { 'clientId': src } ) 62 for i in products: 63 if self.debug: 64 pprint( i ) 65 print i['productId'] 66 i['clientId'] = dst 67 self.rpc.productOnClient_createObjects( i ) 68 if self.debug: 69 self.productOnClient( dst ) 70 42 71 43 72 44 73 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" 74 parser = argparse.ArgumentParser(description='Command line tool for OPSI configuration.') 75 parser.add_argument( '--debug', action='store_true', help="enable debugging output" ) 76 #parser.add_argument( '--verbose', type=bool, help="add debugging output" ) 77 parser.add_argument( 'src', help="source/template opsi client" ) 78 parser.add_argument( 'dst', help="opsi client to be created" ) 79 parser.add_argument( '--ip', help="IP address of the new opsi client" ) 80 parser.add_argument( '--mac', help="MAC address of the new opsi client" ) 81 parser.add_argument( '--depot', help="depot server the new opsi client should be located" ) 82 parser.add_argument( '--url', help="OPSI Server JSON-RPC url, normally https://<username>:<password>@<OPSI-SERVER>:4447/rpc" ) 83 84 85 args = parser.parse_args() 51 86 87 urlJsonRpc = UrlJsonRpc 88 if args.url: 89 urlJsonRpc = args.url 90 91 opsi=OpsiRpc( urlJsonRpc, args.debug ) 92 opsi.copyClient( args.src, args.dst, args.ip, args.mac, args.depot ) 93 if args.debug: print "end" 94
Note:
See TracChangeset
for help on using the changeset viewer.