1
2
3
4
5
6
7
8
9
10
11 __doc__="""ManufacturerRoot
12
13 The Manufacturer classification class. default identifiers and screens,
14 live here.
15
16 $Id: ManufacturerRoot.py,v 1.10 2004/04/22 02:14:12 edahl Exp $"""
17
18 __version__ = "$Revision: 1.10 $"[11:-2]
19
20 import logging
21 log = logging.getLogger('zen')
22
23 import transaction
24
25 from Globals import InitializeClass
26 from Acquisition import aq_base
27 from AccessControl import Permissions as permissions
28 from Products.ZenModel.ZenossSecurity import *
29
30 from Products.ZenRelations.PrimaryPathObjectManager import \
31 PrimaryPathBTreeFolder2
32
33 from ZenModelItem import ZenModelItem
34 from ZenPacker import ZenPacker
35 from Products.ZenUtils.Search import \
36 makeCaseSensitiveKeywordIndex, makeCaseInsensitiveFieldIndex
37 from Products.ManagableIndex import FieldIndex
38
46
47
48
49
50 _MARKER = object()
51
53 """
54 The root organizer for manufacturers. May become a BtreeFolder2 at
55 some point (to scale better). Has interface to manage Manufacturers
56 and the products that they create.
57 """
58 dmdRootName = "Manufacturers"
59 meta_type = "ManufacturerRoot"
60 sub_classes = ('Manufacturer',)
61 default_catalog = "productSearch"
62
63
64 factory_type_information = (
65 {
66 'id' : 'Manufacturer',
67 'meta_type' : 'Manufacturer',
68 'description' : """Arbitrary device grouping class""",
69 'icon' : 'Manufacturer_icon.gif',
70 'product' : 'ZenModel',
71 'factory' : 'manage_addManufacturer',
72 'immediate_view' : 'viewManufacturers',
73 'actions' :
74 (
75 { 'id' : 'overview'
76 , 'name' : 'Overview'
77 , 'action' : 'viewManufacturers'
78 , 'permissions' : (
79 permissions.view, )
80 },
81 )
82 },
83 )
84
85
92
93
100
101
108
109
111 """Return and create if nessesary manufacturerName.
112 """
113 from Products.ZenModel.Manufacturer import manage_addManufacturer
114 if manufacturerName and not self.has_key(manufacturerName):
115 logging.info("Creating Manufacturer %s" % manufacturerName)
116 manage_addManufacturer(self, manufacturerName)
117 if manufacturerName:
118 return self._getOb(manufacturerName)
119 return None
120
121
123 """
124 Return manufacturerName. If it doesn't exist, create it.
125 """
126 manufacturerName = self.prepId(manufacturerName)
127 if self.has_key(manufacturerName):
128 return self._getOb(manufacturerName)
129 else:
130 for m in self.objectValues(spec="Manufacturer"):
131 if m.matches(manufacturerName):
132 return m
133
134 return self.createManufacturer(manufacturerName)
135
136
138 """return list of all companies"""
139 return self.objectIds(spec=("Manufacturer"))
140
141
143 """return a list of all products this Manufacturer makes"""
144 productFilter = dict(getManufacturerName=mname)
145 if type == "OS":
146 productFilter['meta_type'] = "SoftwareClass"
147 productFilter['isOS'] = True
148 elif type:
149 productFilter['meta_type'] = type
150
151 cat = getattr(self, self.default_catalog)
152 return sorted(['']+[entry.id for entry in cat(productFilter)])
153
154
166
167
173
174
181
182
183 - def _getProduct(self, prodName, manufacturer, factory, **kwargs):
193
194
196 """Return a generator that gets all products.
197 """
198 for manuf in self.values(spec="Manufacturer"):
199 for prod in manuf.products.objectValuesGen():
200 yield prod
201
202
209
210
228
229
230 - def exportXml(self, ofile, ignorerels=[], root=False):
231 """Return an xml based representation of a RelationshipManager
232 <object id='/Devices/Servers/Windows/dhcp160.confmon.loc'
233 module='Products.Confmon.IpInterface' class='IpInterface'>
234 <property id='name'>jim</property>
235 <toone></toone>
236 <tomany></tomany>
237 <tomanycont></tomanycont>
238 </object>
239 """
240 modname = self.__class__.__module__
241 classname = self.__class__.__name__
242 id = root and self.getPrimaryId() or self.id
243 stag = "<object id='%s' module='%s' class='%s'>\n" % (
244 id , modname, classname)
245 ofile.write(stag)
246 for obj in self.objectValues():
247 if getattr(aq_base(obj), 'exportXml', False):
248 obj.exportXml(ofile, ignorerels)
249 ofile.write("</object>\n")
250
252 """Return self with is acquisition path set to primary path"""
253
254 parent = getattr(self, "__primary_parent__", _MARKER)
255 if parent is _MARKER:
256 base = self.getPhysicalRoot().zport
257 return aq_base(self).__of__(base)
258 if parent is None:
259 raise KeyError(self.id)
260 return aq_base(self).__of__(parent.primaryAq())
261
263 if getattr(aq_base(self), "zDeviceClass", False): return
264 self._setProperty("zDeviceClass", "")
265 self._setProperty("zDeviceGroup", "")
266 self._setProperty("zSystem", "")
267
268
269 InitializeClass(ManufacturerRoot)
270