Permalink
Browse files

Remove RabbitMQ components on ZenPack removal.

Fixes #7.
  • Loading branch information...
1 parent 76fd151 commit f94bd958ec1f1203de14980056bde470272ced0e @cluther cluther committed Jun 29, 2012
Showing with 16 additions and 1 deletion.
  1. +16 −1 ZenPacks/zenoss/RabbitMQ/__init__.py
@@ -26,6 +26,7 @@
from Products.ZenModel.ZenPack import ZenPack as ZenPackBase
from Products.ZenRelations.RelSchema import ToManyCont, ToOne
from Products.ZenUtils.Utils import unused
+from Products.Zuul.interfaces import ICatalogTool
unused(Globals)
@@ -37,6 +38,10 @@
('rabbitmq_nodes', 'RabbitMQNode'),
)
+NEW_COMPONENT_TYPES = (
+ 'ZenPacks.zenoss.RabbitMQ.RabbitMQNode.RabbitMQNode',
+ )
+
# Add new relationships to Device if they don't already exist.
for relname, modname in NEW_DEVICE_RELATIONS:
if relname not in (x[0] for x in Device._relations):
@@ -54,6 +59,8 @@ class ZenPack(ZenPackBase):
def install(self, app):
self.pre_install(app)
super(ZenPack, self).install(app)
+
+ log.info('Adding RabbitMQ relationships to existing devices')
self._buildDeviceRelations()
def pre_install(self, app):
@@ -71,15 +78,23 @@ def pre_install(self, app):
def remove(self, app, leaveObjects=False):
if not leaveObjects:
+ log.info('Removing RabbitMQ components')
+ cat = ICatalogTool(app.zport.dmd)
+ for brain in cat.search(types=NEW_COMPONENT_TYPES):
+ component = brain.getObject()
+ component.getPrimaryParent()._delObject(component.id)
+
# Remove our Device relations additions.
Device._relations = tuple(
[x for x in Device._relations \
if x[0] not in NEW_DEVICE_RELATIONS])
+ log.info('Removing RabbitMQ device relationships')
self._buildDeviceRelations()
+ super(ZenPack, self).remove(app, leaveObjects=leaveObjects)
+
def _buildDeviceRelations(self):
- log.info("Rebuilding relations for existing devices")
for d in self.dmd.Devices.getSubDevicesGen():
d.buildRelations()

0 comments on commit f94bd95

Please sign in to comment.