本文整理汇总了Python中Products.Zuul.interfaces.ICatalogTool.search方法的典型用法代码示例。如果您正苦于以下问题:Python ICatalogTool.search方法的具体用法?Python ICatalogTool.search怎么用?Python ICatalogTool.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.Zuul.interfaces.ICatalogTool
的用法示例。
在下文中一共展示了ICatalogTool.search方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _buildCache
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def _buildCache(self, orgtype=None, instancetype=None, relname=None, treePrefix=None, orderby=None):
if orgtype and not getattr(self._root, "_cache", None):
cat = ICatalogTool(self._object.unrestrictedTraverse(self.uid))
results = cat.search(orgtype, orderby=orderby)
if instancetype:
instanceresults = cat.search(instancetype, orderby=None)
self._root._cache = PathIndexCache(results, instanceresults, relname, treePrefix)
else:
self._root._cache = PathIndexCache(results)
return self._root._cache
示例2: remove
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def remove(self, app, leaveObjects=False):
if not leaveObjects:
log.info('Removing Hadoop components')
cat = ICatalogTool(app.zport.dmd)
for brain in cat.search(types=NEW_COMPONENT_TYPES):
component = brain.getObject()
component.getPrimaryParent()._delObject(component.id)
# Remove our Device relations additions.
Device._relations = tuple(
[x for x in Device._relations
if x[0] not in NEW_DEVICE_RELATIONS])
# Remove zHBaseMasterPort if HBase ZenPack is not installed
try:
self.dmd.ZenPackManager.packs._getOb(
'ZenPacks.zenoss.HBase'
)
except AttributeError:
if self.dmd.Devices.hasProperty('zHBaseMasterPort'):
self.dmd.Devices.deleteZenProperty('zHBaseMasterPort')
log.debug('Removing zHBaseMasterPort property')
log.info('Removing Hadoop device relationships')
self._buildDeviceRelations()
super(ZenPack, self).remove(app, leaveObjects=leaveObjects)
示例3: getDeviceBrains
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def getDeviceBrains(self, uid=None, start=0, limit=50, sort='name',
dir='ASC', params=None, hashcheck=None):
cat = ICatalogTool(self._getObject(uid))
reverse = dir=='DESC'
qs = []
query = None
globFilters = {}
if params is None:
params = {}
for key, value in params.iteritems():
if key == 'ipAddress':
ip = ensureIp(value)
try:
checkip(ip)
except IpAddressError:
pass
else:
if numbip(ip):
minip, maxip = getSubnetBounds(ip)
qs.append(Between('ipAddress', str(minip), str(maxip)))
elif key == 'deviceClass':
qs.append(MatchRegexp('uid', '(?i).*%s.*' %
value))
elif key == 'productionState':
qs.append(Or(*[Eq('productionState', str(state))
for state in value]))
else:
globFilters[key] = value
if qs:
query = And(*qs)
brains = cat.search('Products.ZenModel.Device.Device', start=start,
limit=limit, orderby=sort, reverse=reverse,
query=query, globFilters=globFilters, hashcheck=hashcheck)
return brains
示例4: moveProcess
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def moveProcess(self, uid, targetUid):
obj = self._getObject(uid)
target = self._getObject(targetUid)
brainsCollection = []
# reindex all the devices and processes underneath this guy and the target
for org in (obj.getPrimaryParent().getPrimaryParent(), target):
catalog = ICatalogTool(org)
brainsCollection.append(catalog.search(OSProcess))
if isinstance(obj, OSProcessClass):
source = obj.osProcessOrganizer()
source.moveOSProcessClasses(targetUid, obj.id)
newObj = getattr(target.osProcessClasses, obj.id)
elif isinstance(obj, OSProcessOrganizer):
source = aq_parent(obj)
source.moveOrganizer(targetUid, (obj.id,))
newObj = getattr(target, obj.id)
else:
raise Exception('Illegal type %s' % obj.__class__.__name__)
# fire the object moved event for the process instances (will update catalog)
for brains in brainsCollection:
objs = imap(unbrain, brains)
for item in objs:
notify(ObjectMovedEvent(item, item.os(), item.id, item.os(), item.id))
return newObj.getPrimaryPath()
示例5: getIpAddresses
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def getIpAddresses(self, limit=0, start=0, sort='ipAddressAsInt', dir='DESC',
params=None, uid=None, criteria=()):
infos = []
cat = ICatalogTool(self._getObject(uid))
reverse = dir=='DESC'
brains = cat.search("Products.ZenModel.IpAddress.IpAddress",
start=start, limit=limit,
orderby=sort, reverse=reverse)
for brain in brains:
infos.append(IInfo(unbrain(brain)))
devuuids = set(info.device.uuid for info in infos if info.device)
# get ping severities
zep = getFacade('zep')
pingSeverities = zep.getEventSeverities(devuuids,
severities=(),
status=(),
eventClass=Status_Ping)
self._assignPingStatuses(infos, pingSeverities)
# get snmp severities
snmpSeverities = zep.getEventSeverities(devuuids,
severities=(),
status=(),
eventClass=Status_Snmp)
self._assignSnmpStatuses(infos, snmpSeverities)
return SearchResults(infos, brains.total, brains.hash_)
示例6: getSubComponents
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def getSubComponents(self, dmd):
i = 0
catalog = ICatalogTool(dmd.Devices)
COMPONENT = 'Products.ZenModel.DeviceComponent.DeviceComponent'
query = Eq('monitored', '1')
for brain in catalog.search(COMPONENT, query=query):
i += 1
obj = None
try:
obj = brain.getObject()
except KeyError:
continue
dev = obj.device()
status = obj.getStatus()
row = (dict(
getParentDeviceTitle=obj.getParentDeviceTitle(),
hostname=obj.getParentDeviceTitle(),
name=obj.name(),
meta_type=obj.meta_type,
getInstDescription=obj.getInstDescription(),
getStatusString=obj.convertStatus(status),
getDeviceLink=obj.getDeviceLink(),
getPrimaryUrlPath=obj.getPrimaryUrlPath(),
cssclass=obj.getStatusCssClass(status),
status=status
))
obj._p_invalidate()
dev._p_invalidate()
if i % 100 == 0:
transaction.abort()
yield Utils.Record(**row)
示例7: interfaces_by_type
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def interfaces_by_type(device, type_):
"""Yield Interface objects matching the given type."""
catalog = ICatalogTool(device.primaryAq())
search_results = catalog.search(
types=('ZenPacks.Rackspace.BTI7200.%s.%s' % (type_, type_)))
for result in search_results.results:
yield result.getObject()
示例8: removeSoftwareAndOperatingSystems
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def removeSoftwareAndOperatingSystems(self, dmd):
"""
Find everything that is an OperationSystem Or
Software and unindex it
"""
cat = ICatalogTool(dmd)
brains = cat.search(types=(OperatingSystem,Software))
for brain in brains:
dmd.global_catalog.uncatalog_object(brain.getPath())
示例9: _findDevices
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def _findDevices(self, identifier, ipAddress, limit=None):
"""
Returns a tuple ([device brains], [devices]) searching manage IP and
interface IPs. limit is the maximum total number in both lists.
"""
dev_cat = ICatalogTool(self._devices)
try:
ip_address = next(i for i in (ipAddress, identifier) if isip(i))
ip_decimal = ipToDecimal(ip_address)
except Exception:
ip_address = None
ip_decimal = None
query_set = Or(Eq('id', identifier), Eq('name', identifier))
if ip_decimal is not None:
query_set.addSubquery(Eq('ipAddress', str(ip_decimal)))
device_brains = list(dev_cat.search(types=Device,
query=query_set,
limit=limit,
filterPermissions=False))
limit = None if limit is None else limit - len(device_brains)
if not limit:
return device_brains, []
if ip_decimal is not None:
# don't search interfaces for 127.x.x.x IPv4 addresses
if ipToDecimal('126.255.255.255') < ip_decimal < ipToDecimal('128.0.0.0'):
ip_decimal = None
# don't search interfaces for the ::1 IPv6 address
elif ipToDecimal('::1') == ip_decimal:
ip_decimal = None
if ip_decimal is None and not device_brains:
return [], []
net_cat = ICatalogTool(self._networks)
results = net_cat.search(types=IpAddress,
query=(Eq('name', ip_address)),
limit = limit,
filterPermissions = False)
devices = [brain.getObject().device() for brain in results]
return device_brains, devices
示例10: getInstances
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def getInstances(self, uid=None, start=0, limit=50, sort='name',
dir='ASC', params=None):
# do the catalog search
cat = ICatalogTool(self._getObject(uid))
reverse = bool(dir == 'DESC')
brains = cat.search(self._instanceClass, start=start, limit=limit,
orderby=sort, reverse=reverse)
objs = imap(unbrain, brains)
# convert to info objects
return SearchResults(imap(IInfo, objs), brains.total, brains.hash_)
示例11: remote_createAllUsers
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def remote_createAllUsers(self):
cat = ICatalogTool(self.dmd)
brains = cat.search(("Products.ZenModel.Device.Device", "Products.ZenModel.DeviceClass.DeviceClass"))
users = []
for brain in brains:
device = brain.getObject()
user = self._create_user(device)
if user is not None:
users.append(user)
fmt = 'SnmpTrapConfig.remote_createAllUsers {0} users'
log.debug(fmt.format(len(users)))
return users
示例12: getSubComponents
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def getSubComponents(self):
cat = ICatalogTool(self)
query = And(Not(Eq('objectImplements', 'Products.ZenModel.ComponentGroup.ComponentGroup')),
Not(Eq('objectImplements', 'Products.ZenModel.Device.Device')))
brains = cat.search(query=query)
children = []
for brain in brains:
try:
children.append(brain.getObject())
except:
pass
return children
示例13: interfaces_by_names
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def interfaces_by_names(device, interface_names, type_='Interface'):
"""Yield Interface objects matching the given names."""
catalog = ICatalogTool(device.primaryAq())
name_equals = (Eq('name', x) for x in interface_names)
search_results = catalog.search(
types=('ZenPacks.Rackspace.BTI7200.%s.%s' % (type_, type_,)),
query=Or(*name_equals))
for result in search_results.results:
yield result.getObject()
示例14: keyword_search
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def keyword_search(root, keywords):
"""Generate objects that match one or more of given keywords."""
if isinstance(keywords, basestring):
keywords = [keywords]
elif isinstance(keywords, set):
keywords = list(keywords)
if keywords:
catalog = ICatalogTool(root)
query = In('searchKeywords', keywords)
for result in catalog.search(query=query):
try:
yield result.getObject()
except Exception:
pass
示例15: cleanDevicePath
# 需要导入模块: from Products.Zuul.interfaces import ICatalogTool [as 别名]
# 或者: from Products.Zuul.interfaces.ICatalogTool import search [as 别名]
def cleanDevicePath(self, dmd):
"""
Make sure only groups systems and locations and device classes
are the only thing indexed by the path
"""
cat = ICatalogTool(dmd)
brains = cat.search(types=(Device,))
idx = dmd.global_catalog._catalog.indexes['path']
for brain in brains:
badPaths = []
for path in idx._unindex[brain.getRID()]:
if not self.keepDevicePath(path):
badPaths.append(path)
if badPaths:
dmd.global_catalog.unindex_object_from_paths(DummyDevice(brain), badPaths)