Package ZenModel :: Module Location
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.Location

  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__="""Location 
 15   
 16  $Id: Location.py,v 1.12 2004/04/22 19:08:47 edahl Exp $""" 
 17   
 18  __version__ = "$Revision: 1.12 $"[11:-2] 
 19   
 20  from Globals import InitializeClass 
 21  from Globals import DTMLFile 
 22   
 23  from AccessControl import ClassSecurityInfo 
 24   
 25  from AccessControl import Permissions as permissions 
 26   
 27  from Products.ZenRelations.RelSchema import * 
 28   
 29  from DeviceOrganizer import DeviceOrganizer 
 30  from ZenPackable import ZenPackable 
 31   
32 -def manage_addLocation(context, id, description = "", 33 address="", REQUEST = None):
34 """make a Location""" 35 loc = Location(id, description) 36 context._setObject(id, loc) 37 loc.description = description 38 loc.address = address 39 if REQUEST is not None: 40 REQUEST['RESPONSE'].redirect(context.absolute_url() +'/manage_main')
41 42 43 addLocation = DTMLFile('dtml/addLocation',globals()) 44 45
46 -class Location(DeviceOrganizer, ZenPackable):
47 """ 48 Location is a DeviceGroup Organizer that manages physical device Locations. 49 """ 50 51 # Organizer configuration 52 dmdRootName = "Locations" 53 54 address = '' 55 56 portal_type = meta_type = event_key = 'Location' 57 58 _properties = DeviceOrganizer._properties + ( 59 {'id':'address','type':'string','mode':'w'}, 60 ) 61 62 _relations = DeviceOrganizer._relations + ZenPackable._relations + ( 63 ("devices", ToMany(ToOne,"Products.ZenModel.Device","location")), 64 ("networks", ToMany(ToOne,"Products.ZenModel.IpNetwork","location")), 65 ) 66 67 # Screen action bindings (and tab definitions) 68 factory_type_information = ( 69 { 70 'immediate_view' : 'deviceOrganizerStatus', 71 'actions' : 72 ( 73 { 'id' : 'status' 74 , 'name' : 'Status' 75 , 'action' : 'deviceOrganizerStatus' 76 , 'permissions' : (permissions.view,) 77 }, 78 { 'id' : 'events' 79 , 'name' : 'Events' 80 , 'action' : 'viewEvents' 81 , 'permissions' : (permissions.view,) 82 }, 83 # { 'id' : 'historyEvents' 84 # , 'name' : 'History' 85 # , 'action' : 'viewHistoryEvents' 86 # , 'permissions' : (permissions.view,) 87 # }, 88 { 'id' : 'manage' 89 , 'name' : 'Administration' 90 , 'action' : 'deviceOrganizerManage' 91 , 'permissions' : ('Manage DMD',) 92 }, 93 { 'id' : 'geomap' 94 , 'name' : 'Map' 95 , 'action' : 'locationGeoMap' 96 , 'permissions' : (permissions.view,) 97 }, 98 ) 99 }, 100 ) 101 102 security = ClassSecurityInfo() 103
104 - def setAddress(self, address):
105 """Sets the mailing address for this location""" 106 self.address = address
107 111
112 - def numMappableChildren(self):
113 children = self.children() 114 return len( 115 filter(lambda x:getattr(x, 'address', None), children) 116 )
117
118 - def getGeomapData(self):
119 """ Returns node info ready for Google Maps """ 120 address = self.address 121 psthresh = self.dmd.prodStateDashboardThresh 122 summary = self.getEventSummary(prodState=psthresh) 123 colors = 'red orange yellow green green'.split() 124 color = 'green' 125 for i in range(5): 126 if summary[i][1]+summary[i][2]>0: 127 color = colors[i] 128 break 129 link = self.absolute_url_path() 130 linkToMap = self.numMappableChildren() 131 if linkToMap: 132 link+='/locationGeoMap' 133 summarytext = self.mapTooltip() # mapTooltip is a page template 134 return [address, color, link, summarytext]
135
136 - def getChildGeomapData(self):
137 """ Returns geomap info on child nodes """ 138 allnodes = [] 139 data = [] 140 children = self.children() 141 allnodes.extend(children) 142 data = [x.getGeomapData() for x in allnodes] 143 if not data: data = [self.getGeomapData()] 144 return data
145
146 - def getSecondaryNodes(self):
147 """ Returns geomap info on cousin nodes that should be 148 included in the view due to outside linking. 149 """ 150 data = [] 151 # Short-circuit the method for now 152 return data
153 154 InitializeClass(Location) 155