本文整理汇总了Python中vitrage.datasources.transformer_base.extract_field_value函数的典型用法代码示例。如果您正苦于以下问题:Python extract_field_value函数的具体用法?Python extract_field_value怎么用?Python extract_field_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了extract_field_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_snapshot_entity_vertex
def _create_snapshot_entity_vertex(self, entity_event):
name = extract_field_value(entity_event, "name")
entity_id = extract_field_value(entity_event, "id")
state = extract_field_value(entity_event, "status")
return self._create_vertex(entity_event, name, entity_id, state)
示例2: _create_nova_zone_neighbors
def _create_nova_zone_neighbors(self, entity_event):
zone_vertex_id = self._create_entity_key(entity_event)
neighbors = [self._create_cluster_neighbor(zone_vertex_id)]
hosts = extract_field_value(entity_event, 'hosts')
host_transformer = self.transformers[NOVA_HOST_DATASOURCE]
if host_transformer:
for hostname, host_data in hosts.items():
host_available = extract_field_value(host_data,
'nova-compute',
'available')
host_active = extract_field_value(host_data,
'nova-compute',
'active')
host_state = self.STATE_AVAILABLE \
if host_available and host_active \
else self.STATE_UNAVAILABLE
host_neighbor = self._create_host_neighbor(
zone_vertex_id,
hostname,
host_state,
entity_event[DSProps.SAMPLE_DATE])
neighbors.append(host_neighbor)
else:
LOG.warning('Cannot find host transformer')
return neighbors
示例3: _create_vertex
def _create_vertex(self, entity_event, name, entity_id, state):
project = extract_field_value(entity_event, 'tenant_id')
metadata = {
VProps.NAME: name,
VProps.PROJECT_ID: project
}
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
# TODO(Alexey): need to check here that only the UPDATE sync_mode will
# update the UPDATE_TIMESTAMP property
update_timestamp = self._format_update_timestamp(
extract_field_value(entity_event, DSProps.SAMPLE_DATE),
sample_timestamp)
return graph_utils.create_vertex(
self._create_entity_key(entity_event),
entity_id=entity_id,
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE,
entity_state=state,
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
metadata=metadata)
示例4: _create_update_entity_vertex
def _create_update_entity_vertex(self, entity_event):
name = extract_field_value(entity_event, 'hostname')
entity_id = extract_field_value(entity_event, 'instance_id')
state = extract_field_value(entity_event, 'state')
return self._create_vertex(entity_event, name, entity_id, state)
示例5: _validate_host_neighbor
def _validate_host_neighbor(self, host_neighbor, zone_vertex_id, hosts, datasource_action):
host_vertex = host_neighbor.vertex
host_vertex_id = host_vertex.get(VertexProperties.ID)
host_dic = hosts[host_vertex_id]
self.assertIsNotNone(hosts[host_vertex_id])
host_available = tbase.extract_field_value(host_dic, "nova-compute", "available")
host_active = tbase.extract_field_value(host_dic, "nova-compute", "active")
if host_available and host_active:
expected_host_state = ZoneTransformer.STATE_AVAILABLE
else:
expected_host_state = ZoneTransformer.STATE_UNAVAILABLE
self.assertEqual(expected_host_state, host_vertex.get(VertexProperties.STATE))
is_placeholder = host_vertex[VertexProperties.IS_PLACEHOLDER]
self.assertFalse(is_placeholder)
is_deleted = host_vertex[VertexProperties.IS_DELETED]
self.assertFalse(is_deleted)
# Validate neighbor edge
edge = host_neighbor.edge
self.assertEqual(edge.target_id, host_neighbor.vertex.vertex_id)
self.assertEqual(edge.source_id, zone_vertex_id)
self.assertEqual(edge.label, EdgeLabel.CONTAINS)
示例6: _validate_volume_vertex_props
def _validate_volume_vertex_props(self, vertex, event):
is_update_event = tbase.is_update_event(event)
self.assertEqual(EntityCategory.RESOURCE, vertex[VProps.CATEGORY])
self.assertEqual(event[DSProps.SYNC_TYPE], vertex[VProps.TYPE])
id_field_path = 'volume_id' if is_update_event else 'id'
self.assertEqual(
tbase.extract_field_value(event, id_field_path),
vertex[VProps.ID])
self.assertEqual(event[DSProps.SAMPLE_DATE],
vertex[VProps.SAMPLE_TIMESTAMP])
name_field_path = 'display_name'
self.assertEqual(
tbase.extract_field_value(event, name_field_path),
vertex[VProps.NAME])
state_field_path = 'status'
self.assertEqual(
tbase.extract_field_value(event, state_field_path),
vertex[VProps.STATE])
self.assertFalse(vertex[VProps.IS_PLACEHOLDER])
self.assertFalse(vertex[VProps.IS_DELETED])
示例7: _create_snapshot_entity_vertex
def _create_snapshot_entity_vertex(self, entity_event):
zone_name = extract_field_value(entity_event, 'zoneName')
is_available = extract_field_value(entity_event,
'zoneState',
'available')
state = self.STATE_AVAILABLE if is_available \
else self.STATE_UNAVAILABLE
return self._create_vertex(entity_event, state, zone_name)
示例8: _create_update_entity_vertex
def _create_update_entity_vertex(self, entity_event):
volume_name = extract_field_value(entity_event, 'display_name')
volume_id = extract_field_value(entity_event, 'volume_id')
volume_state = extract_field_value(entity_event, 'status')
timestamp = entity_event.get('updated_at', None)
return self._create_vertex(entity_event,
volume_name,
volume_id,
volume_state,
timestamp)
示例9: _create_snapshot_entity_vertex
def _create_snapshot_entity_vertex(self, entity_event):
volume_name = extract_field_value(entity_event, 'display_name')
volume_id = extract_field_value(entity_event, 'id')
volume_state = extract_field_value(entity_event, 'status')
timestamp = extract_field_value(entity_event, 'created_at')
return self._create_vertex(entity_event,
volume_name,
volume_id,
volume_state,
timestamp)
示例10: _create_snapshot_entity_vertex
def _create_snapshot_entity_vertex(self, entity_event):
stack_name = extract_field_value(entity_event, 'stack_name')
stack_id = extract_field_value(entity_event, 'id')
stack_state = extract_field_value(entity_event, 'stack_status')
timestamp = extract_field_value(entity_event, 'creation_time')
project_id = extract_field_value(entity_event, 'project')
return self._create_vertex(entity_event,
stack_name,
stack_id,
stack_state,
timestamp,
project_id)
示例11: _create_update_entity_vertex
def _create_update_entity_vertex(self, entity_event):
volume_name = extract_field_value(entity_event, 'stack_name')
volume_id = extract_field_value(entity_event, 'stack_identity')
volume_state = extract_field_value(entity_event, 'state')
timestamp = entity_event.get('create_at', None)
project_id = entity_event.get('tenant_id', None)
return self._create_vertex(entity_event,
volume_name,
volume_id,
volume_state,
timestamp,
project_id)
示例12: _create_entity_key
def _create_entity_key(self, entity_event):
network_id = 'network_id' if tbase.is_update_event(entity_event) \
else 'id'
key_fields = self._key_values(NEUTRON_NETWORK_DATASOURCE,
extract_field_value(entity_event,
network_id))
return tbase.build_key(key_fields)
示例13: _create_zone_neighbor
def _create_zone_neighbor(self,
entity_event,
sample_timestamp,
host_vertex_id,
zone_name_path):
zone_transformer = self.transformers[NOVA_ZONE_DATASOURCE]
if zone_transformer:
zone_name = extract_field_value(entity_event, zone_name_path)
properties = {
VProps.ID: zone_name,
VProps.TYPE: NOVA_ZONE_DATASOURCE,
VProps.SAMPLE_TIMESTAMP: sample_timestamp
}
zone_neighbor = zone_transformer.create_placeholder_vertex(
**properties)
relation_edge = graph_utils.create_edge(
source_id=zone_neighbor.vertex_id,
target_id=host_vertex_id,
relationship_type=EdgeLabel.CONTAINS)
return Neighbor(zone_neighbor, relation_edge)
else:
LOG.warning('Cannot find zone transformer')
return None
示例14: _create_entity_key
def _create_entity_key(self, entity_event):
event_type = entity_event.get(DSProps.EVENT_TYPE, None)
network_id = extract_field_value(entity_event,
*self.UPDATE_ID_PROPERTY[event_type])
key_fields = self._key_values(NEUTRON_NETWORK_DATASOURCE, network_id)
return tbase.build_key(key_fields)
示例15: _create_entity_key
def _create_entity_key(self, event):
instance_id = 'instance_id' if tbase.is_update_event(event) else 'id'
key_fields = self._key_values(NOVA_INSTANCE_DATASOURCE,
extract_field_value(event,
instance_id))
return tbase.build_key(key_fields)