I would like to ask you, is there an easy way to auto setup some products (from specified product group) on client-agent-install?
Thanks in advance

Code: Alles auswählen
import OPSI
Code: Alles auswählen
import OPSI
Code: Alles auswählen
import OPSI
Code: Alles auswählen
# -*- coding: utf-8 -*-
def my_host_insertObject(self, host):
logger.debug("I was here..")
delattr(self, 'host_insertObject')
setattr(self, 'host_insertObject', new.instancemethod(my_host_insertObject, self, self.__class__))
logger.debug(vars(self))
Code: Alles auswählen
import OPSI
Code: Alles auswählen
# -*- coding: utf-8 -*-
module = 'Action'
config = {
'autoSetupProductGroup' : u"required"
}
Code: Alles auswählen
host_.* : .., action, ..
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: utf-8 -*-
import socket
import threading
import os
from OPSI.Logger import Logger
from OPSI.Types import forceHostId
from OPSI.Object import *
from OPSI import System
from OPSI.Backend.Backend import *
from OPSI.Backend.JSONRPC import JSONRPCBackend
from OPSI.Util import getfqdn
logger = Logger()
class ActionBackend(ConfigDataBackend):
def __init__(self, **kwargs):
self._name = 'action'
ConfigDataBackend.__init__(self, **kwargs)
self._depotConnection = None
self._depotId = forceHostId(getfqdn(conf=OPSI_GLOBAL_CONF))
self._opsiHostKey = None
self._autoSetupProductGroup = u'required'
for (option, value) in kwargs.items():
if option in ('autoSetupProductGroup',):
self._autoSetupProductGroup = str(value)
def _getDepotConnection(self):
if self._depotConnection:
return self._depotConnection
if not self._opsiHostKey:
depots = self._context.host_getObjects(id=self._depotId)
if not depots or not depots[0].getOpsiHostKey():
raise BackendMissingDataError(u"Failed to get opsi host key for depot '{0}'".format(self._depotId))
self._opsiHostKey = depots[0].getOpsiHostKey()
try:
self._depotConnection = JSONRPCBackend(
address=self._depotId,
username=self._depotId,
password=self._opsiHostKey
)
except Exception as error:
raise Exception(u"Failed to connect to depot '%s': %s" % (self._depotId, error))
return self._depotConnection
def host_insertObject(self, host):
if not isinstance(host, OpsiClient):
return
productsToInstall = []
objects = self._getDepotConnection().objectToGroup_getObjects(groupId = self._autoSetupProductGroup, groupType = 'ProductGroup')
if objects:
for object in objects:
self._getDepotConnection().setProductActionRequest(object.objectId, host.id, 'setup')
productsToInstall.append(object.objectId)
logger.debug(u"Auto install products: %s for new host %s" % (", ".join(productsToInstall), host.id))
Code: Alles auswählen
cd /home/opsiproducts
opsi-package-manager -x /var/lib/opsi/repository/opsi-client-agent_4.0.5.4-5.opsi
opsi-setup --set-rights ./opsi-client-agent/
Code: Alles auswählen
[ProductDependency]
action: setup
requiredProduct: java-runtime
requiredAction: setup
requirementType: after