Auto setup some products on opsi-client-agent install
Auto setup some products on opsi-client-agent install
Hello,
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
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
- n.wenselowski
- Ex-uib-Team
- Beiträge: 3194
- Registriert: 04 Apr 2013, 12:15
Re: Auto setup some products on opsi-client-agent install
Hello,
currently not.
Should be not that hard to realise. The implementation depends on the way you deploy the agent to those clients.
With kind regards
Niko
currently not.
Should be not that hard to realise. The implementation depends on the way you deploy the agent to those clients.
With kind regards
Niko
Code: Alles auswählen
import OPSI
Re: Auto setup some products on opsi-client-agent install
The thing is: sometimes branch offices add some computers to OPSI themselves (by running service_setup.cmd).. They can install client agent, but do not have access to configed (because it lacks per user group permissions support).. Some OPSI products should be installed on all computers so it would be really nice if adding new client to OPSI could trigger setup for those products.
The main question is, what's the best way of catching event of client's addition?
Thank you in advance
The main question is, what's the best way of catching event of client's addition?
Thank you in advance
- n.wenselowski
- Ex-uib-Team
- Beiträge: 3194
- Registriert: 04 Apr 2013, 12:15
Re: Auto setup some products on opsi-client-agent install
Hello,
my approach would be the use of a backend extension to customize host_insertObject.
No need to work with external scripts, works regardless of the way clients are added.
With kind regards
Niko
my approach would be the use of a backend extension to customize host_insertObject.
No need to work with external scripts, works regardless of the way clients are added.
With kind regards
Niko
Code: Alles auswählen
import OPSI
Re: Auto setup some products on opsi-client-agent install
Thank you for idea!
It works when I edit host_insertObject method in /usr/share/pyshared/OPSI/Backend/File.py but I do not really know how to override it in
(for example) /etc/opsi/backendManager/extend.d/80_custom.conf
Could you please give me a hint?
It works when I edit host_insertObject method in /usr/share/pyshared/OPSI/Backend/File.py but I do not really know how to override it in
(for example) /etc/opsi/backendManager/extend.d/80_custom.conf
Could you please give me a hint?
- n.wenselowski
- Ex-uib-Team
- Beiträge: 3194
- Registriert: 04 Apr 2013, 12:15
Re: Auto setup some products on opsi-client-agent install
Hello,
I'd suggest looking at the other .conf-files how the backend is accessed there (hint: self == BackendManager).
Everything in there is Python code that is loaded onto the BackendManager.
With kind regards
Niko
I'd suggest looking at the other .conf-files how the backend is accessed there (hint: self == BackendManager).
Everything in there is Python code that is loaded onto the BackendManager.
With kind regards
Niko
Code: Alles auswählen
import OPSI
Re: Auto setup some products on opsi-client-agent install
I have looked into those other .conf files before writing here, it does not help
The thing is, I can not override host_insertObject method..
my /etc/opsi/backendManager/extend.d/80_custom.conf
In opsiconfd.log I see logger.debug(vars(self)):
'host_insertObject': <bound method BackendExtender.my_host_insertObject of <OPSI.Backend.BackendManager.BackendExtender instance at 0x9d3fa4c>>
But when I am creating new client, in opsiconfd/127.0.0.1.log I see:
Dispatching method 'host_insertObject' to backends: [u'file', u'opsipxeconfd', u'dhcpd'] (BackendManager.py|406)
and host_insertObject from File.py is executed...
No logs with "I was here.." (I can see „I was here..“ only after opsiconfd restart if I call self.host_insertObject directly from 80_custom.conf..)
Have to dive deeper into OPSI code..
The thing is, I can not override host_insertObject method..
my /etc/opsi/backendManager/extend.d/80_custom.conf
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))
'host_insertObject': <bound method BackendExtender.my_host_insertObject of <OPSI.Backend.BackendManager.BackendExtender instance at 0x9d3fa4c>>
But when I am creating new client, in opsiconfd/127.0.0.1.log I see:
Dispatching method 'host_insertObject' to backends: [u'file', u'opsipxeconfd', u'dhcpd'] (BackendManager.py|406)
and host_insertObject from File.py is executed...
No logs with "I was here.." (I can see „I was here..“ only after opsiconfd restart if I call self.host_insertObject directly from 80_custom.conf..)
Have to dive deeper into OPSI code..
- n.wenselowski
- Ex-uib-Team
- Beiträge: 3194
- Registriert: 04 Apr 2013, 12:15
Re: Auto setup some products on opsi-client-agent install
Hello mirkt,
TBH I'd have to look for myself about the details of it.
Keyword to search for is dispatch.
With kind regards
Niko
TBH I'd have to look for myself about the details of it.
Keyword to search for is dispatch.
With kind regards
Niko
Code: Alles auswählen
import OPSI
Re: Auto setup some products on opsi-client-agent install
Thanks for all the hints I still don't know how to implement wanted functionality in /etc/opsi/backendManager/extend.d, but I have a working solution which does what I need (on one depot).. If anyone is interested:
1. create /etc/opsi/backends/action.conf
2. Edit /etc/opsi/backendManager/dispatch.conf
(add action)
3. Add file OPSI/Backend/Action.py into your systems python packages path OR add it somewhere (ex. /etc/opsi-helpers/modules) and add that directory to system's PYTHONPATH (ex. export PYTHONPATH=$PYTHONPATH:/etc/opsi-helpers/modules/) env. variables..
4. Add product group named "required") with some products, restart opsiconfd, add new client..
[7] [May 18 13:57:27] Auto install products: adobe.reader, adobe.flash, audacity, eraser, oracle.java, mozilla.firefox for new host test.local.lan (Action.py|97)
There must be a better way than calling backend (with all methods) via JSONRPC on the same host, but I don't really know how
1. create /etc/opsi/backends/action.conf
Code: Alles auswählen
# -*- coding: utf-8 -*-
module = 'Action'
config = {
'autoSetupProductGroup' : u"required"
}
Code: Alles auswählen
host_.* : .., action, ..
3. Add file OPSI/Backend/Action.py into your systems python packages path OR add it somewhere (ex. /etc/opsi-helpers/modules) and add that directory to system's PYTHONPATH (ex. export PYTHONPATH=$PYTHONPATH:/etc/opsi-helpers/modules/) env. variables..
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))
[7] [May 18 13:57:27] Auto install products: adobe.reader, adobe.flash, audacity, eraser, oracle.java, mozilla.firefox for new host test.local.lan (Action.py|97)
There must be a better way than calling backend (with all methods) via JSONRPC on the same host, but I don't really know how
- SisterOfMercy
- Beiträge: 1556
- Registriert: 22 Jun 2012, 19:18
Re: Auto setup some products on opsi-client-agent install
Uhhh, this was a bit too much work for me. I took a different route:
Then I edit the control file, \\opsi\opsi_workbench\opsi-client-agent\OPSI\control and add something like this:
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
Bitte schreiben Sie Deutsch, when I'm responding in the German-speaking part of the forum!