Additional Volume info
Change-Id: I796232982957c19774a54d3417f1475640a66960
This commit is contained in:
parent
90da3e6354
commit
b49414adef
19
vitrage/datasources/cinder/volume/properties.py
Normal file
19
vitrage/datasources/cinder/volume/properties.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Copyright 2016 - Nokia
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
class CinderProperties(object):
|
||||
SIZE = 'size'
|
||||
VOLUME_TYPE = 'volume_type'
|
||||
ATTACHMENTS = 'attachments'
|
@ -20,6 +20,8 @@ from vitrage.common.constants import EntityCategory
|
||||
from vitrage.common.constants import EventAction
|
||||
from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE
|
||||
from vitrage.datasources.cinder.volume.properties import \
|
||||
CinderProperties as CinderProps
|
||||
from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
|
||||
from vitrage.datasources.resource_transformer_base import \
|
||||
ResourceTransformerBase
|
||||
@ -52,13 +54,20 @@ class CinderVolumeTransformer(ResourceTransformerBase):
|
||||
volume_state = extract_field_value(entity_event, 'status')
|
||||
project_id = entity_event.get('os-vol-tenant-attr:tenant_id', None)
|
||||
timestamp = extract_field_value(entity_event, 'created_at')
|
||||
size = extract_field_value(entity_event, 'size')
|
||||
volume_type = extract_field_value(entity_event, 'volume_type')
|
||||
attachments = extract_field_value(entity_event, 'attachments')
|
||||
|
||||
return self._create_vertex(entity_event,
|
||||
volume_name,
|
||||
volume_id,
|
||||
volume_state,
|
||||
project_id,
|
||||
timestamp)
|
||||
timestamp,
|
||||
size,
|
||||
volume_type,
|
||||
attachments,
|
||||
'server_id')
|
||||
|
||||
def _create_update_entity_vertex(self, entity_event):
|
||||
|
||||
@ -67,13 +76,20 @@ class CinderVolumeTransformer(ResourceTransformerBase):
|
||||
volume_state = extract_field_value(entity_event, 'status')
|
||||
project_id = entity_event.get('tenant_id', None)
|
||||
timestamp = entity_event.get('updated_at', None)
|
||||
size = extract_field_value(entity_event, 'size')
|
||||
volume_type = extract_field_value(entity_event, 'volume_type')
|
||||
attachments = extract_field_value(entity_event, 'volume_attachment')
|
||||
|
||||
return self._create_vertex(entity_event,
|
||||
volume_name,
|
||||
volume_id,
|
||||
volume_state,
|
||||
project_id,
|
||||
timestamp)
|
||||
timestamp,
|
||||
size,
|
||||
volume_type,
|
||||
attachments,
|
||||
'instance_uuid')
|
||||
|
||||
def _create_vertex(self,
|
||||
entity_event,
|
||||
@ -81,10 +97,23 @@ class CinderVolumeTransformer(ResourceTransformerBase):
|
||||
volume_id,
|
||||
volume_state,
|
||||
project_id,
|
||||
update_timestamp):
|
||||
update_timestamp,
|
||||
volume_size,
|
||||
volume_type,
|
||||
attachments,
|
||||
server_id_key):
|
||||
|
||||
server_ids = []
|
||||
|
||||
for attachment in attachments:
|
||||
server_ids.append((attachment[server_id_key]))
|
||||
|
||||
metadata = {
|
||||
VProps.NAME: volume_name,
|
||||
VProps.PROJECT_ID: project_id,
|
||||
CinderProps.SIZE: volume_size,
|
||||
CinderProps.VOLUME_TYPE: volume_type,
|
||||
CinderProps.ATTACHMENTS: tuple(server_ids)
|
||||
}
|
||||
|
||||
entity_key = self._create_entity_key(entity_event)
|
||||
|
@ -142,6 +142,8 @@ class Processor(processor.ProcessorBase):
|
||||
|
||||
for neighbor in neighbors:
|
||||
# TODO(Alexey): maybe to check if the vertices exists
|
||||
if entity_vertex is not None:
|
||||
self.entity_graph.update_vertex(entity_vertex)
|
||||
self.entity_graph.update_edge(neighbor.edge)
|
||||
|
||||
def delete_relationship(self, updated_vertex, neighbors):
|
||||
@ -151,6 +153,8 @@ class Processor(processor.ProcessorBase):
|
||||
graph_edge = self.entity_graph.get_edge(neighbor.edge.source_id,
|
||||
neighbor.edge.target_id,
|
||||
neighbor.edge.label)
|
||||
if updated_vertex is not None:
|
||||
self.entity_graph.update_vertex(updated_vertex)
|
||||
if graph_edge:
|
||||
self.entity_graph.remove_edge(graph_edge)
|
||||
|
||||
|
@ -6,5 +6,7 @@
|
||||
"id": "12345",
|
||||
"sync_type": "cinder\\.volume",
|
||||
"sync_mode": "snapshot",
|
||||
"sample_date": "2015-12-01T12:46:41Z"
|
||||
"sample_date": "2015-12-01T12:46:41Z",
|
||||
"volume_type": "lvmdriver-1",
|
||||
"size": "1559"
|
||||
}
|
||||
|
@ -7,5 +7,7 @@
|
||||
"sync_type": "cinder\\.volume",
|
||||
"sync_mode": "update",
|
||||
"event_type": "volume.create.start",
|
||||
"sample_date": "2015-12-01T12:46:41Z"
|
||||
"sample_date": "2015-12-01T12:46:41Z",
|
||||
"volume_type": "SCSIID",
|
||||
"size": "1559"
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ from vitrage.common.constants import EntityCategory
|
||||
from vitrage.common.constants import UpdateMethod
|
||||
from vitrage.common.constants import VertexProperties as VProps
|
||||
from vitrage.datasources.cinder.volume import CINDER_VOLUME_DATASOURCE
|
||||
from vitrage.datasources.cinder.volume.properties \
|
||||
import CinderProperties as CinderProps
|
||||
from vitrage.datasources.cinder.volume.transformer \
|
||||
import CinderVolumeTransformer
|
||||
from vitrage.datasources.nova.instance import NOVA_INSTANCE_DATASOURCE
|
||||
@ -180,6 +182,16 @@ class TestCinderVolumeTransformer(base.BaseTest):
|
||||
tbase.extract_field_value(event, state_field_path),
|
||||
vertex[VProps.STATE])
|
||||
|
||||
size_field_path = 'size'
|
||||
self.assertEqual(
|
||||
tbase.extract_field_value(event, size_field_path),
|
||||
vertex[CinderProps.SIZE])
|
||||
|
||||
volume_type_field_path = 'volume_type'
|
||||
self.assertEqual(
|
||||
tbase.extract_field_value(event, volume_type_field_path),
|
||||
vertex[CinderProps.VOLUME_TYPE])
|
||||
|
||||
self.assertFalse(vertex[VProps.IS_PLACEHOLDER])
|
||||
self.assertFalse(vertex[VProps.IS_DELETED])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user