1
2
3
4
5
6
7
8
9
10
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
49
50
51
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
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
99
100
107
108
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 if self.has_key(manufacturerName):
134 man = self._getOb(manufacturerName)
135 else:
136 man = self.createManufacturer(manufacturerName)
137
138 return man
139
140
142 """return list of all companies"""
143 return self.objectIds(spec=("Manufacturer"))
144
145
147 """return a list of all products this Manufacturer makes"""
148 productFilter = dict(getManufacturerName=mname)
149 if type == "OS":
150 productFilter['meta_type'] = "SoftwareClass"
151 productFilter['isOS'] = True
152 elif type:
153 productFilter['meta_type'] = type
154
155 cat = getattr(self, self.default_catalog)
156 return sorted([''] + [ entry.id for entry in cat(productFilter) ])
157
158
170
171
177
178
186
187
188 - def _getProduct(self, prodName, manufacturer, factory, **kwargs):
189 prod = self.findProduct(prodName)
190 if prod:
191
192 return prod
193
194
195 prodid = self.prepId(prodName)
196 manufobj = self.getManufacturer(manufacturer)
197 prod = manufobj._getOb(prodid, None)
198 if prod is None:
199 prod = factory(prodid, prodName=prodName, **kwargs)
200 manufobj.products._setObject(prodid, prod)
201 prod = manufobj.products._getOb(prodid)
202 return prod
203
204
206 """Return a generator that gets all products.
207 """
208 for manuf in self.values(spec="Manufacturer"):
209 for prod in manuf.products.objectValuesGen():
210 yield prod
211
212
214 """Go through all devices in this tree and reindex them."""
215 zcat = self._getOb(self.default_catalog)
216 zcat.manage_catalogClear()
217 transaction.savepoint()
218 for i, prod in enumerate(self.getProductsGen()):
219 prod.index_object()
220 if not i % 1000: transaction.savepoint()
221
222
240
241
242 - def exportXml(self, ofile, ignorerels=[], root=False):
243 """Return an xml based representation of a RelationshipManager
244 <object id='/Devices/Servers/Windows/dhcp160.confmon.loc'
245 module='Products.Confmon.IpInterface' class='IpInterface'>
246 <property id='name'>jim</property>
247 <toone></toone>
248 <tomany></tomany>
249 <tomanycont></tomanycont>
250 </object>
251 """
252 modname = self.__class__.__module__
253 classname = self.__class__.__name__
254 id = root and self.getPrimaryId() or self.id
255 stag = "<object id='%s' module='%s' class='%s'>\n" % (
256 id , modname, classname)
257 ofile.write(stag)
258 for obj in self.objectValues():
259 if getattr(aq_base(obj), 'exportXml', False):
260 obj.exportXml(ofile, ignorerels)
261 ofile.write("</object>\n")
262
263
265 if getattr(aq_base(self), "zDeviceClass", False): return
266 self._setProperty("zDeviceClass", "")
267 self._setProperty("zDeviceGroup", "")
268 self._setProperty("zSystem", "")
269
270
271 InitializeClass(ManufacturerRoot)
272