summaryrefslogtreecommitdiff
path: root/glanceclient/v2/schemas.py
diff options
context:
space:
mode:
authorAlexander Tivelkov <ativelkov@mirantis.com>2015-03-27 17:53:46 +0300
committerAlexander Tivelkov <ativelkov@mirantis.com>2015-03-27 19:03:48 +0300
commit90407d9e473014c24eeab294192f9d3208f58ea7 (patch)
tree397b668c7cb5d8a48039bcfbade9f37d89dbf71a /glanceclient/v2/schemas.py
parent13b5a5ade126b39c683f3f81968b9350fc0f6ba2 (diff)
downloadpython-glanceclient-90407d9e473014c24eeab294192f9d3208f58ea7.tar.gz
Expose 'is_base' schema property attribute
Changeset I49255255 has added an 'is_base' attribute for Image Schema properties, thus allowing to differentiate between base and custom image properties, but the client hasn't make any use of it. This patch adds appropriate attribute to SchemaProperty class and a helper method which allows to validate if the given property is base or not. The added helper method (is_base_property) should not be confused with the existing is_core_property: the latter just checks if the property is known to the schema, regardless of its being base or not. Change-Id: I7c397196dad9ae5494ed2f8f3aacef3fc1ce70d8 Partial-Bug: #1323660
Diffstat (limited to 'glanceclient/v2/schemas.py')
-rw-r--r--glanceclient/v2/schemas.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/glanceclient/v2/schemas.py b/glanceclient/v2/schemas.py
index 5c31741..94d1bb6 100644
--- a/glanceclient/v2/schemas.py
+++ b/glanceclient/v2/schemas.py
@@ -65,6 +65,7 @@ class SchemaProperty(object):
def __init__(self, name, **kwargs):
self.name = name
self.description = kwargs.get('description')
+ self.is_base = kwargs.get('is_base', True)
def translate_schema_properties(schema_properties):
@@ -86,9 +87,27 @@ class Schema(object):
self.properties = translate_schema_properties(raw_properties)
def is_core_property(self, property_name):
+ """Checks if a property with a given name is known to the schema,
+ i.e. is either a base property or a custom one registered in
+ schema-image.json file
+
+ :param property_name: name of the property
+ :returns: True if the property is known, False otherwise
+ """
+ return self._check_property(property_name, True)
+
+ def is_base_property(self, property_name):
+ """Checks if a property with a given name is a base property
+
+ :param property_name: name of the property
+ :returns: True if the property is base, False otherwise
+ """
+ return self._check_property(property_name, False)
+
+ def _check_property(self, property_name, allow_non_base):
for prop in self.properties:
if property_name == prop.name:
- return True
+ return prop.is_base or allow_non_base
return False
def raw(self):