Changeset 1051
- Timestamp:
- Aug 15, 2012, 3:09:28 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
opsi/server/dass-opsi-tools/usr/bin/opsi-client.py
r1050 r1051 1 1 #!/usr/bin/env python 2 2 3 # Skript erstellen, dass ein OPSI-Rechner-Eintrag kopiert.3 # Skript, dass ein OPSI-Rechner-Eintrag kopiert. 4 4 # D.h. die Produkte, Anforderung. 5 5 # Ggf. optional Stand und ggf. Versionsnummer 6 6 # Ggf. optional ProductProperties 7 7 8 9 10 11 12 13 14 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 15 16 16 import argparse … … 32 32 print self.urlJsonRpc 33 33 print self.rpc.getClientIds_list() 34 35 def list(self): 36 return self.rpc.getClientIds_list() 37 38 def exists(self, src): 39 return len( self.rpc.host_getObjects( [], {"id":src} ) ) == 1 40 41 def info(self, src): 42 if not self.exists( src ): 43 print "failed: opsi client", src, "does not exist" 44 return False 45 print src + ":" 46 products = self.getProductOnClient( src, [] ) 47 for i in products: 48 print i['productId'] + ": (", i['actionRequest'], i['actionProgress'], ")", i['installationStatus'] 49 pprint( i, indent=4 ) 50 return True 51 52 def clean(self, src): 53 if not self.exists( src ): 54 return False 55 products = self.rpc.productOnClient_getObjects( [], { 'clientId': src } ) 56 self.rpc.productOnClient_deleteObjects( products ) 57 if self.debug: 58 pprint( self.getProductOnClient( src ) ) 59 return True 34 60 35 61 def copyClient( self, src, dst, ipAddress = None, hardwareAddress = None, depot = None ): … … 45 71 self.rpc.configState_create( "clientconfig.depot.id", dst, depot ) 46 72 if self.debug: 47 self.productOnClient( src)73 pprint( self.getProductOnClient( src ) ) 48 74 self.copyProductOnClient( src, dst ) 49 75 # TODO: … … 53 79 54 80 55 def productOnClient( self, client, attributes = ProductAttributesCopy ):81 def getProductOnClient( self, client, attributes = ProductAttributesCopy ): 56 82 #pprint( self.rpc.productOnClient_getObjects( [], { 'clientId': client } ) ) 57 83 #pprint( self.rpc.productOnClient_getHashes( attributes, { 'clientId': client } ) ) 58 pprint( self.rpc.productOnClient_getHashes( [], { 'clientId': client } ))84 return self.rpc.productOnClient_getHashes( [], { 'clientId': client } ) 59 85 60 86 def copyProductOnClient( self, src, dst, attributes = ProductAttributesCopy ): … … 62 88 for i in products: 63 89 if self.debug: 90 print i['productId'] 64 91 pprint( i ) 65 print i['productId']66 92 i['clientId'] = dst 67 93 self.rpc.productOnClient_createObjects( i ) 68 69 self.productOnClient( dst)94 if self.debug: 95 pprint( self.getProductOnClient( dst ) ) 70 96 71 97 … … 86 112 parser_exists = subparsers.add_parser('exists', help='check, if a opsi clients exists' ) 87 113 parser_exists.add_argument( 'src', help="source opsi client" ) 88 114 115 parser_info = subparsers.add_parser('info', help='print information about a opsi client' ) 116 parser_info.add_argument( 'src', help="opsi client" ) 117 89 118 parser_clean = subparsers.add_parser('clean', help='remove all product states from a opsi client' ) 90 119 parser_clean.add_argument( 'src', help="source opsi client to clean" ) … … 96 125 parser_copy.add_argument( '--mac', help="MAC address of the new opsi client" ) 97 126 parser_copy.add_argument( '--depot', help="depot server the new opsi client should be located" ) 98 99 #>>> parser_bar.set_defaults(func=bar)100 #>>> # parse the args and call whatever function was selected101 #>>> args = parser.parse_args('bar XYZYX'.split())102 #>>> args.func(args)103 104 127 105 128 args = parser.parse_args() … … 112 135 opsi=OpsiRpc( urlJsonRpc, args.debug ) 113 136 114 if args.subcommand == "copy": 137 result = True 138 139 if args.subcommand == "list": 140 print( "\n".join( opsi.list() ) ) 141 elif args.subcommand == "exists": 142 result = opsi.exists( args.src ) 143 elif args.subcommand == "info": 144 result = opsi.info( args.src ) 145 elif args.subcommand == "clean": 146 result = opsi.clean( args.src ) 147 elif args.subcommand == "copy": 115 148 opsi.copyClient( args.src, args.dst, args.ip, args.mac, args.depot ) 116 149 else: 117 150 print "not yet implemented" 118 151 119 if args.debug: print "end" 120 152 if args.debug: print result 153 154 if result: 155 exit(0) 156 else: 157 exit(1)
Note:
See TracChangeset
for help on using the changeset viewer.