updated unmapped properties handling

Change-Id: I14b0e7d06fafc38ac35967109c17af36b0dbe150
This commit is contained in:
Travis Tripp 2014-05-05 23:12:56 +00:00
parent ccc6c4683b
commit c05f99f52a
1 changed files with 28 additions and 22 deletions

View File

@ -32,9 +32,7 @@ class GlanceResourceDriver(base.ResourceInterface):
self.separator = "."
self.service_type = 'image'
self.endpoint_type = 'publicURL'
self.default_namespace = "Default"
self.default_capability_type = "Default"
self.default_resource_type = "OS::Glance::Image"
self.unknown_properties_type = "AdditionalProperties"
def get_resource(self, resource_type, resource_id, auth_token,
endpoint_id=None, **kwargs):
@ -77,29 +75,36 @@ class GlanceResourceDriver(base.ResourceInterface):
image_properties = {}
for capability in resource.capabilities:
properties = capability.properties
capability_type = self.replace_colon_from_name(
capability.capability_type
)
capability_type_namespace = self.replace_colon_from_name(
capability.capability_type_namespace
)
if capability.capability_type_namespace == resource_type \
and capability.capability_type \
== self.unknown_properties_type:
for property in capability.properties:
image_properties[property.name] = property.value
else:
properties = capability.properties
capability_type = self.replace_colon_from_name(
capability.capability_type
)
capability_type_namespace = self.replace_colon_from_name(
capability.capability_type_namespace
)
for property in properties:
prop_name = capability_type_namespace + \
self.separator + \
capability_type + \
self.separator + \
self.replace_colon_from_name(property.name)
image_properties[prop_name] = property.value
for property in properties:
prop_name = capability_type_namespace + \
self.separator + \
capability_type + \
self.separator + \
self.replace_colon_from_name(property.name)
image_properties[prop_name] = property.value
image = glance_client.images.get(resource.id)
image.update(properties=image_properties, purge_props=False)
def find_resources(self, query_string, auth_token,
def find_resources(self, resource_type, query_string, auth_token,
endpoint_id=None, **kwargs):
"""Find resources matching the query
:param query_string: query expression. Include resource type(s)
:param resource_type: resource_type set for this call
:param query_string: query expression
:param auth_token: keystone auth_token of request user
:param endpoint_id: id for locating the cloud resource provider
:param **kwargs: Include additional info required by the driver,
@ -111,7 +116,7 @@ class GlanceResourceDriver(base.ResourceInterface):
images = glance_client.images.list()
for image in list(images):
resource = self.transform_image_to_resource(
self.default_resource_type,
resource_type,
image
)
resource_list[resource.id] = resource
@ -187,8 +192,8 @@ class GlanceResourceDriver(base.ResourceInterface):
capability_type = self.replace_hash_from_name(capability_type)
prop_name = self.replace_hash_from_name(prop_name)
else:
namespace = self.default_namespace
capability_type = self.default_capability_type
namespace = resource_type
capability_type = self.unknown_properties_type
prop_name = key
image_property = Property()
@ -221,3 +226,4 @@ class GlanceResourceDriver(base.ResourceInterface):
if name:
return name.replace('#', ':')
return