#!/usr/bin/env python

# Skript erstellen, dass ein OPSI-Rechner-Eintrag kopiert.
# D.h. die Produkte, Anforderung.
# Ggf. optional Stand und ggf. Versionsnummer
# Ggf. optional ProductProperties

                #self.command("opsi-admin -d method host_createOpsiClient "+ \
                        #computername + " null " + "\\'"+description+"\\'" + \
                        #" \\'created by dassadmin\\' " + mac_address + " " + \
                        #ip_address)
                #method host_createOpsiClient id *opsiHostKey *description *notes *hardwareAddress *ipAddress *inventoryNumber *oneTimePassword *created *lastSeen
                #self.command("opsi-admin -d method configState_create clientconfig.depot.id " + \
                        #computername + " " + depotName)                        

import jsonrpc
from pprint import pprint

UrlJsonRpc="https://joergs:linuxlinux@opsi4.joergs.dass-it:4447/rpc"

class OpsiRpc:
    def __init__(self, urlJsonRpc=UrlJsonRpc):
        self.urlJsonRpc=urlJsonRpc
        self.rpcProxy=jsonrpc.ServiceProxy(self.urlJsonRpc)
        
    def dump(self):
        print self.urlJsonRpc
        print self.rpcProxy.getClientIds_list()
        
    def copyClient( self, src, dst, hardwareAddress, ipAddress ):
    
        #method host_createOpsiClient id *opsiHostKey *description *notes *hardwareAddress *ipAddress *inventoryNumber *oneTimePassword *created *lastSeen
        id=dst
        opsiHostKey=None
        description=""
        notes="copy of " + src
        self.rpcProxy.host_createOpsiClient( id, opsiHostKey, description, notes, hardwareAddress, ipAddress )
        
    def productOnClient( self, client ):
        pprint( self.rpcProxy.productOnClient_getObjects( [], { 'clientId': client } ) )



if __name__ == '__main__':
    opsi=OpsiRpc()
    #opsi.dump()
    opsi.copyClient( "test1.joergs.dass-it.opsi", "testnew1.joergs.dass-it.opsi", "00:00:00:00:01:01", "192.168.0.1" )
    opsi.productOnClient( "opsiwin1.joergs.dass-it.opsi" )
    opsi.dump()
    print "end"
    