| Trees | Indices | Help |
|
|---|
|
|
1 ###########################################################################
2 #
3 # This program is part of Zenoss Core, an open source monitoring platform.
4 # Copyright (C) 2007, 2009 Zenoss Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License version 2 as published by
8 # the Free Software Foundation.
9 #
10 # For complete information please visit: http://www.zenoss.com/oss/
11 #
12 ###########################################################################
13
14 __doc__="""ManufacturerRoot
15
16 The Manufacturer classification class. default identifiers and screens,
17 live here.
18
19 $Id: ManufacturerRoot.py,v 1.10 2004/04/22 02:14:12 edahl Exp $"""
20
21 __version__ = "$Revision: 1.10 $"[11:-2]
22
23 import logging
24 log = logging.getLogger('zen')
25
26 import transaction
27
28 from Globals import InitializeClass
29 from Acquisition import aq_base
30 from AccessControl import Permissions as permissions
31 from Products.ZenModel.ZenossSecurity import *
32
33 from Products.ZenRelations.PrimaryPathObjectManager import \
34 PrimaryPathBTreeFolder2
35
36 from ZenModelItem import ZenModelItem
37 from ZenPacker import ZenPacker
38 from Products.ZenUtils.Search import \
39 makeCaseSensitiveKeywordIndex, makeCaseInsensitiveFieldIndex
40 from Products.ManagableIndex import FieldIndex
41
43 """make a Manufacturer class"""
44 m = ManufacturerRoot()
45 context._setObject(m.getId(), m)
46 m = context._getOb(m.dmdRootName)
47 if REQUEST is not None:
48 REQUEST['RESPONSE'].redirect(context.absolute_url() + '/manage_main')
49
50
51 #addManufacturerRoot = DTMLFile('dtml/addManufacturerRoot',globals())
52
53
55 """
56 The root organizer for manufacturers. May become a BtreeFolder2 at
57 some point (to scale better). Has interface to manage Manufacturers
58 and the products that they create.
59 """
60 dmdRootName = "Manufacturers"
61 meta_type = "ManufacturerRoot"
62 sub_classes = ('Manufacturer',)
63 default_catalog = "productSearch"
64
65 # Screen action bindings (and tab definitions)
66 factory_type_information = (
67 {
68 'id' : 'Manufacturer',
69 'meta_type' : 'Manufacturer',
70 'description' : """Arbitrary device grouping class""",
71 'icon' : 'Manufacturer_icon.gif',
72 'product' : 'ZenModel',
73 'factory' : 'manage_addManufacturer',
74 'immediate_view' : 'viewManufacturers',
75 'actions' :
76 (
77 { 'id' : 'overview'
78 , 'name' : 'Overview'
79 , 'action' : 'viewManufacturers'
80 , 'permissions' : (
81 permissions.view, )
82 },
83 { 'id' : 'viewHistory'
84 , 'name' : 'Modifications'
85 , 'action' : 'viewHistory'
86 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,)
87 },
88 )
89 },
90 )
91
92
94 if not id: id = self.dmdRootName
95 super(ManufacturerRoot, self).__init__(id)
96 PrimaryPathBTreeFolder2.__init__(self, id)
97 self.createCatalog()
98 self.buildzProperties()
99
100
102 """Add a manufacturer from UI code.
103 """
104 if manufacturerName:
105 self.createManufacturer(manufacturerName)
106 if REQUEST: return self.callZenScreen(REQUEST)
107
108
110 """Delete a list of manufacturers from UI.
111 """
112 if not ids: return self.callZenScreen(REQUEST)
113 for id in ids: self._delObject(id)
114 if REQUEST: return self.callZenScreen(REQUEST)
115
116
118 """Return and create if nessesary manufacturerName.
119 """
120 from Products.ZenModel.Manufacturer import manage_addManufacturer
121 if manufacturerName and not self.has_key(manufacturerName):
122 logging.info("Creating Manufacturer %s" % manufacturerName)
123 manage_addManufacturer(self, manufacturerName)
124 if manufacturerName:
125 return self._getOb(manufacturerName)
126 return None
127
128
130 """
131 Return manufacturerName. If it doesn't exist, create it.
132 """
133 manufacturerName = self.prepId(manufacturerName)
134 if self.has_key(manufacturerName):
135 return self._getOb(manufacturerName)
136 else:
137 for m in self.objectValues(spec="Manufacturer"):
138 if m.matches(manufacturerName):
139 return m
140
141 return self.createManufacturer(manufacturerName)
142
143
147
148
150 """return a list of all products this Manufacturer makes"""
151 productFilter = dict(getManufacturerName=mname)
152 if type == "OS":
153 productFilter['meta_type'] = "SoftwareClass"
154 productFilter['isOS'] = True
155 elif type:
156 productFilter['meta_type'] = type
157
158 cat = getattr(self, self.default_catalog)
159 return sorted([''] + [ entry.id for entry in cat(productFilter) ])
160
161
163 """Find a product by is productKey.
164 """
165 cat = getattr(self, self.default_catalog)
166 brains = cat({'productKeys': query})
167 if not brains: return None
168 try:
169 return self.getObjByPath(brains[0].getPrimaryId)
170 except KeyError:
171 log.warn("bad path '%s' index '%s'",
172 brains[0].getPrimaryId, self.default_catalog)
173
174
176 """Return and create if nessesary a HardwareClass object.
177 """
178 from Products.ZenModel.HardwareClass import HardwareClass
179 return self._getProduct(prodName, manufacturer, HardwareClass, **kwargs)
180
181
183 """Return and create if nesseary a SoftwareClass object.
184 """
185 from Products.ZenModel.SoftwareClass import SoftwareClass
186 prod = self._getProduct(prodName, manufacturer, SoftwareClass, **kwargs)
187 prod.isOS = isOS
188 return prod
189
190
192 prod = self.findProduct(prodName)
193 if prod:
194 # Product already exists. Return it.
195 return prod
196
197 # Product doesn't already exist. Create it.
198 prodid = self.prepId(prodName)
199 manufobj = self.getManufacturer(manufacturer)
200 prod = manufobj.products._getOb(prodid, None)
201 if prod is None:
202 prod = factory(prodid, prodName=prodName, **kwargs)
203 manufobj.products._setObject(prodid, prod)
204 prod = manufobj.products._getOb(prodid)
205 return prod
206
207
209 """Return a generator that gets all products.
210 """
211 for manuf in self.values(spec="Manufacturer"):
212 for prod in manuf.products.objectValuesGen():
213 yield prod
214
215
217 """Go through all devices in this tree and reindex them."""
218 zcat = self._getOb(self.default_catalog)
219 zcat.manage_catalogClear()
220 transaction.savepoint()
221 for i, prod in enumerate(self.getProductsGen()):
222 prod.index_object()
223 if not i % 1000: transaction.savepoint()
224
225
227 """Create a catalog for EventClassRecord searching"""
228 from Products.ZCatalog.ZCatalog import manage_addZCatalog
229
230 # XXX update to use ManagableIndex
231 manage_addZCatalog(self, self.default_catalog, self.default_catalog)
232 zcat = self._getOb(self.default_catalog)
233 cat = zcat._catalog
234 cat.addIndex('productKeys',
235 makeCaseSensitiveKeywordIndex('productKeys'))
236 cat.addIndex('meta_type',
237 makeCaseInsensitiveFieldIndex('meta_type'))
238 cat.addIndex('getManufacturerName',
239 makeCaseInsensitiveFieldIndex('getManufacturerName'))
240 cat.addIndex('isOS', FieldIndex('isOS'))
241 zcat.addColumn('getPrimaryId')
242 zcat.addColumn('id')
243
244
246 """Return an xml based representation of a RelationshipManager
247 <object id='/Devices/Servers/Windows/dhcp160.confmon.loc'
248 module='Products.Confmon.IpInterface' class='IpInterface'>
249 <property id='name'>jim</property>
250 <toone></toone>
251 <tomany></tomany>
252 <tomanycont></tomanycont>
253 </object>
254 """
255 modname = self.__class__.__module__
256 classname = self.__class__.__name__
257 id = root and self.getPrimaryId() or self.id
258 stag = "<object id='%s' module='%s' class='%s'>\n" % (
259 id , modname, classname)
260 ofile.write(stag)
261 for obj in self.objectValues():
262 if getattr(aq_base(obj), 'exportXml', False):
263 obj.exportXml(ofile, ignorerels)
264 ofile.write("</object>\n")
265
266
268 if getattr(aq_base(self), "zDeviceClass", False): return
269 self._setProperty("zDeviceClass", "")
270 self._setProperty("zDeviceGroup", "")
271 self._setProperty("zSystem", "")
272
273
274 InitializeClass(ManufacturerRoot)
275
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Mon Oct 19 14:44:17 2009 | http://epydoc.sourceforge.net |