Changeset 1088


Ignore:
Timestamp:
Aug 29, 2012, 7:24:39 PM (12 years ago)
Author:
joergs
Message:

copyProductPropertyState

File:
1 edited

Legend:

Unmodified
Added
Removed
  • opsi/server/dass-opsi-tools/usr/bin/opsiclient

    r1087 r1088  
    8585        products = self.rpc.productOnClient_getObjects( [], { 'clientId': src } )
    8686        self.rpc.productOnClient_deleteObjects( products )
     87
     88        products = self.rpc.productPropertyState_getObjects( [], { 'clientId': src } )
     89        self.rpc.productPropertyState_deleteObjects( products )
     90       
    8791        if self.debug:
    8892            pprint( self.getProductOnClient( src ) )
     
    9599        self.rpc.configState_create( "clientconfig.depot.id", name, depot )       
    96100
    97     def copyClient( self, src, dst, ipAddress = None, hardwareAddress = None, depot = None, description = "" ):
     101    def copyClient( self, src, dst, ipAddress = None, hardwareAddress = None, depot = None, description = "", copyProperties = True ):
    98102   
    99103        print "create/update", dst, "from template", src + ":",
     
    124128        #  copy product properties:
    125129        #  opsiCallClientBaculaProperties=[ "method", "getProductProperties_hash", "bacula" ]
     130        if copyProperties:
     131            if self.debug:
     132                print "copy product properties"
     133            self.copyProductPropertyState( src, dst )
    126134        print "done"
    127135        return True
     
    134142       
    135143    def copyProductOnClient( self, src, dst, attributes = ProductAttributesCopy ):
    136         products = self.rpc.productOnClient_getHashes( attributes, { 'clientId': src } )
    137         for i in products:
     144        products_src = self.rpc.productOnClient_getHashes( attributes, { 'clientId': src } )
     145        products_dst = []
     146        for i in products_src:
    138147            if self.debug:
    139148                print i['productId']
    140149                pprint( i )
    141150            i['clientId'] = dst
    142             self.rpc.productOnClient_createObjects( i )
     151            products_dst.append(i)
     152        self.rpc.productOnClient_createObjects( products_dst )
    143153        if self.debug:
    144154            pprint( self.getProductOnClient( dst ) )
     155
     156    def getProductPropertyState( self, client, attributes = [] ):
     157        return self.rpc.productPropertyState_getHashes( [], { 'objectId': client } )
     158                       
     159    def copyProductPropertyState( self, src, dst, attributes = [] ):
     160        productProperties_src = self.getProductPropertyState( src, attributes )
     161        productProperties_dst = []
     162        for i in productProperties_src:
     163            if self.debug:
     164                print i['productId'], "-", i["propertyId"] + ": ",
     165                pprint(i["values"])
     166                #pprint( i )
     167            i['objectId'] = dst
     168            productProperties_dst.append(i)
     169        self.rpc.productPropertyState_createObjects( productProperties_dst )
     170        if self.debug:
     171            pprint( self.getProductPropertyState( dst ) )
     172           
    145173       
    146174
     
    176204    parser_copy.add_argument( '--mac', help="MAC address of the new opsi client" )
    177205    parser_copy.add_argument( '--depot', help="depot server the new opsi client should be located" )
     206    #parser_copy.add_argument( '--no-properties', action='store_false', help="don't copy product properties" )
    178207   
    179208    args = parser.parse_args()
     
    192221        result = opsi.clean( args.src )
    193222    elif args.subcommand == "copy":
     223        #result = opsi.copyClient( args.src, args.dst, args.ip, args.mac, args.depot, not args.no-properties )
    194224        result = opsi.copyClient( args.src, args.dst, args.ip, args.mac, args.depot )
    195225    else:
Note: See TracChangeset for help on using the changeset viewer.