Obtaining a dmd object in a ZenPack init file top level

6 posts / 0 new
Last post
Pheripheral
Pheripheral's picture
Offline
Last seen: 1 day 11 hours ago
Joined: 09/02/2015 - 04:52
Posts: 24
Obtaining a dmd object in a ZenPack init file top level

Hi,

I’m attempting to develop a ZenPack to carry out some data loading from a config file and push it into zenoss via direct dmd manipulation. This is on Zenoss 4.2.5

I’ve got this working when driven by independent user actions in the GUI (via some new menu additions) and when called from inside the ZenPack class in the init file of the ZenPack.

However, I’d also like this to be run from the top level of the init file, so that the config is picked up whenever zenoss is restarted.

When run from inside the zenpack class I can grab a dmd object via app.zport.dmd as the app is passed into the install method.

What I’m having a problem with is obtaining a dmd object to pass to my code from this top level of the init file.

 Can anyone suggest a way this can be done from here?

Jstanley
Jstanley's picture
Offline
Last seen: 6 hours 3 min ago
Joined: 07/10/2014 - 09:31
Posts: 213
What are you trying to load?

What are you trying to load? I assume the config file can be changed and that is why you need to load it each time? What are you using this data for within Zenoss?

 

Just trying to get an idea of what you are trying to accomplish, so I can help accordingly.

 

Pheripheral
Pheripheral's picture
Offline
Last seen: 1 day 11 hours ago
Joined: 09/02/2015 - 04:52
Posts: 24
Yep, as the config file may

Yep, as the config file may change i want to be able to auto load ta new  config on a zenoss restart. I've got it reading a flag from the config regarding whether or not to reload a config on restart.

The config is loading in various aspects of the zenoss configuration - system settings, organiser tree hierarchy, device list, users data... and these are loaded in via calls to various methods on the facades etc. (e.g. dmd.ZenUsers.manage_addUser or deviceFacade.addDevice ...)

So hoping to find a method of grabbing a dmd object from within the top level of the init file to pass into the methods that then call the various addDevice etc... methods.

Thanks for replying!

 

 

Jstanley
Jstanley's picture
Offline
Last seen: 6 hours 3 min ago
Joined: 07/10/2014 - 09:31
Posts: 213
So, you are using an outside

So, you are using an outside config file that basically configures your Zenoss environment. And these settings can change from restart to restart?

 

Pheripheral
Pheripheral's picture
Offline
Last seen: 1 day 11 hours ago
Joined: 09/02/2015 - 04:52
Posts: 24
Yep that's pretty much what

Yep that's pretty much what we're trying to do, essentially be able to reconfigure zenoss from our config file on startup without a user having to get involved.

 

Thanks

Vsergeyev
Vsergeyev's picture
Offline
Last seen: 2 months 2 weeks ago
Joined: 01/21/2016 - 03:00
Posts: 4
Hi,

Hi,

Maybe this may help you:

https://github.com/zenoss/zenoss-prodbin/blob/8097e1fcdd73da3d0f73c1f2548997f49faf99cd/Products/ZenModel/zendmd.py#L204

It instantiates zope application and takes dmd from it.

app = Zope2.app()
...
zport = app.zport
dmd   = zport.dmd

Log in to post comments