Permalink
Browse files

Auto-bind OpenVZHost monitoring template.

  • Loading branch information...
1 parent 4289683 commit b5d4ead2029d8d6b4f2e2a5e418a0c7635865e12 @cluther cluther committed Jan 9, 2012
@@ -68,7 +68,29 @@ def openvz_getExpandedLinks(self):
links = '<a href="%s">OpenVZ Container %s on Host %s</a><br/>' % (host.getPrimaryUrlPath(), host.titleOrId(), host.device().titleOrId()) + links
return links
Device.getExpandedLinks = openvz_getExpandedLinks
-
+
+
+@monkeypatch('Products.ZenModel.Device.Device')
+def setOpenVZHostTemplate(self, enabled):
+ """Bind OpenVZHost monitoring template if enabled is true."""
+ templates = self.primaryAq().zDeviceTemplates
+
+ if enabled:
+ if 'OpenVZHost' not in templates:
+ templates.append('OpenVZHost')
+ self.setZenProperty('zDeviceTemplates', templates)
+ else:
+ if 'OpenVZHost' in templates:
+ templates.remove('OpenVZHost')
+ self.setZenProperty('zDeviceTemplates', templates)
+
+
+@monkeypatch('Products.ZenModel.Device.Device')
+def getOpenVZHostTemplate(self):
+ """Returns true if OpenVZHost monitoring template is bound."""
+ return 'OpenVZHost' in self.primaryAq().zDeviceTemplates
+
+
class ZenPack(ZenPackBase):
def install(self, app):
ZenPackBase.install(self, app)
@@ -64,7 +64,7 @@ def process(self, device, results, log):
pos += 1
arch = lines[pos]
pos += 1
- hostmap = ObjectMap({"page_size" : page_size, "arch" : arch }, compname="hw")
+ hw_map = ObjectMap({"page_size" : page_size, "arch" : arch }, compname="hw")
infolines = []
while lines[pos] != "#veinfo-stop":
infolines.append(lines[pos])
@@ -141,4 +141,11 @@ def process(self, device, results, log):
# an objectmap -
# a list of relmaps, objectmaps
- return [hostmap, rm]
+ # If we get here, we've identified this as an OpenVZ host. Create a new
+ # ObjectMap that will be applied to the device. Use it to call our
+ # setOpenVZHostTemplate method on the device to bind the host-level
+ # monitoring template.
+ device_map = ObjectMap()
+ device_map.setOpenVZHostTemplate = True
+
+ return [device_map, hw_map, rm]

0 comments on commit b5d4ead

Please sign in to comment.