Make the instance 'host' attribute optional
Make the ``host`` resource attribute on the ``instance`` resource type optional in Gnocchi. This allows the hypervisor a compute instance is running on to be withheld from Gnocchi's resource metadata, which may be required for security reasons e.g. for public clouds. To handle updating existing attributes, changes have been made to the ``upgrade_resource_types`` function to make it check if any existing attributes are identical to the specified schema, and update the resource type accordingly. Change-Id: I26875b876be6401164442d2f5e52e2eb9b8e703c
This commit is contained in:
@@ -218,6 +218,15 @@ resources_update_operations = [
|
||||
"value": {"type": "string", "min_length": 0, "max_length": 255,
|
||||
"required": False} # Only containers have a storage policy
|
||||
}]},
|
||||
{"desc": "make host optional for instance",
|
||||
"type": "update_attribute_type",
|
||||
"resource_type": "instance",
|
||||
"data": [{
|
||||
"op": "add", # Usually update, the attribute likely already exists
|
||||
"path": "/attributes/host",
|
||||
"value": {"type": "string", "min_length": 0, "max_length": 255,
|
||||
"required": False} # Allow the hypervisor to be withheld
|
||||
}]},
|
||||
]
|
||||
|
||||
|
||||
@@ -243,8 +252,15 @@ def upgrade_resource_types(conf):
|
||||
if ops['type'] == 'update_attribute_type':
|
||||
rt = gnocchi.resource_type.get(name=ops['resource_type'])
|
||||
first_op = ops['data'][0]
|
||||
attrib = first_op['path'].replace('/attributes', '')
|
||||
if first_op['op'] == 'add' and attrib in rt['attributes']:
|
||||
attrib = first_op['path'].replace('/attributes/', '')
|
||||
# Options are only used when adding/updating attributes.
|
||||
# Make a shallow copy of the new value type, and remove options
|
||||
# from the copy to make sure it isn't included in checks.
|
||||
value = first_op['value'].copy()
|
||||
value.pop('options', None)
|
||||
if (first_op['op'] == 'add'
|
||||
and attrib in rt['attributes']
|
||||
and value == rt['attributes'][attrib]):
|
||||
continue
|
||||
if first_op['op'] == 'remove' and attrib not in rt['attributes']:
|
||||
continue
|
||||
|
@@ -0,0 +1,7 @@
|
||||
---
|
||||
upgrade:
|
||||
- |
|
||||
The ``instance`` resource type has been updated to make the ``host``
|
||||
resource attribute optional. This allows the hypervisor a compute instance
|
||||
is running on to be withheld from Gnocchi's resource metadata, which may
|
||||
be required for security reasons e.g. for public clouds.
|
Reference in New Issue
Block a user