Commit 0d5684f5 by Kálmán Viktor

dashboard: create vm with different parameters

parent 0c033922
......@@ -6,8 +6,7 @@ $(function() {
});
function vmCreateLoaded() {
// temporarily disable for testing
//$('.vm-create-advanced').hide();
$('.vm-create-advanced').hide();
$('.vm-create-advanced-btn').click(function() {
$('.vm-create-advanced').stop().slideToggle();
if ($('.vm-create-advanced-icon').hasClass('icon-caret-down')) {
......@@ -178,7 +177,16 @@ function vmCreateLoaded() {
type: 'POST',
data: $('form').serialize(),
success: function(data, textStatus, xhr) {
console.log(data);
if(data.pk) {
window.location.replace('/dashboard/vm/' + data.pk + '/#activity');
}
},
error: function(xhr, textStatus, error) {
if (xhr.status == 500) {
alert("uhuhuhuhuhuh");
} else {
alert("unknown error");
}
}
});
return false;
......
......@@ -4,7 +4,7 @@
{% block content %}
<div class="body-content">
<div class="page-header">
<h1>{{ instance.name }} <small>550.vm.ik.bme.hu</small></h1>
<h1>{{ instance.name }} <small>{{ instance.pk }}.vm.ik.bme.hu</small></h1>
</div>
<div class="row">
<div class="col-md-4" id="vm-info-pane">
......
from django.http import HttpResponse
from django.views.generic import TemplateView, DetailView
from django_tables2 import SingleTableView
from django.core.urlresolvers import reverse_lazy
from django.shortcuts import redirect
from django_tables2 import SingleTableView
from tables import VmListTable
from vm.models import Instance, InstanceTemplate, InterfaceTemplate
......@@ -121,21 +123,38 @@ class VmCreate(TemplateView):
return context
# TODO handle not ajax posts
def post(self, request, *args, **kwargs):
if self.request.user.is_authenticated():
user = self.request.user
else:
user = None
resp = request.POST.copy()
resp['managed-vlans'] = request.POST.getlist('managed-vlans')
resp['unmanaged-vlans'] = request.POST.getlist('unmanaged-vlans')
resp['disks'] = request.POST.getlist('disks')
resp = {}
try:
ikwargs = {
'num_cores': request.POST.get('cpu-count'),
'ram_size': request.POST.get('ram-size'),
'priority': request.POST.get('cpu-priority'),
'disks': Disk.objects.filter(
pk__in=request.POST.getlist('disks'))
}
template = InstanceTemplate.objects.get(
pk=request.POST.get('template-pk'))
inst = Instance.create_from_template(template=template,
owner=user, **ikwargs)
inst.deploy_async()
template = InstanceTemplate.objects.get(
pk=request.POST.get('template-pk'))
inst = Instance.create_from_template(template=template, owner=user)
inst.deploy_async()
resp['pk'] = inst.pk
except InstanceTemplate.DoesNotExist:
resp['error'] = True
except:
resp['error'] = True
# TODO handle response
return HttpResponse(json.dumps(resp), content_type="application/json")
if request.is_ajax():
return HttpResponse(json.dumps(resp),
content_type="application/json",
status=500 if resp.get('error') else 200)
else:
return redirect(reverse_lazy('dashboard.views.detail', resp))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment