本文整理汇总了Python中Products.ZenUtils.ZenScriptBase.ZenScriptBase.unrestrictedTraverse方法的典型用法代码示例。如果您正苦于以下问题:Python ZenScriptBase.unrestrictedTraverse方法的具体用法?Python ZenScriptBase.unrestrictedTraverse怎么用?Python ZenScriptBase.unrestrictedTraverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.ZenUtils.ZenScriptBase.ZenScriptBase
的用法示例。
在下文中一共展示了ZenScriptBase.unrestrictedTraverse方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ModelCatalogUtils
# 需要导入模块: from Products.ZenUtils.ZenScriptBase import ZenScriptBase [as 别名]
# 或者: from Products.ZenUtils.ZenScriptBase.ZenScriptBase import unrestrictedTraverse [as 别名]
class ModelCatalogUtils(object):
def __init__(self, dmd=None):
self.model_index = zope.component.createObject('ModelIndex', get_solr_config())
self.dmd = dmd
def _get_zodb_connection(self):
print("Connecting to zodb...")
from Products.ZenUtils.ZenScriptBase import ZenScriptBase
self.dmd = ZenScriptBase(connect=True).dmd
def _get_object(self, uid):
obj = None
if not self.dmd:
self._get_zodb_connection()
try:
obj = self.dmd.unrestrictedTraverse(uid)
except:
print "Object not found: {}".format(uid)
return obj
def index_by_uid(self, uid):
obj = self._get_object(uid)
if obj:
self.model_index.index(obj)
def unindex_by_uid(self, uid):
query={UID: uid}
search_params=SearchParams(query=query)
self.model_index.unindex_search(search_params, collection=ZENOSS_MODEL_COLLECTION_NAME)
def generate_indexing_event(self, uid):
obj = self._get_object(uid)
if obj:
notify(IndexingEvent(obj))