image editing now mostly working
This commit is contained in:
@@ -3,6 +3,7 @@ from django.conf import settings
|
||||
|
||||
|
||||
INSTANCES = r'^instances/(?P<instance_id>[^/]+)/%s$'
|
||||
IMAGES = r'^images/(?P<image_id>[^/]+)/%s$'
|
||||
USERS = r'^users/(?P<user_id>[^/]+)/%s$'
|
||||
TENANTS = r'^tenants/(?P<tenant_id>[^/]+)/%s$'
|
||||
|
||||
@@ -19,8 +20,7 @@ urlpatterns = patterns('django_openstack.syspanel.views.instances',
|
||||
|
||||
urlpatterns += patterns('django_openstack.syspanel.views.images',
|
||||
url(r'^images/$', 'index', name='syspanel_images'),
|
||||
# NOTE(termie): currently just using the 'dash' versions
|
||||
#url(INSTANCES % 'console', 'console', name='syspanel_instances_console'),
|
||||
url(IMAGES % 'update', 'update', name='syspanel_images_update'),
|
||||
#url(INSTANCES % 'vnc', 'vnc', name='syspanel_instances_vnc'),
|
||||
)
|
||||
|
||||
|
||||
@@ -40,6 +40,15 @@ class ToggleImage(forms.SelfHandlingForm):
|
||||
messages.error(request, "Error updating image: %s" % e.message)
|
||||
return redirect(request.build_absolute_uri())
|
||||
|
||||
class UpdateImageForm(forms.Form):
|
||||
name = forms.CharField(max_length="5", label="Name")
|
||||
kernel = forms.CharField(max_length="5", label="Kernel ID", required=False)
|
||||
ramdisk = forms.CharField(max_length="5", 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)
|
||||
|
||||
|
||||
@login_required
|
||||
@@ -74,7 +83,7 @@ def index(request):
|
||||
@login_required
|
||||
def update(request, image_id):
|
||||
try:
|
||||
image = glance_api(request).get_image(image_id)[0]
|
||||
image = api.glance_api(request).get_image(image_id)[0]
|
||||
except GlanceClientConnectionError, e:
|
||||
messages.error(request, "Error connecting to glance: %s" % e.message)
|
||||
except glance_exception.Error, e:
|
||||
@@ -85,41 +94,35 @@ def update(request, image_id):
|
||||
if form.is_valid():
|
||||
image_form = form.clean()
|
||||
metadata = {
|
||||
'is_public': image_form['is_public'],
|
||||
'is_public': True,
|
||||
'disk_format': image_form['disk_format'],
|
||||
'container_format': image_form['container_format'],
|
||||
'name': image_form['name'],
|
||||
'location': image_form['location'],
|
||||
}
|
||||
try:
|
||||
# TODO add public flag to properties
|
||||
metadata['properties'] = {
|
||||
'kernel_id': int(image_form['kernel_id']),
|
||||
'ramdisk_id': int(image_form['ramdisk_id']),
|
||||
'image_state': image_form['state'],
|
||||
'kernel_id': int(image_form['kernel']),
|
||||
'ramdisk_id': int(image_form['ramdisk']),
|
||||
'architecture': image_form['architecture'],
|
||||
'project_id': image_form['project_id'],
|
||||
}
|
||||
|
||||
glance_api(request).update_image(image_id, metadata)
|
||||
api.glance_api(request).update_image(image_id, metadata)
|
||||
messages.success(request, "Image was successfully updated.")
|
||||
redirect("syspanel_images")
|
||||
except GlanceClientConnectionError, e:
|
||||
messages.error(request, "Error connecting to glance: %s" % e.message)
|
||||
redirect("syspanel_images_update", image_id)
|
||||
except glance_exception.Error, e:
|
||||
messages.error(request, "Error updating image: %s" % e.message)
|
||||
except:
|
||||
messages.error(request, "Image could not be updated, please try again.")
|
||||
|
||||
|
||||
redirect("syspanel_images_update", image_id)
|
||||
else:
|
||||
messages.error(request, "Image could not be uploaded, please try agian.")
|
||||
form = UpdateImageForm(request.POST)
|
||||
return render_to_response('django_nova_syspanel/images/image_update.html',{
|
||||
return render_to_response('syspanel_image_update.html',{
|
||||
'image': image,
|
||||
'form': form,
|
||||
}, context_instance = template.RequestContext(request))
|
||||
|
||||
return redirect('syspanel_images')
|
||||
else:
|
||||
form = UpdateImageForm(initial={
|
||||
'name': image.get('name', ''),
|
||||
@@ -134,7 +137,7 @@ def update(request, image_id):
|
||||
'disk_format': image.get('disk_format', ''),
|
||||
})
|
||||
|
||||
return render_to_response('django_nova_syspanel/images/image_update.html',{
|
||||
return render_to_response('syspanel_image_update.html',{
|
||||
'image': image,
|
||||
'form': form,
|
||||
}, context_instance = template.RequestContext(request))
|
||||
|
||||
10
openstack-dashboard/dashboard/templates/_image_form.html
Normal file
10
openstack-dashboard/dashboard/templates/_image_form.html
Normal file
@@ -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>
|
||||
@@ -24,7 +24,7 @@
|
||||
<li>{% include "_delete_image.html" with form=delete_form %}</li>
|
||||
<li>{% include "_toggle_image.html" with form=toggle_form %}</li>
|
||||
|
||||
<li><a href="{#% url syspanel_images_update image.id %#}">Edit</a></li>
|
||||
<li><a href="{% url syspanel_images_update image.id %}">Edit</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
{% extends 'syspanel_base.html' %}
|
||||
{# list of user's instances #}
|
||||
{# standard nav, sidebar, list of instances in main #}
|
||||
|
||||
{% block sidebar %}
|
||||
{% with current_sidebar="users" %}
|
||||
{{block.super}}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div id='page_header'>
|
||||
<h2><span>System Panel:</span> Images </h2>
|
||||
<p class='desc'><span>—</span> Update Image </p>
|
||||
</div>
|
||||
|
||||
{% include "_messages.html" %}
|
||||
|
||||
<div class="main_content">
|
||||
<div class="dash_block wide form">
|
||||
<div class='title_block'>
|
||||
<h3>Update User</h3>
|
||||
</div>
|
||||
|
||||
{% include '_image_form.html' %}
|
||||
|
||||
<div class="right">
|
||||
<h3>Description:</h3>
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus vitae est urna. Phasellus sagittis, sem posuere hendrerit mattis, velit risus viverra enim, tempus dapibus sem turpis ac erat.</p>
|
||||
<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed mollis ligula nec lacus mollis eu laoreet lectus porta. </p>
|
||||
<p>Sed iaculis mauris et est consectetur egestas. Praesent dolor libero, semper sed aliquet</p>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<div class="main_content">
|
||||
<div class="dash_block wide form">
|
||||
<div class='title_block'>
|
||||
<h3>Update User</h3>
|
||||
<h3>Update Image</h3>
|
||||
</div>
|
||||
|
||||
{% include '_user_form.html' %}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
$(function(){
|
||||
// update/create image form
|
||||
$("#images_form input#id_name").example("ami-ubuntu");
|
||||
$("#images_form input#id_kernel").example("123");
|
||||
$("#images_form input#id_ramdisk").example("123");
|
||||
$("#images_form input#id_state").example("available");
|
||||
$("#images_form input#id_location").example("file:///var/lib/glance/images/123");
|
||||
$("#images_form input#id_architecture").example("x86_64");
|
||||
$("#images_form input#id_project_id").example("some");
|
||||
$("#images_form input#id_disk_format").example("ari");
|
||||
$("#images_form input#id_container_format").example("ari");
|
||||
$("#images_form input#id_ramdisk").example("123");
|
||||
$("#image_form input#id_name").example("ami-ubuntu");
|
||||
$("#image_form input#id_kernel").example("123");
|
||||
$("#image_form input#id_ramdisk").example("123");
|
||||
$("#image_form input#id_state").example("available");
|
||||
$("#image_form input#id_location").example("file:///var/lib/glance/images/123");
|
||||
$("#image_form input#id_architecture").example("x86_64");
|
||||
$("#image_form input#id_project_id").example("some");
|
||||
$("#image_form input#id_disk_format").example("ari");
|
||||
$("#image_form input#id_container_format").example("ari");
|
||||
$("#image_form input#id_ramdisk").example("123");
|
||||
|
||||
// launch instance form
|
||||
$("#launch_img input#id_name").example("YetAnotherInstance")
|
||||
|
||||
Reference in New Issue
Block a user