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__="""Collection 15 16 Collection is a grouping of devices and components. 17 """ 18 19 20 from AccessControl import Permissions 21 from Globals import InitializeClass 22 from AccessControl import ClassSecurityInfo, Permissions 23 from Globals import DTMLFile 24 from Products.ZenRelations.RelSchema import * 25 from ZenModelRM import ZenModelRM 26 2729 ''' This is here so than zope will let us copy/paste/rename 30 Collections. 31 ''' 32 c = Collection(id) 33 context._setObject(id, c) 34 if REQUEST is not None: 35 return REQUEST['RESPONSE'].redirect(context.absolute_url() +'/manage_main')36 37 addCollection = DTMLFile('dtml/addCollection',globals()) 38 3941 ''' Holds an assortment of devices and/or components. 42 ''' 43 44 meta_type = 'Collection' 45 46 _properties = ( 47 ) 48 49 _relations = ( 50 ('report', 51 ToOne(ToManyCont, 'Products.ZenModel.MultiGraphReport', 'collections')), 52 ('items', 53 ToManyCont(ToOne, 'Products.ZenModel.CollectionItem', 'collection')), 54 ) 55 56 factory_type_information = ( 57 { 58 'immediate_view' : 'editCollection', 59 'actions' : 60 ( 61 { 'id' : 'edit' 62 , 'name' : 'Collection' 63 , 'action' : 'editCollection' 64 , 'permissions' : ( Permissions.view, ) 65 }, 66 ) 67 }, 68 ) 69 70 security = ClassSecurityInfo() 71 72179 180 185 18673 - def createCollectionItem(self, orgPath='', devId='', compPath='', 74 recurse=False, checkExists=False):75 ''' Create and insert a new CollectionItem based either on the 76 orgPath or on devId/compPath. Returns the new item. 77 ''' 78 from CollectionItem import CollectionItem 79 ci = CollectionItem(self.getUnusedId('items', 'Item')) 80 if orgPath: 81 ci.deviceOrganizer = orgPath 82 else: 83 ci.deviceId = devId 84 ci.compPath = compPath 85 ci.recurse = recurse 86 ci.sequence = len(self.items()) 87 self.items._setObject(ci.id, ci) 88 ci = self.items._getOb(ci.id) 89 # This check happens after the _setObject so that ci has full 90 # aq wrapper in case it needs it. 91 if checkExists and not ci.getRepresentedItem(): 92 self.items._delObject(ci.id) 93 ci = None 94 return ci95 96 97 security.declareProtected('Manage DMD', 'manage_addCollectionItem')98 - def manage_addCollectionItem(self, itemType, 99 deviceIds=(), componentPaths=(), deviceClasses=(), systems=(), 100 groups=(), locations=(), recurse=False, REQUEST=None):101 ''' Create a new CollectionItem and add to this collection 102 ''' 103 from CollectionItem import CollectionItem 104 105 count = 0 106 if itemType == 'devcomp': 107 if not deviceIds: 108 deviceIds = [] 109 if not componentPaths: 110 componentPaths = [''] 111 for i, devId in enumerate(deviceIds): 112 for cPath in componentPaths: 113 ci = self.createCollectionItem(devId=devId, compPath=cPath, 114 recurse=False, checkExists=True) 115 if ci: 116 count += 1 117 if itemType == 'deviceClass': 118 for dClass in deviceClasses: 119 self.createCollectionItem( 120 orgPath='/Devices' + dClass, recurse=recurse) 121 count += 1 122 if itemType == 'system': 123 for system in systems: 124 self.createCollectionItem( 125 orgPath='/Systems' + system, recurse=recurse) 126 count += 1 127 if itemType == 'group': 128 for group in groups: 129 self.createCollectionItem( 130 orgPath='/Groups' + group, recurse=recurse) 131 count += 1 132 if itemType == 'location': 133 for loc in locations: 134 self.createCollectionItem( 135 orgPath='/Locations' + loc, recurse=recurse) 136 count += 1 137 138 if REQUEST: 139 REQUEST['message'] = ' %s item%s added' % (count, 140 count > 1 and 's' or '') 141 return self.callZenScreen(REQUEST)142 143 144 security.declareProtected('Manage DMD', 'manage_deleteCollectionItems')146 ''' Delete collection items from this report 147 ''' 148 for id in ids: 149 self.items._delObject(id) 150 self.manage_resequenceCollectionItems() 151 if REQUEST: 152 REQUEST['message'] = 'Item%s deleted' % (len(ids) > 1 and 's' or '') 153 return self.callZenScreen(REQUEST)154 155 156 security.declareProtected('Manage DMD', 'manage_resequenceCollectionItems')159 """Reorder the sequence of the items. 160 """ 161 from Products.ZenUtils.Utils import resequence 162 return resequence(self, self.items(), seqmap, origseq, REQUEST)163 164 165 security.declareProtected('Manage DMD', 'getItems')167 ''' Return an ordered list of CollectionItems 168 ''' 169 import sys 170 def cmpItems(a, b): 171 try: a = int(a.sequence) 172 except ValueError: a = sys.maxint 173 try: b = int(b.sequence) 174 except ValueError: b = sys.maxint 175 return cmp(a, b)176 items = self.items()[:] 177 items.sort(cmpItems) 178 return items188 ''' Return a deduped list of devices and components represented 189 by this collection's collectionitems 190 ''' 191 things = {} 192 for collectionItem in self.items(): 193 devsAndComps = collectionItem.getDevicesAndComponents() 194 for devOrComp in devsAndComps: 195 things[devOrComp.getPrimaryId()] = devOrComp 196 return things.values()197 198 199 InitializeClass(Collection) 200
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Oct 25 16:28:40 2007 | http://epydoc.sourceforge.net |