Add general description field in image properties

It would be beneficial for us to be able to add descriptions to the
image file.

Change-Id: I8e5f9ce423f1bc76e559ffb437f255fd9717902e
Fixes: bug #1180861
This commit is contained in:
Zhenguo Niu 2013-06-06 14:04:25 +08:00 committed by Gerrit Code Review
parent 4903a9b43f
commit 8ded0be73d
4 changed files with 24 additions and 1 deletions

View File

@ -41,6 +41,9 @@ LOG = logging.getLogger(__name__)
class CreateImageForm(forms.SelfHandlingForm):
name = forms.CharField(max_length="255", label=_("Name"), required=True)
description = forms.CharField(widget=forms.widgets.Textarea(),
label=_("Description"),
required=False)
copy_from = forms.CharField(max_length="255",
label=_("Image Location"),
help_text=_("An external (HTTP) URL to load "
@ -121,8 +124,11 @@ class CreateImageForm(forms.SelfHandlingForm):
'container_format': container_format,
'min_disk': (data['minimum_disk'] or 0),
'min_ram': (data['minimum_ram'] or 0),
'name': data['name']}
'name': data['name'],
'properties': {}}
if data['description']:
meta['properties']['description'] = data['description']
if settings.HORIZON_IMAGES_ALLOW_UPLOAD and data['image_file']:
meta['data'] = self.files['image_file']
else:
@ -141,6 +147,9 @@ class CreateImageForm(forms.SelfHandlingForm):
class UpdateImageForm(forms.SelfHandlingForm):
image_id = forms.CharField(widget=forms.HiddenInput())
name = forms.CharField(max_length="255", label=_("Name"))
description = forms.CharField(widget=forms.widgets.Textarea(),
label=_("Description"),
required=False)
kernel = forms.CharField(max_length="36", label=_("Kernel ID"),
required=False,
widget=forms.TextInput(
@ -177,6 +186,8 @@ class UpdateImageForm(forms.SelfHandlingForm):
'container_format': container_format,
'name': data['name'],
'properties': {}}
if data['description']:
meta['properties']['description'] = data['description']
if data['kernel']:
meta['properties']['kernel_id'] = data['kernel']
if data['ramdisk']:

View File

@ -48,6 +48,7 @@ class CreateImageFormTests(test.TestCase):
"""
post = {
'name': u'Ubuntu 11.10',
'description': u'Login with admin/admin',
'disk_format': u'qcow2',
'minimum_disk': 15,
'minimum_ram': 512,
@ -78,6 +79,7 @@ class ImageViewTests(test.TestCase):
def test_image_create_post_copy_from(self):
data = {
'name': u'Ubuntu 11.10',
'description': u'Login with admin/admin',
'copy_from': u'http://cloud-images.ubuntu.com/releases/'
u'oneiric/release/ubuntu-11.10-server-cloudimg'
u'-amd64-disk1.img',
@ -96,6 +98,8 @@ class ImageViewTests(test.TestCase):
protected=False,
min_disk=data['minimum_disk'],
min_ram=data['minimum_ram'],
properties={
'description': data['description']},
name=data['name']). \
AndReturn(self.images.first())
self.mox.ReplayAll()
@ -114,6 +118,7 @@ class ImageViewTests(test.TestCase):
temp_file.seek(0)
data = {
'name': u'Test Image',
'description': u'Login with admin/admin',
'image_file': temp_file,
'disk_format': u'qcow2',
'minimum_disk': 15,
@ -129,6 +134,8 @@ class ImageViewTests(test.TestCase):
protected=False,
min_disk=data['minimum_disk'],
min_ram=data['minimum_ram'],
properties={
'description': data['description']},
name=data['name'],
data=IsA(InMemoryUploadedFile)). \
AndReturn(self.images.first())

View File

@ -74,6 +74,7 @@ class UpdateView(forms.ModalFormView):
image = self.get_object()
return {'image_id': self.kwargs['image_id'],
'name': image.name,
'description': image.properties.get('description', ''),
'kernel': image.properties.get('kernel_id', ''),
'ramdisk': image.properties.get('ramdisk_id', ''),
'architecture': image.properties.get('architecture', ''),

View File

@ -8,6 +8,10 @@
<dl>
<dt>{% trans "Name" %}</dt>
<dd>{{ image.name|default:_("None") }}</dd>
{% if image.properties.description %}
<dt>{% trans "Description" %}</dt>
<dd>{{ image.properties.description }}</dd>
{% endif %}
<dt>{% trans "ID" %}</dt>
<dd>{{ image.id|default:_("None") }}</dd>
<dt>{% trans "Status" %}</dt>