Skip to content

Commit

Permalink
Merge branch 'release/1.0.13'
Browse files Browse the repository at this point in the history
  • Loading branch information
eedgar committed Sep 4, 2013
2 parents 210659d + d6c363a commit a45c7e2
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 25 deletions.
19 changes: 18 additions & 1 deletion docs/jsonformat.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Json Options for a ZenPack::
"organizers": [],
"zProperties": [],
"deviceClasses": [],
"relationships": []
"relationships": [].
"discoveryMappings": []
}

* id: A string defining the unique name of your Zenpack. [required]
Expand All @@ -39,6 +40,7 @@ Json Options for a ZenPack::
* zproperties: An Array of :ref:`zproperty` elements. [optional]
* deviceClasses: An Array of :ref:`deviceClass` elements. [optional]
* relationships: An Array of :ref:`relationship` elements. [optional]
* discoveryMappings: An Array of :ref:`discoveryMapping` elements. [optional]
* organizers: An Array of :ref:`organizer` elements. [optional]

.. _zproperties:
Expand Down Expand Up @@ -258,6 +260,21 @@ Json Options for a DeviceType::
* impactedBy: An Array of components that this component is impactedBy.
* The component can be in :ref:`shorthand` notation.

.. _discoveryMapping:

discoveryMapping {}
-------------------

Json Options for a DiscoveryMapping::

"discoveryMappings": [{
"oid": '1.3.6.1.5',
"deviceClass": 'Network/Switch/Cisco/Foo'
}]

* oid: a devices SnmpOid to match
* deviceClass: The destination device Class

.. _properties:

properties []
Expand Down
9 changes: 9 additions & 0 deletions examples/autoclassification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"deviceClasses": [ { "path": "Device" } ],
"discoveryMappings": [
{ "oid": "1.2.3.4.5",
"deviceClass": "Network/Example"},
{ "oid": "1.2.3.4.5.6",
"deviceClass": "Network/Example"}],
"id": "ZenPacks.training.AutoClassification"
}
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
'Mock',
'nose',
'pep8',
'argparse'
]


Expand Down
44 changes: 44 additions & 0 deletions zpg/AutoClassificationZcml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python
##############################################################################
#
# Copyright (C) Zenoss, Inc. 2013, all rights reserved.
#
# This content is made available according to terms specified in the LICENSE
# file at the top-level directory of this package.
#
##############################################################################

from ._defaults import Defaults
from ._zenoss_utils import KlassExpand, zpDir
from .Template import Template
defaults = Defaults()


class AutoClassificationZcml(Template):
"""Build the autoclassification.zcml file"""

def __init__(self,
zenpack,
):
'''Args:
zenpack: ZenPack class instance
'''

super(AutoClassificationZcml, self).__init__(zenpack)
self.source_template = 'autoclassification.zcml.tmpl'
self.zenpack = zenpack
self.components = zenpack.components

self.dest_file = "%s/autoclassification.zcml" % zpDir(zenpack)

def discoveryMappings(self):
if self.zenpack.discoveryMappings:
return True
return False

def write(self):
'''Write the file'''

if self.discoveryMappings():
self.processTemplate()
33 changes: 21 additions & 12 deletions zpg/Component.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,13 @@ def displayInfo(self):
imports = "from Products.Zuul.infos.device import DeviceInfo"
else:
imports = "from Products.Zuul.infos.component import ComponentInfo"
if self.properties:
self.imports.append(imports)
return True
if self.ManyRelationships():
self.imports.append(imports)
return True
if self.componentInZenPackNameSpace():
if self.properties:
self.imports.append(imports)
return True
if self.ManyRelationships():
self.imports.append(imports)
return True
return False

def displayIInfo(self):
Expand All @@ -327,13 +328,14 @@ def displayIInfo(self):
imports = "from %s import IDeviceInfo" % name
else:
imports = "from %s.component import IComponentInfo" % name
for p in self.properties.values():
if p.detailDisplay:
if self.componentInZenPackNameSpace():
for p in self.properties.values():
if p.detailDisplay:
self.imports.append(imports)
return True
if self.ManyRelationships():
self.imports.append(imports)
return True
if self.ManyRelationships():
self.imports.append(imports)
return True
return False

@classmethod
Expand Down Expand Up @@ -445,9 +447,16 @@ def impactSingle(self, impactee):
return True
return False

