本文整理汇总了Python中ion.services.sa.observatory.observatory_util.ObservatoryUtil类的典型用法代码示例。如果您正苦于以下问题:Python ObservatoryUtil类的具体用法?Python ObservatoryUtil怎么用?Python ObservatoryUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObservatoryUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_child_sites_org
def test_get_child_sites_org(self):
self.mu.load_mock_resources(self.res_list)
self.mu.load_mock_associations(self.assoc_list + self.assoc_list1)
self.mu.assign_mockres_find_objects(filter_predicate="hasResource")
self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock)
child_sites, site_ancestors = self.obs_util.get_child_sites(org_id='Org_1', include_parents=False, id_only=True)
self.assertEquals(len(child_sites), 6)
self.assertEquals(len(site_ancestors), 5)
self.assertIn('Sub_1', child_sites)
self.assertIn('PS_1', child_sites)
self.assertIn('IS_1', child_sites)
self.assertIn('Obs_1', child_sites)
self.assertIn('Obs_2', child_sites)
child_sites, site_ancestors = self.obs_util.get_child_sites(org_id='Org_1', include_parents=True, id_only=True)
self.assertEquals(len(child_sites), 7)
self.assertEquals(len(site_ancestors), 5)
child_sites, site_ancestors = self.obs_util.get_child_sites(org_id='Org_1', include_parents=True, id_only=False)
self.assertEquals(len(child_sites), 7)
self.assertEquals(len(site_ancestors), 5)
self.assertEquals(len([v for v in child_sites.values() if v is None]), 0)
self.assertEquals(child_sites['Org_1']._get_type(), RT.Org)
示例2: test_get_device_data_products
def test_get_device_data_products(self):
self.mu.load_mock_resources(self.res_list + self.res_list1)
self.mu.load_mock_associations(self.assoc_list + self.assoc_list1 + self.assoc_list2 + self.assoc_list3)
self.mu.assign_mockres_find_objects(filter_predicate="hasResource")
self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock)
res_dict = self.obs_util.get_site_data_products('Obs_1', RT.Observatory)
self.assertGreaterEqual(len(res_dict), 6)
self.assertIsNone(res_dict['data_product_resources'])
self.assertIn('ID_1', res_dict['device_data_products'])
self.assertEquals(len(res_dict['device_data_products']['ID_1']), 3)
self.assertIn('DP_1', res_dict['device_data_products']['ID_1'])
self.assertIn('PD_1', res_dict['device_data_products'])
self.assertEquals(len(res_dict['device_data_products']['PD_1']), 3)
res_dict = self.obs_util.get_site_data_products('PS_1', RT.PlatformSite)
self.assertEquals(len(res_dict['device_data_products']['ID_1']), 3)
self.assertIn('ID_1', res_dict['device_data_products'])
self.assertIn('DP_1', res_dict['device_data_products']['ID_1'])
self.assertIn('PD_1', res_dict['device_data_products'])
self.assertEquals(len(res_dict['device_data_products']['PD_1']), 3)
res_dict = self.obs_util.get_site_data_products('Org_1', RT.Org)
self.assertIn('DP_1', res_dict['device_data_products']['ID_1'])
res_dict = self.obs_util.get_site_data_products('PS_1', RT.PlatformSite, include_data_products=True)
self.assertIsNotNone(res_dict['data_product_resources'])
self.assertIn('DP_1', res_dict['data_product_resources'])
示例3: on_init
def on_init(self):
resource_collector_factory = DeploymentResourceCollectorFactory(self.clients, self.RR2)
self.resource_collector = resource_collector_factory.create(self.deployment_obj)
self._hasdevice_associations_to_delete = []
self._hasdevice_associations_to_create = []
self.outil = ObservatoryUtil(self, enhanced_rr=self.RR2)
示例4: __init__
def __init__(self, clients=None, enhanced_rr=None):
self.clients = clients
self.enhanced_rr = enhanced_rr
if not enhanced_rr:
self.enhanced_rr = EnhancedResourceRegistryClient(self.clients.resource_registry)
self.outil = ObservatoryUtil(self, enhanced_rr=self.enhanced_rr)
示例5: test_get_status_roll_ups_platform_warn
def test_get_status_roll_ups_platform_warn(self):
self.mu.load_mock_resources(self.res_list)
self.mu.load_mock_associations(self.assoc_list + self.assoc_list1 + self.assoc_list2)
self.mu.load_mock_device_statuses(self.status_by_device_4)
self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock, device_status_mgr=self.dsm_mock)
# PD_1 power+comms warning
status_rollups = self.obs_util.get_status_roll_ups('ID_1', RT.InstrumentDevice)
self._assert_status(status_rollups, 'ID_1')
status_rollups = self.obs_util.get_status_roll_ups('PD_1', RT.PlatformDevice)
#log.warn("status %s" % status_rollups)
self._assert_status(status_rollups, 'PD_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'ID_1')
status_rollups = self.obs_util.get_status_roll_ups('IS_1', RT.InstrumentSite)
self.assertEquals(len(status_rollups), 6)
self.assertIn('IS_1', status_rollups)
self.assertIn('ID_1', status_rollups)
self._assert_status(status_rollups, 'IS_1')
self._assert_status(status_rollups, 'ID_1')
status_rollups = self.obs_util.get_status_roll_ups('PS_1', RT.PlatformSite)
self.assertEquals(len(status_rollups), 6)
self.assertIn('PS_1', status_rollups)
self.assertIn('PD_1', status_rollups)
self.assertIn('IS_1', status_rollups)
self.assertIn('ID_1', status_rollups)
self._assert_status(status_rollups, 'PS_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'PD_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'IS_1')
self._assert_status(status_rollups, 'ID_1')
status_rollups = self.obs_util.get_status_roll_ups('Sub_1', RT.Subsite)
self.assertIn('Sub_1', status_rollups)
self.assertIn('PS_1', status_rollups)
self.assertIn('PD_1', status_rollups)
self.assertIn('IS_1', status_rollups)
self.assertIn('ID_1', status_rollups)
self._assert_status(status_rollups, 'Sub_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'PS_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'PD_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'IS_1')
self._assert_status(status_rollups, 'ID_1')
status_rollups = self.obs_util.get_status_roll_ups('Obs_1', RT.Observatory)
self.assertIn('Obs_1', status_rollups)
self.assertIn('Sub_1', status_rollups)
self.assertIn('PS_1', status_rollups)
self.assertIn('PD_1', status_rollups)
self.assertIn('IS_1', status_rollups)
self.assertIn('ID_1', status_rollups)
self._assert_status(status_rollups, 'Obs_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'Sub_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'PS_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'PD_1', agg=DST.STATUS_WARNING, power=DST.STATUS_WARNING, comms=DST.STATUS_WARNING)
self._assert_status(status_rollups, 'IS_1')
self._assert_status(status_rollups, 'ID_1')
示例6: test_get_site_devices
def test_get_site_devices(self):
self.mu.load_mock_resources(self.res_list)
self.mu.load_mock_associations(self.assoc_list2)
self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock)
site_devices = self.obs_util.get_site_devices(['Sub_1', 'PS_1', 'IS_1'])
self.assertEquals(len(site_devices), 3)
self.assertEquals(site_devices['Sub_1'], [])
self.assertEquals(site_devices['IS_1'], [('InstrumentSite', 'ID_1', 'InstrumentDevice')])
示例7: test_get_child_sites
def test_get_child_sites(self):
self.mu.load_mock_resources(self.res_list)
self.mu.load_mock_associations(self.assoc_list)
self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Obs_1', include_parents=False, id_only=True)
self.assertEquals(len(site_resources), 3)
self.assertEquals(len(site_children), 3)
self.assertIn('Sub_1', site_resources)
self.assertIn('PS_1', site_resources)
self.assertIn('IS_1', site_resources)
self.assertNotIn('Obs_1', site_resources)
self.assertEquals(len([v for v in site_resources.values() if v is None]), 3)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Obs_1', include_parents=False, id_only=False)
self.assertEquals(len(site_resources), 3)
self.assertEquals(len(site_children), 3)
self.assertEquals(len([v for v in site_resources.values() if v is None]), 0)
self.assertEquals(site_resources['Sub_1']._get_type(), RT.Subsite)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Obs_1', include_parents=True)
self.assertEquals(len(site_resources), 4)
self.assertEquals(len(site_children), 3)
self.assertIn('Obs_1', site_resources)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Sub_1', include_parents=False)
self.assertEquals(len(site_resources), 2)
self.assertEquals(len(site_children), 2)
self.assertNotIn('Sub_1', site_resources)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Sub_1', include_parents=True)
self.assertEquals(len(site_resources), 4)
self.assertEquals(len(site_children), 3)
self.assertIn('Sub_1', site_resources)
self.assertIn('Obs_1', site_resources)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='PS_1', include_parents=False)
self.assertEquals(len(site_resources), 1)
self.assertEquals(len(site_children), 1)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='PS_1', include_parents=True)
self.assertEquals(len(site_resources), 4)
self.assertEquals(len(site_children), 3)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='IS_1', include_parents=False)
self.assertEquals(len(site_resources), 0)
self.assertEquals(len(site_children), 0)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='IS_1', include_parents=True)
self.assertEquals(len(site_resources), 4)
self.assertEquals(len(site_children), 3)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='XXX', include_parents=True)
self.assertEquals(len(site_resources), 1)
self.assertEquals(len(site_children), 0)
示例8: _notification_children
def _notification_children(notification_origin, notification_type, observatory_util=None):
if observatory_util is None:
observatory_util = ObservatoryUtil()
children = []
if notification_type == NotificationTypeEnum.PLATFORM:
device_relations = observatory_util.get_child_devices(notification_origin)
children = [did for pt,did,dt in device_relations[notification_origin]]
elif type == NotificationTypeEnum.SITE:
child_site_dict, ancestors = observatory_util.get_child_sites(notification_origin)
children = child_site_dict.keys()
elif type == NotificationTypeEnum.FACILITY:
objects, _ = resource_registry.find_objects(subject=notification_origin, predicate=PRED.hasResource, id_only=False)
for o in objects:
if o.type_ == RT.DataProduct \
or o.type_ == RT.InstrumentSite \
or o.type_ == RT.InstrumentDevice \
or o.type_ == RT.PlatformSite \
or o.type_ == RT.PlatformDevice:
children.append(o._id)
if notification_origin in children:
children.remove(notification_origin)
return children
示例9: prepare_activation
def prepare_activation(self, deployment_obj):
"""
Prepare (validate) a deployment for activation, returning lists of what associations need to be added
and which ones need to be removed.
"""
self.match_list = []
self.remove_list = []
self.unmatched_device_list = []
self.models_map = {}
self.top_device = ''
self.top_site = ''
self.deployment_obj = deployment_obj
self.site_resources = {}
self.device_resources = {}
self.outil = ObservatoryUtil(self, enhanced_rr=self.enhanced_rr)
# retrieve the site tree information using the OUTIL functions; site info as well has site children
self.top_site, self.top_device = self._find_top_site_device(deployment_obj._id)
# must have a site and a device to continue
if not self.top_site or not self.top_device:
return [], []
log.debug("port_assignments: %s", self.deployment_obj.port_assignments )
# retrieve all models to use in match validation
self._get_models()
self.site_resources, site_children = self.outil.get_child_sites( parent_site_id=self.top_site._id, id_only=False)
log.debug("site_resources: %s", self.site_resources)
log.debug("site_children: %s", site_children)
site_ref_designator_map = self._get_site_ref_designator_map()
# retrieve the device tree from outil then cache the device resources
device_tree = self.outil.get_child_devices(device_id=self.top_device._id)
self._get_device_resources(device_tree)
self._match_devices(self.top_device._id, device_tree, site_ref_designator_map)
# check for hasDevice relations to remove and existing hasDevice relations
self. _find_pairs_to_remove()
if self.unmatched_device_list:
log.warning("Devices not matched to sites: %s ", self.unmatched_device_list)
return self.remove_list, self.match_list
示例10: on_init
def on_init(self):
IonObject("Resource") # suppress pyflakes error
CFG, log, RT, PRED, LCS, LCE, NotFound, BadRequest, log #suppress pyflakes errors about "unused import"
self.override_clients(self.clients)
self.outil = ObservatoryUtil(self)
self.HIERARCHY_DEPTH = {RT.InstrumentSite: 3,
RT.PlatformSite: 2,
RT.Subsite: 1,
RT.Observatory: 0,
}
self.HIERARCHY_LOOKUP = [RT.Observatory,
RT.Subsite,
RT.PlatformSite,
RT.InstrumentSite]
示例11: get_deployment_sites_devices
def get_deployment_sites_devices(self, deployment_obj):
# retrieve all site and device ids related to this deployment
site_ids = []
device_ids = []
self.outil = ObservatoryUtil(self, enhanced_rr=self.enhanced_rr)
top_site, top_device = self._find_top_site_device(deployment_obj._id)
site_resources, site_children = self.outil.get_child_sites( parent_site_id=top_site._id, id_only=False)
site_ids = site_resources.keys()
# get_site_devices returns a tuple that includes all devices linked to deployment sites
site_devices = self.outil.get_site_devices(site_ids)
for site, tuple_list in site_devices.iteritems():
for (site_type, device_id, device_type) in tuple_list:
device_ids.append(device_id)
return site_ids, device_ids
示例12: test_get_child_devices
def test_get_child_devices(self):
self.mu.load_mock_resources(self.res_list)
self.mu.load_mock_associations(self.assoc_list2)
self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock)
child_devices = self.obs_util.get_child_devices('PD_1')
self.assertEquals(len(child_devices), 2)
self.assertEquals(child_devices['PD_1'][0][1], 'ID_1')
child_devices = self.obs_util.get_child_devices('ID_1')
self.assertEquals(len(child_devices), 1)
self.assertEquals(child_devices['ID_1'], [])
child_devices = self.obs_util.get_child_devices('Sub_1')
self.assertEquals(len(child_devices), 1)
self.assertEquals(child_devices['Sub_1'], [])
child_devices = self.obs_util.get_child_devices('XXX')
self.assertEquals(len(child_devices), 1)
示例13: ObservatoryManagementService
class ObservatoryManagementService(BaseObservatoryManagementService):
def on_init(self):
IonObject("Resource") # suppress pyflakes error
CFG, log, RT, PRED, LCS, LCE, NotFound, BadRequest, log #suppress pyflakes errors about "unused import"
self.override_clients(self.clients)
self.outil = ObservatoryUtil(self)
self.HIERARCHY_DEPTH = {RT.InstrumentSite: 3,
RT.PlatformSite: 2,
RT.Subsite: 1,
RT.Observatory: 0,
}
self.HIERARCHY_LOOKUP = [RT.Observatory,
RT.Subsite,
RT.PlatformSite,
RT.InstrumentSite]
#todo: add lcs methods for these??
# # set up all of the policy interceptions
# if self.container and self.container.governance_controller:
# reg_precondition = self.container.governance_controller.register_process_operation_precondition
# reg_precondition(self, 'execute_observatory_lifecycle',
# self.RR2.policy_fn_lcs_precondition("observatory_id"))
# reg_precondition(self, 'execute_subsite_lifecycle',
# self.RR2.policy_fn_lcs_precondition("subsite_id"))
# reg_precondition(self, 'execute_platform_site_lifecycle',
# self.RR2.policy_fn_lcs_precondition("platform_site_id"))
# reg_precondition(self, 'execute_instrument_site_lifecycle',
# self.RR2.policy_fn_lcs_precondition("instrument_site_id"))
def override_clients(self, new_clients):
"""
Replaces the service clients with a new set of them... and makes sure they go to the right places
"""
self.RR2 = EnhancedResourceRegistryClient(new_clients.resource_registry)
#shortcut names for the import sub-services
if hasattr(new_clients, "resource_registry"):
self.RR = new_clients.resource_registry
if hasattr(new_clients, "instrument_management"):
self.IMS = new_clients.instrument_management
if hasattr(new_clients, "data_process_management"):
self.PRMS = new_clients.data_process_management
#farm everything out to the impls
self.dataproductclient = DataProductManagementServiceClient()
self.dataprocessclient = DataProcessManagementServiceClient()
def _calc_geospatial_point_center(self, site):
siteTypes = [RT.Site, RT.Subsite, RT.Observatory, RT.PlatformSite, RT.InstrumentSite]
if site and site.type_ in siteTypes:
# if the geospatial_bounds is set then calculate the geospatial_point_center
for constraint in site.constraint_list:
if constraint.type_ == OT.GeospatialBounds:
site.geospatial_point_center = GeoUtils.calc_geospatial_point_center(constraint)
##########################################################################
#
# CRUD OPS
#
##########################################################################
def create_marine_facility(self, org=None):
"""Create an Org (domain of authority) that realizes a marine facility. This Org will have
set up roles for a marine facility. Shared resources, such as a device can only be
registered in one marine facility Org, and additionally in many virtual observatory Orgs. The
marine facility operators will have more extensive permissions and will supercede virtual
observatory commands
@param org Org
@retval org_id str
@throws BadRequest if object does not have _id or _rev attribute
@throws NotFound object with specified id does not exist
"""
log.debug("ObservatoryManagementService.create_marine_facility(): %s", org)
# create the org
org.org_type = OrgTypeEnum.MARINE_FACILITY
org_id = self.clients.org_management.create_org(org)
#Instantiate initial set of User Roles for this marine facility
instrument_operator_role = IonObject(RT.UserRole,
governance_name=INSTRUMENT_OPERATOR_ROLE,
name='Observatory Operator', #previously Instrument Operator
description='Operate and post events related to Observatory Platforms and Instruments')
self.clients.org_management.add_user_role(org_id, instrument_operator_role)
observatory_operator_role = IonObject(RT.UserRole,
#.........这里部分代码省略.........
示例14: TestObservatoryUtil
class TestObservatoryUtil(IonUnitTestCase):
def setUp(self):
self.mu = MockUtil()
self.process_mock = self.mu.create_process_mock()
self.container_mock = self.mu.create_container_mock()
self.dsm_mock = self.mu.create_device_status_manager_mock()
res_list = [
dict(rt='Org', _id='Org_1', attr={}),
dict(rt='Observatory', _id='Obs_1', attr={}),
dict(rt='Observatory', _id='Obs_2', attr={}),
dict(rt='Subsite', _id='Sub_1', attr={}),
dict(rt='Subsite', _id='Sub_2', attr={}),
dict(rt='PlatformSite', _id='PS_1', attr={}),
dict(rt='InstrumentSite', _id='IS_1', attr={}),
dict(rt='PlatformDevice', _id='PD_1', attr={}),
dict(rt='InstrumentDevice', _id='ID_1', attr={}),
]
assoc_list = [
['Obs_1', 'hasSite', 'Sub_1'],
['Sub_1', 'hasSite', 'PS_1'],
['PS_1', 'hasSite', 'IS_1'],
]
assoc_list1 = [
['Org_1', 'hasResource', 'Obs_1'],
['Org_1', 'hasResource', 'Obs_2'],
['Obs_2', 'hasSite', 'Sub_2'],
]
assoc_list2 = [
['PS_1', 'hasDevice', 'PD_1'],
['IS_1', 'hasDevice', 'ID_1'],
['PD_1', 'hasDevice', 'ID_1'],
]
def spy_get_child_sites(self, parent_site_id=None, org_id=None, exclude_types=None, include_parents=True, id_only=True):
child_sites, site_ancestors = self.obs_util.get_child_sites(parent_site_id=parent_site_id,
org_id=org_id,
exclude_types=exclude_types,
include_parents=include_parents,
id_only=id_only)
print "child_sites of", parent_site_id, "are", child_sites
print "site_ancestors of", parent_site_id, "are", site_ancestors
return child_sites, site_ancestors
def test_get_child_sites(self):
self.mu.load_mock_resources(self.res_list)
self.mu.load_mock_associations(self.assoc_list)
self.obs_util = ObservatoryUtil(self.process_mock, self.container_mock)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Obs_1', include_parents=False, id_only=True)
self.assertEquals(len(site_resources), 3)
self.assertEquals(len(site_children), 3)
self.assertIn('Sub_1', site_resources)
self.assertIn('PS_1', site_resources)
self.assertIn('IS_1', site_resources)
self.assertNotIn('Obs_1', site_resources)
self.assertEquals(len([v for v in site_resources.values() if v is None]), 3)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Obs_1', include_parents=False, id_only=False)
self.assertEquals(len(site_resources), 3)
self.assertEquals(len(site_children), 3)
self.assertEquals(len([v for v in site_resources.values() if v is None]), 0)
self.assertEquals(site_resources['Sub_1']._get_type(), RT.Subsite)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Obs_1', include_parents=True)
self.assertEquals(len(site_resources), 4)
self.assertEquals(len(site_children), 3)
self.assertIn('Obs_1', site_resources)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Sub_1', include_parents=False)
self.assertEquals(len(site_resources), 2)
self.assertEquals(len(site_children), 2)
self.assertNotIn('Sub_1', site_resources)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='Sub_1', include_parents=True)
self.assertEquals(len(site_resources), 4)
self.assertEquals(len(site_children), 3)
self.assertIn('Sub_1', site_resources)
self.assertIn('Obs_1', site_resources)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='PS_1', include_parents=False)
self.assertEquals(len(site_resources), 1)
self.assertEquals(len(site_children), 1)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='PS_1', include_parents=True)
self.assertEquals(len(site_resources), 4)
self.assertEquals(len(site_children), 3)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='IS_1', include_parents=False)
self.assertEquals(len(site_resources), 0)
self.assertEquals(len(site_children), 0)
site_resources, site_children = self.spy_get_child_sites(parent_site_id='IS_1', include_parents=True)
#.........这里部分代码省略.........
示例15: _process_cmd_sites
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