gnocchi: Add volume_type attribute to volume

Change-Id: I3b968d35dc30122756abdbabd96424fc8e587d25
Co-Authored-By: zhangguoqing <zhang.guoqing@99cloud.net>
This commit is contained in:
Mehdi Abaakouk 2016-11-21 09:17:02 +01:00 committed by Mehdi Abaakouk (sileht)
parent f8d1f602a7
commit 970358ce5e
2 changed files with 23 additions and 4 deletions

View File

@ -188,6 +188,7 @@ resources:
event_delete: volume.delete.start
event_attributes:
id: resource_id
volume_type: resource_metadata.volume_type
- resource_type: host
metrics:

View File

@ -97,6 +97,18 @@ resources_initial = {
},
}
# NOTE(sileht): Order matter this have to be considered like alembic migration
# code, because it updates the resources schema of Gnocchi
resources_update_operation = [
{"desc": "add volume_type to volume",
"type": "update_attribute_type",
"resource_type": "volume",
"data": {
"attribute": "/attributes/volume_type",
"value": {"type": "string", "min_length": 0, "max_length": 255,
"required": False}}},
]
def upgrade_resource_types(conf):
gnocchi = get_gnocchiclient(conf)
@ -109,7 +121,13 @@ def upgrade_resource_types(conf):
gnocchi.resource_type.create(resource_type=rt)
except Exception:
LOG.error("Gnocchi resource creation fail", exc_info=True)
else:
# NOTE(sileht): We have to handle this case when it will be
# possible to add/rm resource-types columns
pass
return
for op in resources_update_operation:
if op['type'] == 'update_attribute_type':
try:
gnocchi.resource_type.update(op['resource_type'], op['data'])
except Exception:
LOG.error("Gnocchi resource update fail: %s", op['desc'],
exc_info=True)
return