def componentInZenPackNameSpace(self):
'return true if the component id startswith the zenpack id'
return self.id.startswith(self.zenpack.id)

def write(self):
"""Write the component files"""
self.updateImports()
self.findUpdateComponents()
self.convertImpactStringsToRealComponents()
self.processTemplate()

# Only write components that are prefixed in this zenpacks namespace.
if self.componentInZenPackNameSpace():
self.processTemplate()
5 changes: 3 additions & 2 deletions zpg/ComponentJS.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def __init__(self, deviceClass):
self.deviceClass = deviceClass
self.zenpack = self.deviceClass.zenpack
self.zPythonClass = self.deviceClass.zPythonClass
self.ConfigureComponent = "%s.%s" % (
self.zPythonClass, self.zPythonClass.split('.')[-1])
self.ConfigureComponent = self.zPythonClass
#self.ConfigureComponent = "%s.%s" % (
# self.zPythonClass, self.zPythonClass.split('.')[-1])

self.source_template = 'component.js.tmpl'
self.dest_file = "%s/resources/js/%s.js" % (
Expand Down
5 changes: 5 additions & 0 deletions zpg/Configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def impactAdapters(self):
return True
return False

def discoveryMappings(self):
if self.zenpack.discoveryMappings:
return True
return False

# TODO
# Router and facade
# custom device loaders
Expand Down
46 changes: 46 additions & 0 deletions zpg/DiscoveryMapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python
#
#
# Copyright (C) Zenoss, Inc. 2013, all rights reserved.
#
# This content is made available according to terms specified in the LICENSE
# file at the top-level directory of this package.
#
#

from .colors import error, warn, debug, info, green, red, yellow


class DiscoveryMapping(object):
''' Discovery Mapping Object '''

discoveryMappings = {}

def __init__(self,
zenpack,
oid,
deviceClass,
*args,
**kwargs
):
"""Args:
zenpack: the containing zenpack
oid: a devices snmpoid to match
deviceClass: destination device class to move the
discovered device
"""
self.zenpack = zenpack
self.oid = oid
self.deviceClass = deviceClass

for key in kwargs:
do_not_warn = False
clsname = self.__class__.__name__
layer = "%s:%s" % (clsname, self.name)
msg = "WARNING: [%s] unknown keyword ignored in file: '%s'"
margs = (layer, key)
if not do_not_warn:
warn(self.logger, yellow(msg) % margs)

DiscoveryMapping.discoveryMappings[self.oid] = self
self.zenpack.registerDiscoveryMapping(self)
11 changes: 10 additions & 1 deletion zpg/ImpactPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,17 @@ def updateImports(self):
if istring not in self.imports:
self.imports.append(istring)

def impactAdapters(self):
'''Return true if there are any impact relationships'''
for c in self.components.values():
if c.hasImpact():
return True
return False

def write(self):
'''Write the impact file'''

self.updateImports()
self.processTemplate()

if self.impactAdapters():
self.processTemplate()
10 changes: 9 additions & 1 deletion zpg/ImpactZcml.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,16 @@ def __init__(self,

self.dest_file = "%s/impact.zcml" % zpDir(zenpack)

def impactAdapters(self):
'''Return true if there are any impact relationships'''
for c in self.components.values():
if c.hasImpact():
return True
return False

def write(self):
'''Write the impact file'''

#self.updateImports()
self.processTemplate()
if self.impactAdapters():
self.processTemplate()
28 changes: 28 additions & 0 deletions zpg/Templates/autoclassification.zcml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
##############################################################################
#
# Copyright (C) Zenoss, Inc. 2012, all rights reserved.
#
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
#
##############################################################################
-->

<configure xmlns="http://namespaces.zope.org/zope">

<!-- Import discovery mapping directives. -->
<include package="ZenPacks.zenoss.DiscoveryMapping" file="meta.zcml"/>

#for $discoveryMapping in $zenpack.discoveryMappings.values
<discoveryMapping
oid="$discoveryMapping.oid"
deviceClass="$discoveryMapping.deviceClass"
/>

#end for
</configure>



7 changes: 7 additions & 0 deletions zpg/Templates/configure.zcml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@
-->

#end if
#if $discoveryMappings
<include
file="autoclassification.zcml"
xmlns:zcml="http://namespaces.zope.org/zcml"
zcml:condition="installed ZenPacks.zenoss.DiscoveryMapping"
/>
#end if
</configure>
Loading

0 comments on commit a45c7e2

Please sign in to comment.