glance inbuilt properties made read only

Change-Id: Ie81817192ce428c327ba35ba8220d782c3f484e2
This commit is contained in:
Lakshmi N Sampath 2014-05-10 07:54:04 -07:00
parent 36b47bdb69
commit 09c98674f0
1 changed files with 51 additions and 35 deletions

View File

@ -35,6 +35,8 @@ class GlanceResourceDriver(base.ResourceInterface):
self.endpoint_type = 'publicURL' self.endpoint_type = 'publicURL'
self.default_namespace_postfix = "::Default" self.default_namespace_postfix = "::Default"
self.unknown_properties_type = "AdditionalProperties" self.unknown_properties_type = "AdditionalProperties"
self.unmodifiable_properties = [u'instance_uuid', u'image_type',
u'base_image_ref', u'image_location']
def get_resource(self, resource_type, resource_id, auth_token, def get_resource(self, resource_type, resource_id, auth_token,
endpoint_id=None, **kwargs): endpoint_id=None, **kwargs):
@ -108,7 +110,18 @@ class GlanceResourceDriver(base.ResourceInterface):
tag_name = capability.capability_type tag_name = capability.capability_type
image_properties[tag_name] = utils.TAG_IDENTIFIER image_properties[tag_name] = utils.TAG_IDENTIFIER
#Retrieve unmodifiable properties from glance
image = glance_client.images.get(resource.id) image = glance_client.images.get(resource.id)
glance_image_properties = image.properties
merge_properties = dict()
for key in glance_image_properties:
if key in self.unmodifiable_properties:
merge_properties[key] = glance_image_properties[key]
#Set unmodifiable properties in the glance input since purge_props=True
image_properties = dict(image_properties.items() +
merge_properties.items())
image.update(properties=image_properties, purge_props=True) image.update(properties=image_properties, purge_props=True)
def find_resources(self, resource_query, auth_token, def find_resources(self, resource_query, auth_token,
@ -207,46 +220,49 @@ class GlanceResourceDriver(base.ResourceInterface):
image_resource.name = image.name image_resource.name = image.name
for key in glance_image_properties: for key in glance_image_properties:
if key.count(self.separator) == 2: if key not in self.unmodifiable_properties:
(namespace, capability_type, prop_name) = key.split(".") if key.count(self.separator) == 2:
namespace = self.replace_hash_from_name(namespace) (namespace, capability_type, prop_name) = key.split(".")
capability_type = self.replace_hash_from_name(capability_type) namespace = self.replace_hash_from_name(namespace)
prop_name = self.replace_hash_from_name(prop_name) capability_type = \
else: self.replace_hash_from_name(capability_type)
prop_name = key prop_name = self.replace_hash_from_name(prop_name)
capability_type = None
namespace = None
cap_and_namespace = utils.get_qualifier(
key,
glance_image_properties[key]
)
if cap_and_namespace:
capability_type = cap_and_namespace.name
namespace = cap_and_namespace.namespace
else: else:
namespace = resource_type + self.default_namespace_postfix prop_name = key
capability_type = self.unknown_properties_type capability_type = None
namespace = None
image_property = Property() cap_and_namespace = utils.get_qualifier(
image_property.name = prop_name key,
image_property.value = glance_image_properties[key] glance_image_properties[key]
)
if cap_and_namespace:
capability_type = cap_and_namespace.name
namespace = cap_and_namespace.namespace
else:
namespace = resource_type + \
self.default_namespace_postfix
capability_type = self.unknown_properties_type
image_capability = None image_property = Property()
for capability in image_resource.capabilities: image_property.name = prop_name
if capability.capability_type_namespace == namespace and \ image_property.value = glance_image_properties[key]
capability.capability_type == capability_type:
image_capability = capability
if not image_capability: image_capability = None
image_capability = Capability() for capability in image_resource.capabilities:
image_capability.properties = {} if capability.capability_type_namespace == namespace and \
image_resource.capabilities.append(image_capability) capability.capability_type == capability_type:
image_capability = capability
image_capability.capability_type_namespace = namespace if not image_capability:
image_capability.capability_type = capability_type image_capability = Capability()
image_capability.properties[image_property.name] = \ image_capability.properties = {}
image_property.value image_resource.capabilities.append(image_capability)
image_capability.capability_type_namespace = namespace
image_capability.capability_type = capability_type
image_capability.properties[image_property.name] = \
image_property.value
return image_resource return image_resource