def extract_key(self, entity_event):

        instance_id = extract_field_value(
            entity_event,
            self.INSTANCE_ID[entity_event['sync_mode']])

        key_fields = self._key_values([instance_id])
        return base.build_key(key_fields)
    def extract_key(self, entity_event):

        host_name = extract_field_value(
            entity_event,
            self.HOST_NAME[entity_event['sync_mode']]
        )

        key_fields = self._key_values([host_name])
        return base.build_key(key_fields)
    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
        )
    def create_placeholder_vertex(self, host_name, timestamp):

        key_fields = self._key_values([host_name])

        return graph_utils.create_vertex(
            base.build_key(key_fields),
            entity_id=host_name,
            entity_category=EntityTypes.RESOURCE,
            entity_type=self.HOST_TYPE,
            update_timestamp=timestamp,
            is_placeholder=True
        )
    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
        )
    def test_build_instance_key(self):
        LOG.debug('Test build instance key')

        # Test setup
        instance_id = '456'
        expected_key = 'RESOURCE:nova.instance:%s' % instance_id

        instance_transformer = InstanceTransformer(self.transformers)
        # Test action
        key_fields = instance_transformer._key_values([instance_id])

        # Test assertions
        observed_key = tbase.build_key(key_fields)
        self.assertEqual(expected_key, observed_key)
    def _create_host_neighbor(self, zone_id, host_name, host_state, timestamp):

        host_transformer = self.transformers['nova.host']

        host_vertex = graph_utils.create_vertex(
            base.build_key(host_transformer._key_values([host_name])),
            entity_id=host_name,
            entity_category=EntityTypes.RESOURCE,
            entity_type=self.ZONE_TYPE,
            entity_state=host_state,
            update_timestamp=timestamp,
        )

        relation_edge = graph_utils.create_edge(
            source_id=zone_id,
            target_id=host_vertex.vertex_id,
            relationship_type=EdgeLabels.CONTAINS
        )
        return base.Neighbor(host_vertex, relation_edge)
    def test_extract_key(self):
        LOG.debug('Test get key from nova instance transformer')

        # Test setup
        spec_list = mock_sync.simple_instance_generators(
            host_num=1,
            vm_num=1,
            snapshot_events=1,
            update_events=0
        )
        instance_events = mock_sync.generate_random_events_list(spec_list)

        instance_transformer = InstanceTransformer(self.transformers)
        for event in instance_events:
            # Test action
            observed_key = instance_transformer.extract_key(event)

            # Test assertions
            observed_key_fields = observed_key.split(
                TransformerBase.KEY_SEPARATOR)

            self.assertEqual(EntityTypes.RESOURCE, observed_key_fields[0])
            self.assertEqual(
                InstanceTransformer.INSTANCE_TYPE,
                observed_key_fields[1]
            )

            instance_id = tbase.extract_field_value(
                event,
                instance_transformer.INSTANCE_ID[event['sync_mode']]
            )

            self.assertEqual(instance_id, observed_key_fields[2])

            key_values = instance_transformer._key_values([instance_id])
            expected_key = tbase.build_key(key_values)

            self.assertEqual(expected_key, observed_key)