本文整理汇总了Python中ion.services.sa.observatory.observatory_util.ObservatoryUtil.get_site_devices方法的典型用法代码示例。如果您正苦于以下问题:Python ObservatoryUtil.get_site_devices方法的具体用法?Python ObservatoryUtil.get_site_devices怎么用?Python ObservatoryUtil.get_site_devices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ion.services.sa.observatory.observatory_util.ObservatoryUtil
的用法示例。
在下文中一共展示了ObservatoryUtil.get_site_devices方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DeploymentPlanner
# 需要导入模块: from ion.services.sa.observatory.observatory_util import ObservatoryUtil [as 别名]
# 或者: from ion.services.sa.observatory.observatory_util.ObservatoryUtil import get_site_devices [as 别名]
#.........这里部分代码省略.........
# validate port_type based on deployment context
# a platform device deployment should have UPLINK port type
if OT.RemotePlatformDeploymentContext == deployment_context_type or \
OT.CabledNodeDeploymentContext == deployment_context_type:
if device_id in self.device_resources and self.device_resources[device_id].type_ is RT.PlatformDevice:
if platform_port.port_type != PortTypeEnum.UPLINK:
log.warning('Type of port for platform port assignment should be UPLINK. Device id: %s', device_id)
#validate that parent_id is provided
if not platform_port.parent_id:
log.warning('Id of parent device should be provided in port assignment information. Device id: %s', device_id)
def _validate_ooi_reference_designator(self, device_id, device_port):
ooi_rd = OOIReferenceDesignator(device_port.reference_designator)
if ooi_rd.error:
log.warning("Invalid OOIReferenceDesignator ( %s ) specified for device %s", device_port.reference_designator, device_id)
if not ooi_rd.port:
log.warning("Invalid OOIReferenceDesignator ( %s ) specified for device %s, could not retrieve port", device_port.reference_designator, device_id)
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
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 [], []
示例2: TestObservatoryUtil
# 需要导入模块: from ion.services.sa.observatory.observatory_util import ObservatoryUtil [as 别名]
# 或者: from ion.services.sa.observatory.observatory_util.ObservatoryUtil import get_site_devices [as 别名]
#.........这里部分代码省略.........
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)
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)
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')])
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)
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)
示例3: TestObservatoryUtil
# 需要导入模块: from ion.services.sa.observatory.observatory_util import ObservatoryUtil [as 别名]
# 或者: from ion.services.sa.observatory.observatory_util.ObservatoryUtil import get_site_devices [as 别名]
#.........这里部分代码省略.........
self.assertEquals(len(site_ancestors), 3)
child_sites, site_ancestors = self.spy_get_child_sites(parent_site_id='XXX', include_parents=True)
self.assertEquals(len(child_sites), 1)
self.assertEquals(len(site_ancestors), 0)
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)
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')])
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), 1)
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)
event_list1 = [
dict(et='DeviceStatusEvent', o='ID_1', attr=dict(status=DeviceStatusType.STATUS_WARNING) )
]