本文整理匯總了Python中Mgmt.iterate方法的典型用法代碼示例。如果您正苦於以下問題:Python Mgmt.iterate方法的具體用法?Python Mgmt.iterate怎麽用?Python Mgmt.iterate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Mgmt
的用法示例。
在下文中一共展示了Mgmt.iterate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_alarm_status
# 需要導入模塊: import Mgmt [as 別名]
# 或者: from Mgmt import iterate [as 別名]
def get_alarm_status(self, alarm):
"""
get_alarm_status(auth, alarm) -> string
Get an alarm's status.
Parameters:
alarm (string) - name of the alarm whose status will be returned
Exceptions:
get_alarm_statusFault - Alarm does not exist
get_alarm_statusFault - Server Error. Contact Support.
"""
alarm = alarm.lower()
alarm_enabled = Mgmt.get_value('/stats/config/alarm/%s/enable'
% alarm)
if alarm_enabled is None:
raise ServiceError, 'Alarm %s does not exist' % alarm
elif alarm_enabled == 'false':
return 'disabled'
elif alarm_enabled == 'true':
# XXX/jshilkaitis: use mdc_iterate_binding_pattern one day, but
# need to expose it first, and since it's non-trivial, I'm
# punting on that for now.
alarm_pfx = '/stats/state/alarm/' + alarm
alarm_nodes = Mgmt.iterate(alarm_pfx, subtree=True)
for node in alarm_nodes:
if ((Mgmt.bn_name_pattern_match(
node[0], alarm_pfx + '/node/*/rising/error') or
Mgmt.bn_name_pattern_match(
node[0], alarm_pfx + '/node/*/falling/error')) and
node[2] == 'true'):
return 'ERROR'
else:
raise ServiceError, 'Server error. Contact Support.'
return 'ok'
示例2: __get_top_talkers_list
# 需要導入模塊: import Mgmt [as 別名]
# 或者: from Mgmt import iterate [as 別名]
def __get_top_talkers_list(self, node_path, value_type):
"""
Internal function to support top talkers queries.
Iterate subtree on node_path and use the results to generate
a result list of value_type instances.
"""
temp_result = {}
bindings = Mgmt.iterate(node_path, subtree=True)
for b in bindings:
if Mgmt.bn_name_pattern_match(b[0], node_path + '/*/*'):
parts = Mgmt.bn_name_to_parts(b[0])
idx = int(parts[3]) - 1 # iterate results are 1-based
attr_name = parts[4]
curr_val = temp_result.setdefault(idx, value_type())
setattr(curr_val, attr_name, b[2])
return [temp_result[i] for i in xrange(len(temp_result))]