Merge branch 'add_update_instance_form'
This commit is contained in:
commit
6da850bf18
@ -131,7 +131,7 @@ def server_delete(request, instance):
|
||||
|
||||
|
||||
def server_get(request, instance_id):
|
||||
return compute_api(request).servers.get(instance_id)
|
||||
return extras_api(request).servers.get(instance_id)
|
||||
|
||||
|
||||
def server_list(request):
|
||||
@ -143,6 +143,12 @@ def server_reboot(request, instance_id, hardness=openstack.compute.servers.REBOO
|
||||
return server.reboot(hardness)
|
||||
|
||||
|
||||
def server_update(request, instance_id, name, description):
|
||||
return extras_api(request).servers.update(instance_id,
|
||||
name=name,
|
||||
description=description)
|
||||
|
||||
|
||||
def service_get(request, name):
|
||||
return admin_api(request).services.get(name)
|
||||
|
||||
|
@ -12,6 +12,7 @@ urlpatterns = patterns('django_openstack.dash.views.instances',
|
||||
url(r'^(?P<tenant_id>[^/]+)/instances/$', 'index', name='dash_instances'),
|
||||
url(INSTANCES % 'console', 'console', name='dash_instances_console'),
|
||||
url(INSTANCES % 'vnc', 'vnc', name='dash_instances_vnc'),
|
||||
url(INSTANCES % 'update', 'update', name='dash_instances_update'),
|
||||
)
|
||||
|
||||
urlpatterns += patterns('django_openstack.dash.views.images',
|
||||
|
@ -74,6 +74,13 @@ class RebootInstance(forms.SelfHandlingForm):
|
||||
return redirect(request.build_absolute_uri())
|
||||
|
||||
|
||||
class UpdateInstance(forms.Form):
|
||||
instance = forms.CharField(widget=forms.TextInput(
|
||||
attrs={'readonly':'readonly'}))
|
||||
name = forms.CharField(required=True)
|
||||
description = forms.CharField(required=False)
|
||||
|
||||
|
||||
@login_required
|
||||
def index(request, tenant_id):
|
||||
for f in (TerminateInstance, RebootInstance):
|
||||
@ -181,3 +188,33 @@ def vnc(request, tenant_id, instance_id):
|
||||
'Unable to get vnc console for instance %s: %s' %
|
||||
(instance_id, e.message))
|
||||
return redirect('dash_instances', tenant_id)
|
||||
|
||||
|
||||
@login_required
|
||||
def update(request, tenant_id, instance_id):
|
||||
if request.POST:
|
||||
form = UpdateInstance(request.POST)
|
||||
if form.is_valid():
|
||||
data = form.clean()
|
||||
instance_id = data['instance']
|
||||
name = data['name']
|
||||
description = data.get('description', '')
|
||||
try:
|
||||
api.server_update(request, instance_id, name, description)
|
||||
messages.success(request, "Instance %s updated" % instance_id)
|
||||
except api_exceptions.ApiException, e:
|
||||
messages.error(request,
|
||||
'Unable to update instance: %s' % e.message)
|
||||
|
||||
return redirect('dash_instances', tenant_id)
|
||||
else:
|
||||
instance = api.server_get(request, instance_id)
|
||||
form = UpdateInstance(initial={'instance': instance_id,
|
||||
'tenant_id': tenant_id,
|
||||
'name': instance.name,
|
||||
'description': instance.attrs['description']})
|
||||
|
||||
return render_to_response('dash_instance_update.html', {
|
||||
'instance': instance,
|
||||
'form': form,
|
||||
}, context_instance=template.RequestContext(request))
|
||||
|
10
openstack-dashboard/dashboard/templates/_instance_form.html
Normal file
10
openstack-dashboard/dashboard/templates/_instance_form.html
Normal file
@ -0,0 +1,10 @@
|
||||
<form id="tenant_form" 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 Instance" class="large-rounded" />
|
||||
</form>
|
@ -40,6 +40,7 @@
|
||||
<li>{% include "_reboot.html" with form=reboot_form %}</li>
|
||||
<li><a target="_blank" href="{% url dash_instances_console request.user.tenant instance.id %}">Log</a></li>
|
||||
<li><a target="_blank" href="{% url dash_instances_vnc request.user.tenant instance.id %}">VNC Console</a></li>
|
||||
<li><a href="{% url dash_instances_update request.user.tenant instance.id %}">Edit</a></li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -0,0 +1,36 @@
|
||||
{% extends 'dash_base.html' %}
|
||||
|
||||
{% block sidebar %}
|
||||
{% with current_sidebar="instances" %}
|
||||
{{block.super}}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
<div id='page_header'>
|
||||
<h2><span>Compute:</span> Update Instance </h2>
|
||||
<!--
|
||||
<p class='desc'><span>—</span>Update Instance</p>
|
||||
-->
|
||||
</div>
|
||||
|
||||
{% include "_messages.html" %}
|
||||
|
||||
<div class="main_content">
|
||||
<div class="dash_block wide form">
|
||||
<div class='title_block'>
|
||||
<h3>Update Instance</h3>
|
||||
</div>
|
||||
<div class="left">
|
||||
{% include '_instance_form.html' with form=form %}
|
||||
<h3><a href="{% url dash_instances request.user.tenant %}"><< Return to Instances List</a></h3>
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
<h3>Description:</h3>
|
||||
<p>Update the name and description of your instance</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user