本文整理汇总了Python中ion.services.sa.observatory.observatory_util.ObservatoryUtil.get_site_root方法的典型用法代码示例。如果您正苦于以下问题:Python ObservatoryUtil.get_site_root方法的具体用法?Python ObservatoryUtil.get_site_root怎么用?Python ObservatoryUtil.get_site_root使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ion.services.sa.observatory.observatory_util.ObservatoryUtil
的用法示例。
在下文中一共展示了ObservatoryUtil.get_site_root方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process_cmd_sites
# 需要导入模块: from ion.services.sa.observatory.observatory_util import ObservatoryUtil [as 别名]
# 或者: from ion.services.sa.observatory.observatory_util.ObservatoryUtil import get_site_root [as 别名]
def _process_cmd_sites(resource_id, res_obj=None):
from ion.services.sa.observatory.observatory_util import ObservatoryUtil
outil = ObservatoryUtil(container=Container.instance)
statuses = outil.get_status_roll_ups(resource_id, include_structure=True)
fragments = [
"</pre><h3>Org, Site and Device Status</h3>",
]
if '_system' in statuses:
extra = statuses['_system']
child_sites, ancestors, devices = extra.get('sites', {}), extra.get('ancestors', {}), extra.get('devices', {})
root_id = outil.get_site_root(resource_id, ancestors=ancestors) if ancestors else resource_id
fragments.append("<p><table>")
fragments.append("<tr><th>Resource</th><th>Type</th><th>AGG</th><th>PWR</th><th>COMM</th><th>DATA</th><th>LOC</th></tr>")
device_info = {}
if devices:
dev_id_list = [dev[1] for dev in devices.values() if dev is not None]
if dev_id_list:
dev_list = Container.instance.resource_registry.read_mult(dev_id_list)
device_info = dict(zip([res._id for res in dev_list], dev_list))
elif ancestors:
dev_id_list = [anc for anc_list in ancestors.values() if anc_list is not None for anc in anc_list]
dev_id_list.append(resource_id)
dev_list = Container.instance.resource_registry.read_mult(dev_id_list)
device_info = dict(zip([res._id for res in dev_list], dev_list))
def stat(status, stype):
stat = status.get(stype, 4)
stat_str = ['', "<span style='color:green'>OK</span>","<span style='color:orange'>WARN</span>","<span style='color:red'>ERROR</span>",'?']
return stat_str[stat]
def status_table(parent_id, level):
fragments.append("<tr>")
par_detail = child_sites.get(parent_id, None) or device_info.get(parent_id, None)
par_status = statuses.get(parent_id, {})
entryname = " "*level + build_link(par_detail.name if par_detail else parent_id, "/view/%s" % parent_id)
if parent_id == resource_id:
entryname = "<b>" + entryname + "</b>"
fragments.append("<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>" % (
entryname,
par_detail._get_type() if par_detail else "?",
stat(par_status, 'agg'), stat(par_status, 'power'), stat(par_status, 'comms'), stat(par_status, 'data'), stat(par_status, 'loc')))
fragments.append("</tr>")
device = devices.get(parent_id, None)
if device:
status_table(device[1], level+1)
ch_ids = ancestors.get(parent_id, None) or []
for ch_id in ch_ids:
status_table(ch_id, level+1)
status_table(root_id, 0)
fragments.append("</table></p>")
fragments.append("<pre>%s</pre>" % (pprint.pformat(statuses))),
else:
fragments.append("<pre>%s</pre>" % (pprint.pformat(statuses))),
fragments.append("<pre>")
content = "\n".join(fragments)
return content