source: opsi/server/dass-opsi-tools/usr/bin/opsi-client.py @ 1049

Last change on this file since 1049 was 1049, checked in by joergs, 9 years ago

renamed

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1#!/usr/bin/env python
2
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
7
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                       
16import argparse
17import jsonrpc
18from pprint import pprint
19
20UrlJsonRpc="https://joergs:linuxlinux@opsi4.joergs.dass-it:4447/rpc"
21
22class OpsiRpc:
23   
24    ProductAttributesCopy = ['actionRequest','actionResult','installationStatus','packageVersion','productVersion']
25   
26    def __init__(self, urlJsonRpc, debug=False ):
27        self.debug=debug
28        self.urlJsonRpc=urlJsonRpc
29        self.rpc=jsonrpc.ServiceProxy(self.urlJsonRpc)
30       
31    def dump(self):
32        print self.urlJsonRpc
33        print self.rpc.getClientIds_list()
34       
35    def copyClient( self, src, dst, ipAddress = None, hardwareAddress = None, depot = None ):
36   
37        print "create/update", dst, "from template", src + ":",
38        #method host_createOpsiClient id *opsiHostKey *description *notes *hardwareAddress *ipAddress *inventoryNumber *oneTimePassword *created *lastSeen
39        #id=dst
40        opsiHostKey=None
41        description=""
42        notes="copy of " + src
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
54       
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       
71
72
73if __name__ == '__main__':
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()
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 TracBrowser for help on using the repository browser.