diff options
author | Jake Dahn <admin@jakedahn.com> | 2011-09-29 16:38:06 -0700 |
---|---|---|
committer | Jake Dahn <admin@jakedahn.com> | 2011-09-30 10:42:41 -0700 |
commit | ffd93c5334bbe293bdd199d2f6d98eede93e4b15 (patch) | |
tree | e7c29f71dce795e49c15e54cc0d62c5219d70ebe /django-openstack | |
parent | 51668c40fa76effd9c5e852329e2a64a3c792291 (diff) | |
download | horizon-ffd93c5334bbe293bdd199d2f6d98eede93e4b15.tar.gz |
adding edit/delete capability for owner of an image through the user dashboard
Diffstat (limited to 'django-openstack')
7 files changed, 151 insertions, 6 deletions
diff --git a/django-openstack/django_openstack/api.py b/django-openstack/django_openstack/api.py index 106c4f52c..d988e6c0c 100644 --- a/django-openstack/django_openstack/api.py +++ b/django-openstack/django_openstack/api.py @@ -141,7 +141,7 @@ class Image(APIDictWrapper): """Simple wrapper around glance image dictionary""" _attrs = ['checksum', 'container_format', 'created_at', 'deleted', 'deleted_at', 'disk_format', 'id', 'is_public', 'location', - 'name', 'properties', 'size', 'status', 'updated_at'] + 'name', 'properties', 'size', 'status', 'updated_at', 'owner'] def __getattr__(self, attrname): if attrname == "properties": diff --git a/django-openstack/django_openstack/dash/urls.py b/django-openstack/django_openstack/dash/urls.py index 553c71b6f..002413f62 100644 --- a/django-openstack/django_openstack/dash/urls.py +++ b/django-openstack/django_openstack/dash/urls.py @@ -50,6 +50,7 @@ urlpatterns += patterns('django_openstack.dash.views.security_groups', urlpatterns += patterns('django_openstack.dash.views.images', url(r'^(?P<tenant_id>[^/]+)/images/$', 'index', name='dash_images'), url(IMAGES % 'launch', 'launch', name='dash_images_launch'), + url(IMAGES % 'update', 'update', name='dash_images_update'), ) urlpatterns += patterns('django_openstack.dash.views.keypairs', diff --git a/django-openstack/django_openstack/dash/views/images.py b/django-openstack/django_openstack/dash/views/images.py index b17bb2e1d..b88f27d2d 100644 --- a/django-openstack/django_openstack/dash/views/images.py +++ b/django-openstack/django_openstack/dash/views/images.py @@ -46,6 +46,75 @@ from novaclient import exceptions as novaclient_exceptions LOG = logging.getLogger('django_openstack.dash.views.images') +class UpdateImageForm(forms.SelfHandlingForm): + image_id = forms.CharField(widget=forms.HiddenInput()) + name = forms.CharField(max_length="25", label="Name") + kernel = forms.CharField(max_length="25", label="Kernel ID", + required=False) + ramdisk = forms.CharField(max_length="25", label="Ramdisk ID", + required=False) + architecture = forms.CharField(label="Architecture", required=False) + #project_id = forms.CharField(label="Project ID") + container_format = forms.CharField(label="Container Format", + required=False) + disk_format = forms.CharField(label="Disk Format") + #is_public = forms.BooleanField(label="Publicly Available", required=False) + + def handle(self, request, data): + image_id = data['image_id'] + tenant_id = request.user.tenant_id + + try: + image = api.image_get(request, image_id) + except glance_exception.ClientConnectionError, e: + LOG.exception("Error connecting to glance") + messages.error(request, "Error connecting to glance: %s" + % e.message) + except glance_exception.Error, e: + LOG.exception('Error retrieving image with id "%s"' % image_id) + messages.error(request, "Error retrieving image %s: %s" + % (image_id, e.message)) + + if image.owner == request.user.username: + try: + meta = { + 'is_public': True, + 'disk_format': data['disk_format'], + 'container_format': data['container_format'], + 'name': data['name'], + } + # TODO add public flag to properties + meta['properties'] = {} + if data['kernel']: + meta['properties']['kernel_id'] = data['kernel'] + + if data['ramdisk']: + meta['properties']['ramdisk_id'] = data['ramdisk'] + + if data['architecture']: + meta['properties']['architecture'] = data['architecture'] + + api.image_update(request, image_id, meta) + messages.success(request, "Image was successfully updated.") + + except glance_exception.ClientConnectionError, e: + LOG.exception("Error connecting to glance") + messages.error(request, "Error connecting to glance: %s" + % e.message) + except glance_exception.Error, e: + LOG.exception('Error updating image with id "%s"' % image_id) + messages.error(request, "Error updating image: %s" % e.message) + except: + LOG.exception('Unspecified Exception in image update') + messages.error(request, "Image could not be updated, \ + please try again.") + return redirect('dash_images_update', tenant_id, image_id) + else: + messages.info(request, "Unable to update image, you are not its \ + owner.") + return redirect('dash_images_update', tenant_id, image_id) + + class LaunchForm(forms.SelfHandlingForm): name = forms.CharField(max_length=80, label="Server Name") image_id = forms.CharField(widget=forms.HiddenInput()) @@ -210,3 +279,32 @@ def launch(request, tenant_id, image_id): 'form': form, 'quotas': quotas, }, context_instance=template.RequestContext(request)) + + +@login_required +def update(request, tenant_id, image_id): + try: + image = api.image_get(request, image_id) + except glance_exception.ClientConnectionError, e: + LOG.exception("Error connecting to glance") + messages.error(request, "Error connecting to glance: %s" + % e.message) + except glance_exception.Error, e: + LOG.exception('Error retrieving image with id "%s"' % image_id) + messages.error(request, "Error retrieving image %s: %s" + % (image_id, e.message)) + + form, handled = UpdateImageForm().maybe_handle(request, initial={ + 'image_id': image_id, + 'name': image.get('name', ''), + 'kernel': image['properties'].get('kernel_id', ''), + 'ramdisk': image['properties'].get('ramdisk_id', ''), + 'architecture': image['properties'].get('architecture', ''), + 'container_format': image.get('container_format', ''), + 'disk_format': image.get('disk_format', ''),}) + if handled: + return handled + + return render_to_response('django_openstack/dash/images/update.html', { + 'form': form, + }, context_instance=template.RequestContext(request)) diff --git a/django-openstack/django_openstack/templates/django_openstack/dash/images/_delete.html b/django-openstack/django_openstack/templates/django_openstack/dash/images/_delete.html new file mode 100644 index 000000000..1f9d0868f --- /dev/null +++ b/django-openstack/django_openstack/templates/django_openstack/dash/images/_delete.html @@ -0,0 +1,8 @@ +<form id="form_delete_{{image.id}}" class="form-delete" method="post"> + {% csrf_token %} + {% for hidden in form.hidden_fields %} + {{hidden}} + {% endfor %} + <input name="image_id" type="hidden" value="{{image.id}}" /> + <input id="delete_{{image.id}}" class="delete" title="Image: {{image.name}}" type="submit" value="Delete" /> +</form> diff --git a/django-openstack/django_openstack/templates/django_openstack/dash/images/_form.html b/django-openstack/django_openstack/templates/django_openstack/dash/images/_form.html new file mode 100644 index 000000000..c6494bb9e --- /dev/null +++ b/django-openstack/django_openstack/templates/django_openstack/dash/images/_form.html @@ -0,0 +1,10 @@ +<form id="image_form" action="" method="post"> + {% csrf_token %} + {% for hidden in form.hidden_fields %}{{ hidden }}{% endfor %} + {% for field in form.visible_fields %} + {{ field.label_tag }} + {{ field.errors }} + {{ field }} + {% endfor %} + <input type="submit" value="Update Image" class="large-rounded" /> +</form> diff --git a/django-openstack/django_openstack/templates/django_openstack/dash/images/_list.html b/django-openstack/django_openstack/templates/django_openstack/dash/images/_list.html index 11c8ba8bf..e04fcf5e0 100644 --- a/django-openstack/django_openstack/templates/django_openstack/dash/images/_list.html +++ b/django-openstack/django_openstack/templates/django_openstack/dash/images/_list.html @@ -14,11 +14,14 @@ <td>{{image.created_at|parse_date}}</td> <td>{{image.updated_at|parse_date}}</td> <td>{{image.status|capfirst}}</td> - <td id="actions"> - <ul> - <li><a id="launch_{{image.id}}" class="launch" href="{% url dash_images_launch request.user.tenant_id image.id %}">Launch</a></li> - </ul> - </td> + {% if image.owner == request.user.username %} + <td id="actions"> + <ul> + <li class="form">{% include "django_openstack/dash/images/_delete.html" with form=delete_form %}</li> + <li><a href="{% url dash_images_update request.user.tenant_id image.id %}">Edit</a></li> + </ul> + </td> + {% endif %} </tr> {% endfor %} </table> diff --git a/django-openstack/django_openstack/templates/django_openstack/dash/images/update.html b/django-openstack/django_openstack/templates/django_openstack/dash/images/update.html new file mode 100644 index 000000000..ce88bc80f --- /dev/null +++ b/django-openstack/django_openstack/templates/django_openstack/dash/images/update.html @@ -0,0 +1,25 @@ +{% extends 'django_openstack/dash/base.html' %} + +{% block sidebar %} + {% with current_sidebar="images" %} + {{block.super}} + {% endwith %} +{% endblock %} + +{% block page_header %} + {% include "django_openstack/common/_page_header.html" with title="Update Image" %} +{% endblock page_header %} + +{% block dash_main %} + <div class="dash_block"> + <div class="left"> + {% include 'django_openstack/dash/images/_form.html' %} + </div> + + <div class="right"> + <h3>Description:</h3> + <p>From here you can modify different properties of an image.</p> + </div> + <div class="clear"> </div> + </div> +{% endblock %} |