1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from Globals import InitializeClass
16 from AccessControl import ClassSecurityInfo
17 from AccessControl import getSecurityManager
18 from AccessControl import Permissions as permissions
19
20 from sets import Set
21
22 import Products.ZenUtils.guid as guid
23 from Products.AdvancedQuery import MatchRegexp, Or, In, Eq
24
25 import simplejson
26
27 from Products.ZenModel.ZenModelRM import ZenModelRM
28 from Products.ZenRelations.RelSchema import *
29 from Products.ZenUtils.Search import makeCaseInsensitiveFieldIndex
30 from Products.ZenUtils.Search import makeCaseInsensitiveKeywordIndex
31
32 from Products.ZenModel.Link import Link
33 from Products.ZenModel.Linkable import Linkable
34
35 from Products.ZenUtils.NetworkTree import NetworkLink
36
37
47
48
50 """ An object that manages links.
51 """
52
53 default_catalog = "linkSearch"
54
55 _properties = (
56 {'id':'link_type','type':'string','mode':'w'},
57 {'id':'OSI_layer', 'type':'int', 'mode':'w'},
58 {'id':'entry_type', 'type':'string', 'mode':'w'},
59 )
60
61 _relations = (
62 ("links", ToManyCont(ToOne, "Products.ZenModel.Link", "linkManager")),
63 )
64
65 factory_type_information = (
66 { 'immediate_view' : 'viewLinkManager',
67 'factory' : 'manage_addLinkManager',
68 'actions' : (
69 { 'id' : 'viewLinkManager'
70 , 'name' : 'Link Manager'
71 , 'action' : 'viewLinkManager'
72 , 'permissions' : ( "Manage DMD", )
73 },)
74 },
75 )
76
77 security = ClassSecurityInfo()
78
81
97
99 """ Return the ZCatalog under the default_catalog attribute """
100 return getattr(self, self.default_catalog, None)
101
102 security.declareProtected('Change Device', 'manage_addLink')
103 - def manage_addLink(self, pointa, pointb,
104 link_type="", OSI_layer="1",
105 entry_type="manual", REQUEST=None):
115
116 security.declareProtected('Change Device', 'manage_removeLink')
122
123 security.declareProtected('Change Device', 'getNodeLinks')
130
131 security.declareProtected('View', 'getLinkedNodes')
136
138 zcat = self._getCatalog()
139 if not querystr or not zcat: return []
140 query = MatchRegexp(indxname, querystr)
141 brains = zcat.evalAdvancedQuery(query)
142 return [x.getObject() for x in brains]
143
146
149
152
155 zcat = self._getCatalog()._catalog
156 filter='(?is).*%s.*' % filter
157 filterquery = Or(
158 MatchRegexp('OSI_layer', filter),
159 MatchRegexp('getEndpointNames', filter),
160 MatchRegexp('link_type', filter)
161 )
162 objects = zcat.evalAdvancedQuery(filterquery, ((orderby, orderdir),))
163 objects = list(objects)
164 totalCount = len(objects)
165 offset, count = int(offset), int(count)
166 return totalCount, objects[offset:offset+count]
167
168 - def getJSONLinkInfo(self, offset=0, count=50, filter='',
169 orderby='OSI_layer', orderdir='asc'):
176
178 """
179 An alternate way to get links under an Organizer.
180 """
181 result = Set([])
182 networks = filter(lambda x:x.zDrawMapLinks,
183 self.dmd.Networks.getSubNetworks())
184 siblings = [x.getPrimaryId() for x in context.children()]
185 for net in networks:
186 locdict = {}
187 def addToDict(iface):
188 loc = iface.device().location()
189 if not loc: return
190 here = loc.getPrimaryId()
191 matched = False
192 for sib in siblings:
193 if here.startswith(sib):
194 locdict.setdefault(sib, []).append(iface)
195 matched = True
196 break
197 if not matched:
198 locdict.setdefault(here, []).append(iface)
199 for ip in net.ipaddresses.objectValuesGen():
200 iface = ip.interface()
201 if iface: addToDict(iface)
202 if len(locdict)<=1: continue
203 locgroups = locdict.values()
204 while locgroups:
205 lg = locgroups.pop()
206 targets = []
207 for g in locgroups: targets.extend(g)
208 for l in lg:
209 for t in targets:
210 n = NetworkLink()
211 n.setEndpoints(l, t)
212 result.add(n)
213 return result
214
228 links = filter(hasForeignEndpoint, links)
229 for x in links:
230 geomapdata = x.getGeomapData(sibling)
231 severities[geomapdata] = max(
232 x.getStatus(),
233 severities.get(geomapdata, 0)
234 )
235 result.add(geomapdata)
236 addresses = [x for x in list(result) if x]
237 severities = [severities[x] for x in addresses]
238 return map(list, zip(map(list, addresses), severities))
239
255
256
257
258 InitializeClass(LinkManager)
259