Add 'Extra_Properties' to OS::Glance::WebImage
Add Extra_Properties to OS::Glance::WebImage; property exists in OS::Glance::Image Change-Id: I816ce9d820fb455fd0b751fe914e87f6293b8297 Story: #2007592
This commit is contained in:
parent
403ac3def7
commit
bde268078b
|
@ -29,14 +29,15 @@ class GlanceWebImage(resource.Resource):
|
||||||
|
|
||||||
PROPERTIES = (
|
PROPERTIES = (
|
||||||
NAME, IMAGE_ID, MIN_DISK, MIN_RAM, PROTECTED,
|
NAME, IMAGE_ID, MIN_DISK, MIN_RAM, PROTECTED,
|
||||||
DISK_FORMAT, CONTAINER_FORMAT, LOCATION, TAGS,
|
DISK_FORMAT, CONTAINER_FORMAT, LOCATION, TAGS, EXTRA_PROPERTIES,
|
||||||
ARCHITECTURE, KERNEL_ID, OS_DISTRO, OS_VERSION, OWNER,
|
ARCHITECTURE, KERNEL_ID, OS_DISTRO, OS_VERSION, OWNER,
|
||||||
VISIBILITY, RAMDISK_ID
|
VISIBILITY, RAMDISK_ID
|
||||||
) = (
|
) = (
|
||||||
'name', 'id', 'min_disk', 'min_ram', 'protected',
|
'name', 'id', 'min_disk', 'min_ram', 'protected',
|
||||||
'disk_format', 'container_format', 'location', 'tags',
|
'disk_format', 'container_format', 'location', 'tags',
|
||||||
'architecture', 'kernel_id', 'os_distro', 'os_version', 'owner',
|
'extra_properties', 'architecture', 'kernel_id',
|
||||||
'visibility', 'ramdisk_id'
|
'os_distro', 'os_version', 'owner', 'visibility',
|
||||||
|
'ramdisk_id'
|
||||||
)
|
)
|
||||||
|
|
||||||
glance_id_pattern = ('^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}'
|
glance_id_pattern = ('^([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}'
|
||||||
|
@ -108,6 +109,12 @@ class GlanceWebImage(resource.Resource):
|
||||||
_('List of image tags.'),
|
_('List of image tags.'),
|
||||||
update_allowed=True,
|
update_allowed=True,
|
||||||
),
|
),
|
||||||
|
EXTRA_PROPERTIES: properties.Schema(
|
||||||
|
properties.Schema.MAP,
|
||||||
|
_('Arbitrary properties to associate with the image.'),
|
||||||
|
update_allowed=True,
|
||||||
|
default={}
|
||||||
|
),
|
||||||
ARCHITECTURE: properties.Schema(
|
ARCHITECTURE: properties.Schema(
|
||||||
properties.Schema.STRING,
|
properties.Schema.STRING,
|
||||||
_('Operating system architecture.'),
|
_('Operating system architecture.'),
|
||||||
|
@ -168,6 +175,11 @@ class GlanceWebImage(resource.Resource):
|
||||||
if v is not None)
|
if v is not None)
|
||||||
|
|
||||||
location = args.pop(self.LOCATION)
|
location = args.pop(self.LOCATION)
|
||||||
|
extra_properties = args.pop(self.EXTRA_PROPERTIES, {})
|
||||||
|
if extra_properties:
|
||||||
|
for k, v in extra_properties.items():
|
||||||
|
if k not in self.properties:
|
||||||
|
args[k] = v
|
||||||
images = self.client().images
|
images = self.client().images
|
||||||
image_id = images.create(
|
image_id = images.create(
|
||||||
**args).id
|
**args).id
|
||||||
|
@ -201,7 +213,17 @@ class GlanceWebImage(resource.Resource):
|
||||||
|
|
||||||
images = self.client().images
|
images = self.client().images
|
||||||
|
|
||||||
images.update(self.resource_id, **prop_diff)
|
# Though remove_props defaults to None within the glanceclient,
|
||||||
|
# setting it to a list (possibly []) every time ensures only one
|
||||||
|
# calling format to images.update
|
||||||
|
remove_props = []
|
||||||
|
if self.EXTRA_PROPERTIES in prop_diff:
|
||||||
|
old_properties = self.properties.get(self.EXTRA_PROPERTIES) or {}
|
||||||
|
new_properties = prop_diff.pop(self.EXTRA_PROPERTIES)
|
||||||
|
prop_diff.update(new_properties)
|
||||||
|
remove_props = list(set(old_properties) - set(new_properties))
|
||||||
|
|
||||||
|
images.update(self.resource_id, remove_props, **prop_diff)
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
super(GlanceWebImage, self).validate()
|
super(GlanceWebImage, self).validate()
|
||||||
|
|
|
@ -640,7 +640,7 @@ class GlanceWebImageTest(common.HeatTestCase):
|
||||||
name=u'cirros_image',
|
name=u'cirros_image',
|
||||||
protected=False,
|
protected=False,
|
||||||
owner=u'test_owner',
|
owner=u'test_owner',
|
||||||
tags=['tag1'],
|
tags=['tag1']
|
||||||
)
|
)
|
||||||
|
|
||||||
def _handle_update_tags(self, prop_diff):
|
def _handle_update_tags(self, prop_diff):
|
||||||
|
@ -664,18 +664,21 @@ class GlanceWebImageTest(common.HeatTestCase):
|
||||||
'kernel_id': '12345678-1234-1234-1234-123456789012',
|
'kernel_id': '12345678-1234-1234-1234-123456789012',
|
||||||
'os_distro': 'test_distro',
|
'os_distro': 'test_distro',
|
||||||
'owner': 'test_owner',
|
'owner': 'test_owner',
|
||||||
'ramdisk_id': '12345678-1234-1234-1234-123456789012'}
|
'ramdisk_id': '12345678-1234-1234-1234-123456789012',
|
||||||
|
'extra_properties': {'key1': 'value1', 'key2': 'value2'}}
|
||||||
|
|
||||||
self.my_image.handle_update(json_snippet=None,
|
self.my_image.handle_update(json_snippet=None,
|
||||||
tmpl_diff=None,
|
tmpl_diff=None,
|
||||||
prop_diff=prop_diff)
|
prop_diff=prop_diff)
|
||||||
self.images.update.assert_called_once_with(
|
self.images.update.assert_called_once_with(
|
||||||
self.my_image.resource_id,
|
self.my_image.resource_id,
|
||||||
|
[],
|
||||||
architecture='test_architecture',
|
architecture='test_architecture',
|
||||||
kernel_id='12345678-1234-1234-1234-123456789012',
|
kernel_id='12345678-1234-1234-1234-123456789012',
|
||||||
os_distro='test_distro',
|
os_distro='test_distro',
|
||||||
owner='test_owner',
|
owner='test_owner',
|
||||||
ramdisk_id='12345678-1234-1234-1234-123456789012'
|
ramdisk_id='12345678-1234-1234-1234-123456789012',
|
||||||
|
key1='value1', key2='value2'
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_image_handle_update_tags(self):
|
def test_image_handle_update_tags(self):
|
||||||
|
@ -756,6 +759,7 @@ class GlanceWebImageTest(common.HeatTestCase):
|
||||||
'min_ram': 0,
|
'min_ram': 0,
|
||||||
'id': '41f0e60c-ebb4-4375-a2b4-845ae8b9c995',
|
'id': '41f0e60c-ebb4-4375-a2b4-845ae8b9c995',
|
||||||
'tags': [],
|
'tags': [],
|
||||||
|
'extra_properties': {},
|
||||||
'architecture': 'test_architecture',
|
'architecture': 'test_architecture',
|
||||||
'kernel_id': '12345678-1234-1234-1234-123456789012',
|
'kernel_id': '12345678-1234-1234-1234-123456789012',
|
||||||
'os_distro': 'test_distro',
|
'os_distro': 'test_distro',
|
||||||
|
@ -778,6 +782,7 @@ class GlanceWebImageTest(common.HeatTestCase):
|
||||||
'min_ram': 0,
|
'min_ram': 0,
|
||||||
'id': '41f0e60c-ebb4-4375-a2b4-845ae8b9c995',
|
'id': '41f0e60c-ebb4-4375-a2b4-845ae8b9c995',
|
||||||
'tags': [],
|
'tags': [],
|
||||||
|
'extra_properties': {},
|
||||||
'architecture': 'test_architecture',
|
'architecture': 'test_architecture',
|
||||||
'kernel_id': '12345678-1234-1234-1234-123456789012',
|
'kernel_id': '12345678-1234-1234-1234-123456789012',
|
||||||
'os_distro': 'test_distro',
|
'os_distro': 'test_distro',
|
||||||
|
|
Loading…
Reference in New Issue