本文整理汇总了Python中vitrage.graph.utils.create_vertex函数的典型用法代码示例。如果您正苦于以下问题:Python create_vertex函数的具体用法?Python create_vertex怎么用?Python create_vertex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_vertex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_aggregated_state_functionalities
def test_aggregated_state_functionalities(self):
# setup
state_manager = StateManager(self.conf)
new_vertex1 = create_vertex('12345',
entity_state='ACTIVE',
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE)
metadata2 = {VProps.VITRAGE_STATE: 'SUBOPTIMAL'}
new_vertex2 = create_vertex('23456',
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE,
metadata=metadata2)
new_vertex3 = create_vertex('34567',
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE)
graph_vertex3 = create_vertex('45678',
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE)
# action
state_manager.aggregated_state(new_vertex1,
None)
state_manager.aggregated_state(new_vertex2,
None)
state_manager.aggregated_state(new_vertex3,
graph_vertex3)
# test assertions
self.assertEqual(NormalizedResourceState.RUNNING,
new_vertex1[VProps.AGGREGATED_STATE])
self.assertEqual(NormalizedResourceState.SUBOPTIMAL,
new_vertex2[VProps.AGGREGATED_STATE])
self.assertEqual(NormalizedResourceState.UNDEFINED,
new_vertex3[VProps.AGGREGATED_STATE])
示例2: test_aggregated_state
def test_aggregated_state(self):
# setup
state_manager = DatasourceInfoMapper(self.conf)
metadata1 = {VProps.VITRAGE_STATE: 'SUSPENDED'}
new_vertex1 = create_vertex('12345',
entity_state='ACTIVE',
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE,
metadata=metadata1)
metadata2 = {VProps.VITRAGE_STATE: 'ACTIVE'}
new_vertex2 = create_vertex('23456',
entity_state='SUSPENDED',
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE,
metadata=metadata2)
# action
state_manager.aggregated_state(new_vertex1, None)
state_manager.aggregated_state(new_vertex2, None)
# test assertions
self.assertEqual('SUSPENDED', new_vertex1[VProps.AGGREGATED_STATE])
self.assertEqual(OperationalResourceState.SUBOPTIMAL,
new_vertex1[VProps.OPERATIONAL_STATE])
self.assertEqual('SUSPENDED', new_vertex2[VProps.AGGREGATED_STATE])
self.assertEqual(OperationalResourceState.SUBOPTIMAL,
new_vertex2[VProps.OPERATIONAL_STATE])
示例3: test_aggregated_state_not_normalized
def test_aggregated_state_not_normalized(self):
# setup
state_manager = StateManager(self.conf)
metadata1 = {VProps.VITRAGE_STATE: 'SUSPENDED'}
new_vertex1 = create_vertex('12345',
entity_state='ACTIVE',
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE,
metadata=metadata1)
metadata2 = {VProps.VITRAGE_STATE: 'ACTIVE'}
new_vertex2 = create_vertex('23456',
entity_state='SUSPENDED',
entity_category=EntityCategory.RESOURCE,
entity_type=NOVA_INSTANCE_DATASOURCE,
metadata=metadata2)
# action
state_manager.aggregated_state(new_vertex1, None)
state_manager.aggregated_state(new_vertex2, None)
# test assertions
self.assertEqual(NormalizedResourceState.SUSPENDED,
new_vertex1[VProps.AGGREGATED_STATE])
self.assertEqual(NormalizedResourceState.SUSPENDED,
new_vertex2[VProps.AGGREGATED_STATE])
示例4: _create_vertex
def _create_vertex(self, entity_event):
self._unify_time_format(entity_event)
update_timestamp = entity_event[ZProps.TIMESTAMP]
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(update_timestamp,
sample_timestamp)
zabbix_hostname = entity_event[ZProps.ZABBIX_RESOURCE_NAME]
vitrage_hostname = entity_event[ZProps.RESOURCE_NAME]
entity_event[ZProps.DESCRIPTION] = entity_event[ZProps.DESCRIPTION]\
.replace(zabbix_hostname, vitrage_hostname)
value = entity_event[ZProps.VALUE]
entity_state = AlarmProps.INACTIVE_STATE if \
value == TriggerValue.OK else AlarmProps.ACTIVE_STATE
metadata = {
VProps.NAME: entity_event[ZProps.DESCRIPTION],
VProps.SEVERITY: TriggerSeverity.str(
entity_event[ZProps.PRIORITY]),
VProps.RAWTEXT: entity_event[ZProps.RAWTEXT]
}
return graph_utils.create_vertex(
self._create_entity_key(entity_event),
entity_category=EntityCategory.ALARM,
entity_type=entity_event[DSProps.ENTITY_TYPE],
entity_state=entity_state,
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
metadata=metadata)
示例5: _create_entity_vertex
def _create_entity_vertex(self, entity_event):
sync_mode = entity_event['sync_mode']
host_name = extract_field_value(
entity_event,
self.HOST_NAME[sync_mode]
)
metadata = {VertexProperties.NAME: host_name}
entity_key = self.extract_key(entity_event)
timestamp = extract_field_value(
entity_event,
self.TIMESTAMP[sync_mode]
)
return graph_utils.create_vertex(
entity_key,
entity_id=host_name,
entity_category=EntityTypes.RESOURCE,
entity_type=self.HOST_TYPE,
update_timestamp=timestamp,
metadata=metadata
)
示例6: _create_vertex
def _create_vertex(self,
entity_event,
stack_name,
stack_id,
stack_state,
update_timestamp,
project_id):
metadata = {
VProps.NAME: stack_name,
VProps.PROJECT_ID: project_id,
}
entity_key = self._create_entity_key(entity_event)
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
return graph_utils.create_vertex(
entity_key,
entity_id=stack_id,
entity_category=EntityCategory.RESOURCE,
entity_type=HEAT_STACK_DATASOURCE,
entity_state=stack_state,
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
metadata=metadata)
示例7: _create_vertex
def _create_vertex(self, entity_event):
update_timestamp = datetime_utils.change_time_str_format(
entity_event[NagiosProperties.LAST_CHECK],
'%Y-%m-%d %H:%M:%S',
tbase.TIMESTAMP_FORMAT)
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
update_timestamp = self._format_update_timestamp(update_timestamp,
sample_timestamp)
severity = entity_event[NagiosProperties.STATUS]
entity_state = AlarmProps.ALARM_INACTIVE_STATE if \
severity == NagiosStatus.OK else AlarmProps.ALARM_ACTIVE_STATE
metadata = {
VProps.NAME: entity_event[NagiosProperties.SERVICE],
VProps.SEVERITY: severity,
VProps.INFO: entity_event[NagiosProperties.STATUS_INFO]
}
return graph_utils.create_vertex(
self._create_entity_key(entity_event),
entity_category=EntityCategory.ALARM,
entity_type=entity_event[DSProps.SYNC_TYPE],
entity_state=entity_state,
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
metadata=metadata)
示例8: _create_entity_vertex
def _create_entity_vertex(self, entity_event):
sync_mode = entity_event['sync_mode']
zone_name = extract_field_value(
entity_event,
self.ZONE_NAME[sync_mode]
)
metadata = {
VertexProperties.NAME: zone_name
}
entity_key = self.extract_key(entity_event)
is_available = extract_field_value(
entity_event,
self.ZONE_STATE[sync_mode]
)
state = self.STATE_AVAILABLE if is_available \
else self.STATE_UNAVAILABLE
timestamp = extract_field_value(
entity_event,
self.TIMESTAMP[sync_mode]
)
return graph_utils.create_vertex(
entity_key,
entity_id=zone_name,
entity_category=EntityTypes.RESOURCE,
entity_type=self.ZONE_TYPE,
entity_state=state,
update_timestamp=timestamp,
metadata=metadata
)
示例9: _create_vertex
def _create_vertex(self,
entity_event,
name,
entity_id,
state,
update_timestamp,
project_id):
event_type = entity_event.get(DSProps.EVENT_TYPE, None)
ip_addresses = []
if not event_type:
fixed_ips = extract_field_value(
entity_event, *self.FIXED_IPS_PROPERTY[event_type])
ip_addresses = [ip['ip_address'] for ip in fixed_ips]
metadata = {
VProps.NAME: name,
VProps.PROJECT_ID: project_id,
'ip_addresses': tuple(ip_addresses),
}
sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
return graph_utils.create_vertex(
self._create_entity_key(entity_event),
entity_id=entity_id,
entity_category=EntityCategory.RESOURCE,
entity_type=NEUTRON_PORT_DATASOURCE,
entity_state=state,
sample_timestamp=sample_timestamp,
update_timestamp=update_timestamp,
metadata=metadata)
示例10: _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)
示例11: create_placeholder_vertex
def create_placeholder_vertex(self, zone_name, timestamp):
key = base.build_key(self._key_values([zone_name]))
return graph_utils.create_vertex(
key,
entity_id=zone_name,
entity_category=EntityTypes.RESOURCE,
entity_type=self.ZONE_TYPE,
update_timestamp=timestamp,
is_placeholder=True
)
示例12: _create_alarm
def _create_alarm(vitrage_id, alarm_type):
return graph_utils.create_vertex(
vitrage_id,
entity_id=vitrage_id,
entity_category=EntityCategory.ALARM,
entity_type=alarm_type,
entity_state='active',
is_deleted=False,
sample_timestamp=utcnow(),
is_placeholder=False,
)
示例13: _create_resource
def _create_resource(vitrage_id, resource_type, project_id=None):
return graph_utils.create_vertex(
vitrage_id,
entity_id=vitrage_id,
entity_category=EntityCategory.RESOURCE,
entity_type=resource_type,
entity_state='active',
is_deleted=False,
sample_timestamp=None,
is_placeholder=False,
project_id=project_id
)
示例14: create_placeholder_vertex
def create_placeholder_vertex(self, instance_id, timestamp):
key_fields = self._key_values([instance_id])
return graph_utils.create_vertex(
base.build_key(key_fields),
entity_id=instance_id,
entity_category=EntityTypes.RESOURCE,
entity_type=self.INSTANCE_TYPE,
update_timestamp=timestamp,
is_placeholder=True
)
示例15: test_vertex_crud
def test_vertex_crud(self):
g = create_graph('test_vertex_crud')
g.add_vertex(v_node)
v = g.get_vertex(v_node.vertex_id)
self.assertEqual(v_node[VProps.ID], v[VProps.ID],
'vertex properties are saved')
self.assertEqual(v_node[VProps.CATEGORY], v[VProps.CATEGORY],
'vertex properties are saved')
self.assertEqual(v_node.vertex_id, v.vertex_id,
'vertex vertex_id is saved')
# Changing the referenced item
updated_v = v
updated_v['KUKU'] = 'KUKU'
updated_v[VProps.CATEGORY] = 'CHANGED'
# Get it again
v = g.get_vertex(v_node.vertex_id)
self.assertIsNone(v.get('KUKU', None),
'Change should not affect graph item')
self.assertFalse(v.get(EProps.IS_DELETED, None),
'Change should not affect graph item')
self.assertEqual(v_node[VProps.CATEGORY], v[VProps.CATEGORY],
'Change should not affect graph item')
# Update the graph item and see changes take place
g.update_vertex(updated_v)
# Get it again
v = g.get_vertex(v_node.vertex_id)
self.assertEqual(updated_v['KUKU'], v['KUKU'],
'Graph item should change after update')
self.assertEqual(updated_v[VProps.CATEGORY], v[VProps.CATEGORY],
'Graph item should change after update')
# check metadata
another_vertex = utils.create_vertex(
vertex_id='123', entity_id='456', entity_category=INSTANCE,
metadata={'some_meta': 'DATA'}
)
g.add_vertex(another_vertex)
v = g.get_vertex(another_vertex.vertex_id)
self.assertEqual(another_vertex[VProps.ID], v[VProps.ID],
'vertex properties are saved')
self.assertEqual(another_vertex[VProps.CATEGORY], v[VProps.CATEGORY],
'vertex properties are saved')
self.assertEqual('DATA', v['some_meta'],
'vertex properties are saved')
self.assertEqual(another_vertex.vertex_id, v.vertex_id,
'vertex vertex_id is saved')
# Remove the item
g.remove_vertex(another_vertex)
self.assertEqual(1, len(g), 'graph __len__ after remove vertex')
v = g.get_vertex(another_vertex.vertex_id)
self.assertIsNone(v, 'removed vertex not in graph')