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  import urllib, urllib2 
 33   
 34   
35 -def manage_addLocation(context, id, description = "", 36 address="", REQUEST = None):
37 """make a Location""" 38 loc = Location(id, description) 39 context._setObject(id, loc) 40 loc.description = description 41 loc.address = address 42 if REQUEST is not None: 43 REQUEST['RESPONSE'].redirect(context.absolute_url() +'/manage_main')
44 45 46 addLocation = DTMLFile('dtml/addLocation',globals()) 47 48
49 -class Location(DeviceOrganizer, ZenPackable):
50 """ 51 Location is a DeviceGroup Organizer that manages physical device Locations. 52 """ 53 54 # Organizer configuration 55 dmdRootName = "Locations" 56 57 address = '' 58 59 portal_type = meta_type = event_key = 'Location' 60 61 _properties = DeviceOrganizer._properties + ( 62 {'id':'address','type':'string','mode':'w'}, 63 ) 64 65 _relations = DeviceOrganizer._relations + ZenPackable._relations + ( 66 ("devices", ToMany(ToOne,"Products.ZenModel.Device","location")), 67 ("networks", ToMany(ToOne,"Products.ZenModel.IpNetwork","location")), 68 ) 69 70 # Screen action bindings (and tab definitions) 71 factory_type_information = ( 72 { 73 'immediate_view' : 'deviceOrganizerStatus', 74 'actions' : 75 ( 76 { 'id' : 'status' 77 , 'name' : 'Status' 78 , 'action' : 'deviceOrganizerStatus' 79 , 'permissions' : (permissions.view,) 80 }, 81 { 'id' : 'events' 82 , 'name' : 'Events' 83 , 'action' : 'viewEvents' 84 , 'permissions' : (permissions.view,) 85 }, 86 { 'id' : 'historyEvents' 87 , 'name' : 'History' 88 , 'action' : 'viewHistoryEvents' 89 , 'permissions' : (permissions.view,) 90 }, 91 { 'id' : 'manage' 92 , 'name' : 'Administration' 93 , 'action' : 'deviceOrganizerManage' 94 , 'permissions' : ('Manage DMD',) 95 }, 96 { 'id' : 'geomap' 97 , 'name' : 'Map' 98 , 'action' : 'locationGeoMap' 99 , 'permissions' : (permissions.view,) 100 }, 101 ) 102 }, 103 ) 104 105 security = ClassSecurityInfo() 106 110
111 - def numMappableChildren(self):
112 children = self.children() 113 return len( 114 filter(lambda x:getattr(x, 'address', None), children) 115 )
116
117 - def getGeomapData(self):
118 """ Returns node info ready for Google Maps """ 119 address = self.address 120 summary = self.getEventSummary() 121 colors = 'red orange yellow green green'.split() 122 color = 'green' 123 for i in range(5): 124 if summary[i][1]+summary[i][2]>0: 125 color = colors[i] 126 break 127 link = self.absolute_url_path() 128 linkToMap = self.numMappableChildren() 129 if linkToMap: 130 link+='/locationGeoMap' 131 summarytext = """ 132 Subdevices: %s 133 Mappable Children: %s 134 """ % (len(self.getSubDevices()), self.numMappableChildren()) 135 136 return [address, color, link, summarytext]
137
138 - def getChildGeomapData(self):
139 """ Returns geomap info on child nodes """ 140 allnodes = [] 141 data = [] 142 children = self.children() 143 allnodes.extend(children) 144 data = [x.getGeomapData() for x in allnodes] 145 if not data: data = [self.getGeomapData()] 146 return data
147
148 - def getSecondaryNodes(self):
149 """ Returns geomap info on cousin nodes that should be 150 included in the view due to outside linking. 151 """ 152 data = [] 153 # Short-circuit the method for now 154 return data 155 children = self.children() 156 olddata = self.getChildGeomapData() 157 for child in children: 158 childlinks = child.getLinks(recursive=False) 159 for link in childlinks: 160 gdata = link.getGeomapData(child, full=True) 161 if gdata is not None: 162 for datum in gdata: 163 if (datum not in olddata and 164 data!=self.getGeomapData()): 165 data.append(datum) 166 return data
167 168 InitializeClass(Location) 169