本文整理汇总了Python中opserver_util.OpServerUtils.uve_attr_flatten方法的典型用法代码示例。如果您正苦于以下问题:Python OpServerUtils.uve_attr_flatten方法的具体用法?Python OpServerUtils.uve_attr_flatten怎么用?Python OpServerUtils.uve_attr_flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opserver_util.OpServerUtils
的用法示例。
在下文中一共展示了OpServerUtils.uve_attr_flatten方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: aggregate
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import uve_attr_flatten [as 别名]
def aggregate(self, key, flat):
'''
This function does parallel aggregation of this UVE's state.
It aggregates across all sources and return the global state of the UVE
'''
result = {}
try:
for typ in self._state[key].keys():
result[typ] = {}
for objattr in self._state[key][typ].keys():
if self._is_sum(self._state[key][typ][objattr]):
sum_res = self._sum_agg(self._state[key][typ][objattr])
if flat:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(sum_res)
else:
result[typ][objattr] = sum_res
elif self._is_union(self._state[key][typ][objattr]):
union_res = self._union_agg(
self._state[key][typ][objattr])
if flat:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(union_res)
else:
result[typ][objattr] = union_res
elif self._is_append(self._state[key][typ][objattr]):
result[typ][objattr] = self._append_agg(
self._state[key][typ][objattr])
append_res = ParallelAggregator.consolidate_list(
result, typ, objattr)
if flat:
result[typ][objattr] =\
OpServerUtils.uve_attr_flatten(append_res)
else:
result[typ][objattr] = append_res
else:
default_res = self._default_agg(
self._state[key][typ][objattr])
if flat:
if (len(default_res) == 1):
result[typ][objattr] =\
OpServerUtils.uve_attr_flatten(
default_res[0][0])
else:
nres = []
for idx in range(len(default_res)):
nres.append(default_res[idx])
nres[idx][0] =\
OpServerUtils.uve_attr_flatten(
default_res[idx][0])
result[typ][objattr] = nres
else:
result[typ][objattr] = default_res
except KeyError:
pass
return result
示例2: aggregate
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import uve_attr_flatten [as 别名]
def aggregate(self, key, flat, base_url = None):
'''
This function does parallel aggregation of this UVE's state.
It aggregates across all sources and return the global state of the UVE
'''
result = {}
ltyp = None
objattr = None
try:
for typ in self._state[key].keys():
ltyp = typ
result[typ] = {}
for objattr in self._state[key][typ].keys():
if self._is_elem_sum(self._state[key][typ][objattr]):
sume_res = self._elem_sum_agg(self._state[key][typ][objattr])
if flat:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(sume_res)
else:
result[typ][objattr] = sume_res
elif self._is_struct_sum(self._state[key][typ][objattr]):
sums_res = self._struct_sum_agg(self._state[key][typ][objattr])
if flat:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(sums_res)
else:
result[typ][objattr] = sums_res
elif self._is_list_union(self._state[key][typ][objattr]):
unionl_res = self._list_union_agg(
self._state[key][typ][objattr])
if flat:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(unionl_res)
else:
result[typ][objattr] = unionl_res
elif self._is_map_union(self._state[key][typ][objattr]):
unionm_res = self._map_union_agg(
self._state[key][typ][objattr])
if flat:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(unionm_res)
else:
result[typ][objattr] = unionm_res
elif self._is_append(self._state[key][typ][objattr]):
result[typ][objattr] = self._append_agg(
self._state[key][typ][objattr])
append_res = ParallelAggregator.consolidate_list(
result, typ, objattr)
if flat:
result[typ][objattr] =\
OpServerUtils.uve_attr_flatten(append_res)
else:
result[typ][objattr] = append_res
else:
default_res = self._default_agg(
self._state[key][typ][objattr])
if flat:
if (len(default_res) == 1):
result[typ][objattr] =\
OpServerUtils.uve_attr_flatten(
default_res[0][0])
else:
nres = []
for idx in range(len(default_res)):
nres.append(default_res[idx])
nres[idx][0] =\
OpServerUtils.uve_attr_flatten(
default_res[idx][0])
result[typ][objattr] = nres
else:
result[typ][objattr] = default_res
except KeyError:
pass
except Exception as ex:
print "Aggregation Error key %s type %s attr %s in %s" % \
(key, str(ltyp), str(objattr), str(self._state[key][typ][objattr]))
return result
示例3: aggregate
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import uve_attr_flatten [as 别名]
def aggregate(self, key, flat, base_url = None):
'''
This function does parallel aggregation of this UVE's state.
It aggregates across all sources and return the global state of the UVE
'''
result = {}
try:
for typ in self._state[key].keys():
result[typ] = {}
for objattr in self._state[key][typ].keys():
if self._is_sum(self._state[key][typ][objattr]):
sum_res = self._sum_agg(self._state[key][typ][objattr])
if flat:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(sum_res)
else:
result[typ][objattr] = sum_res
elif self._is_union(self._state[key][typ][objattr]):
union_res = self._union_agg(
self._state[key][typ][objattr])
conv_res = None
if union_res.has_key('@ulink') and base_url and \
union_res['list']['@type'] == 'string':
uterms = union_res['@ulink'].split(":",1)
# This is the linked UVE's table name
m_table = uterms[0]
if self._rev_map.has_key(m_table):
h_table = self._rev_map[m_table]
conv_res = []
sname = ParallelAggregator.get_list_name(union_res)
for el in union_res['list'][sname]:
lobj = {}
lobj['name'] = el
lobj['href'] = base_url + '/analytics/uves/' + \
h_table + '/' + el
if len(uterms) == 2:
lobj['href'] = lobj['href'] + '?cfilt=' + uterms[1]
else:
lobj['href'] = lobj['href'] + '?flat'
conv_res.append(lobj)
if flat:
if not conv_res:
result[typ][objattr] = \
OpServerUtils.uve_attr_flatten(union_res)
else:
result[typ][objattr] = conv_res
else:
result[typ][objattr] = union_res
elif self._is_append(self._state[key][typ][objattr]):
result[typ][objattr] = self._append_agg(
self._state[key][typ][objattr])
append_res = ParallelAggregator.consolidate_list(
result, typ, objattr)
if flat:
result[typ][objattr] =\
OpServerUtils.uve_attr_flatten(append_res)
else:
result[typ][objattr] = append_res
else:
default_res = self._default_agg(
self._state[key][typ][objattr])
if flat:
if (len(default_res) == 1):
result[typ][objattr] =\
OpServerUtils.uve_attr_flatten(
default_res[0][0])
else:
nres = []
for idx in range(len(default_res)):
nres.append(default_res[idx])
nres[idx][0] =\
OpServerUtils.uve_attr_flatten(
default_res[idx][0])
result[typ][objattr] = nres
else:
result[typ][objattr] = default_res
except KeyError:
pass
return result
示例4: get_uve
# 需要导入模块: from opserver_util import OpServerUtils [as 别名]
# 或者: from opserver_util.OpServerUtils import uve_attr_flatten [as 别名]
def get_uve(self, key, flat, filters=None, base_url=None):
filters = filters or {}
sfilter = filters.get('sfilt')
mfilter = filters.get('mfilt')
tfilter = filters.get('cfilt')
ackfilter = filters.get('ackfilt')
if flat and not sfilter and not mfilter and self._usecache:
return self._uvedbcache.get_uve(key, filters)
is_alarm = False
if tfilter == "UVEAlarms":
is_alarm = True
state = {}
state[key] = {}
rsp = {}
failures = False
tab = key.split(":",1)[0]
for r_inst in self._redis_uve_map.keys():
try:
redish = self._redis_inst_get(r_inst)
qmap = {}
ppe = redish.pipeline()
ppe.smembers("ALARM_ORIGINS:" + key)
if not is_alarm:
ppe.smembers("ORIGINS:" + key)
pperes = ppe.execute()
origins = set()
for origset in pperes:
for smt in origset:
tt = smt.rsplit(":",1)[1]
sm = smt.rsplit(":",1)[0]
source = sm.split(":", 1)[0]
mdule = sm.split(":", 1)[1]
if tfilter is not None:
if tt not in tfilter:
continue
if sfilter is not None:
if sfilter != source:
continue
if mfilter is not None:
if mfilter != mdule:
continue
origins.add(smt)
ppeval = redish.pipeline()
for origs in origins:
ppeval.hgetall("VALUES:" + key + ":" + origs)
odictlist = ppeval.execute()
idx = 0
for origs in origins:
odict = odictlist[idx]
idx = idx + 1
info = origs.rsplit(":", 1)
dsource = info[0]
typ = info[1]
afilter_list = set()
if tfilter is not None:
afilter_list = tfilter[typ]
for attr, value in odict.iteritems():
if len(afilter_list):
if attr not in afilter_list:
continue
if value[0] == '<':
snhdict = xmltodict.parse(value)
# TODO: This is a hack for separating external
# bgp routers from control-nodes
if snhdict[attr]['@type'] == 'map':
if typ == 'ContrailConfig' and \
tab == 'ObjectBgpRouter' and \
attr == 'elements':
try:
elem = OpServerUtils.uve_attr_flatten(\
snhdict[attr])
vendor = json.loads(\
elem['bgp_router_parameters'])["vendor"]
if vendor != "contrail":
continue
except:
pass
elif snhdict[attr]['@type'] == 'list':
sname = ParallelAggregator.get_list_name(
snhdict[attr])
if snhdict[attr]['list']['@size'] == '0':
continue
elif snhdict[attr]['list']['@size'] == '1':
if not isinstance(
snhdict[attr]['list'][sname], list):
snhdict[attr]['list'][sname] = [
#.........这里部分代码省略.........