Trees | Indices | Help |
|
---|
|
1 ########################################################################### 2 # 3 # This program is part of Zenoss Core, an open source monitoring platform. 4 # Copyright (C) 2007, 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__="""CollectionItem 15 16 Defines attributes for how a data source will be graphed 17 and builds the nessesary rrd commands. 18 """ 19 20 import os 21 22 from Globals import InitializeClass 23 from Globals import DTMLFile 24 from AccessControl import ClassSecurityInfo, Permissions 25 from Products.ZenRelations.RelSchema import * 26 from ZenModelRM import ZenModelRM 27 2831 ''' This is here so than zope will let us copy/paste/rename 32 CollectionItems. 33 ''' 34 ci = CollectionItem(id) 35 context._setObject(id, ci) 36 ci.deviceId = deviceId 37 ci.compPath = compPath 38 ci.sequence = sequence 39 if REQUEST is not None: 40 return REQUEST['RESPONSE'].redirect(context.absolute_url() +'/manage_main')41 42 addCollectionItem = DTMLFile('dtml/addCollectionItem',globals()) 43 4446 47 meta_type = 'CollectionItem' 48 49 sequence = 0 50 deviceId = '' 51 compPath = '' 52 deviceOrganizer = '' 53 recurse = False 54 55 _properties = ( 56 {'id':'sequence', 'type':'long', 'mode':'w'}, 57 {'id':'deviceId', 'type':'string', 'mode':'w'}, 58 {'id':'compPath', 'type':'string', 'mode':'w'}, 59 {'id':'deviceOrganizer', 'type':'string', 'mode':'w'}, 60 {'id':'recurse', 'type':'boolean', 'mode':'w'}, 61 ) 62 63 _relations = ( 64 ('collection', ToOne(ToManyCont,'Products.ZenModel.Collection','items')), 65 ) 66 67 factory_type_information = ( 68 { 69 'immediate_view' : 'editCollectionItem', 70 'actions' : 71 ( 72 { 'id' : 'edit' 73 , 'name' : 'Collection Item' 74 , 'action' : 'editCollectionItem' 75 , 'permissions' : ( Permissions.view, ) 76 }, 77 ) 78 }, 79 ) 80 81 security = ClassSecurityInfo() 82154 155 156 157 InitializeClass(CollectionItem) 15883 - def __init__(self, id, deviceId='', compPath='', deviceOrganizer='', 84 recurse=False, sequence=0, title=None, buildRelations=True):85 ZenModelRM.__init__(self, id, title, buildRelations) 86 self.deviceId = deviceId 87 self.compPath = compPath 88 self.deviceOrganizer = deviceOrganizer 89 self.recurse = recurse 90 self.sequence = sequence91 9294 ''' Return a string that represents this item 95 ''' 96 thing = self.getRepresentedItem() 97 if self.deviceId: 98 if self.compPath: 99 desc = '%s %s' % (self.deviceId, thing.name()) 100 else: 101 desc = self.deviceId 102 if withLink and thing: 103 desc = '<a href="%s">%s</a>' % (thing.getPrimaryUrlPath(),desc) 104 else: 105 if withLink and thing: 106 desc = '<a href="%s">%s</a>' % (thing.getPrimaryUrlPath(), 107 self.deviceOrganizer) 108 else: 109 desc = self.deviceOrganizer 110 if self.recurse: 111 desc += ' and suborganizers' 112 return desc113 114116 ''' Get the device organizer, component or device 117 that this collection item represents 118 ''' 119 thing = None 120 if self.deviceId: 121 thing = self.dmd.Devices.findDevice(self.deviceId) 122 if self.compPath: 123 for part in self.compPath.split('/'): 124 if part: 125 thing = getattr(thing, part, None) 126 if not thing: 127 break 128 elif self.deviceOrganizer: 129 try: 130 thing = self.dmd.getObjByPath(self.deviceOrganizer.lstrip('/')) 131 except KeyError: 132 thing = None 133 return thing134 135137 ''' Return a list of the devices and components referenced by this item 138 ''' 139 thing = self.getRepresentedItem() 140 if self.deviceId: 141 stuff = [thing] 142 elif self.recurse: 143 stuff = thing.getSubDevices() 144 else: 145 stuff = thing.devices() 146 return stuff147 148150 ''' Return the number of devices and components matched by this item 151 ''' 152 things = self.getDevicesAndComponents() 153 return len(things)
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:51 2007 | http://epydoc.sourceforge.net |