Commit 0d5684f5 by Kálmán Viktor

dashboard: create vm with different parameters

parent 0c033922
...@@ -6,8 +6,7 @@ $(function() { ...@@ -6,8 +6,7 @@ $(function() {
}); });
function vmCreateLoaded() { function vmCreateLoaded() {
// temporarily disable for testing $('.vm-create-advanced').hide();
//$('.vm-create-advanced').hide();
$('.vm-create-advanced-btn').click(function() { $('.vm-create-advanced-btn').click(function() {
$('.vm-create-advanced').stop().slideToggle(); $('.vm-create-advanced').stop().slideToggle();
if ($('.vm-create-advanced-icon').hasClass('icon-caret-down')) { if ($('.vm-create-advanced-icon').hasClass('icon-caret-down')) {
...@@ -178,7 +177,16 @@ function vmCreateLoaded() { ...@@ -178,7 +177,16 @@ function vmCreateLoaded() {
type: 'POST', type: 'POST',
data: $('form').serialize(), data: $('form').serialize(),
success: function(data, textStatus, xhr) { 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; return false;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{% block content %} {% block content %}
<div class="body-content"> <div class="body-content">
<div class="page-header"> <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>
<div class="row"> <div class="row">
<div class="col-md-4" id="vm-info-pane"> <div class="col-md-4" id="vm-info-pane">
......
from django.http import HttpResponse from django.http import HttpResponse
from django.views.generic import TemplateView, DetailView 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 tables import VmListTable
from vm.models import Instance, InstanceTemplate, InterfaceTemplate from vm.models import Instance, InstanceTemplate, InterfaceTemplate
...@@ -121,21 +123,38 @@ class VmCreate(TemplateView): ...@@ -121,21 +123,38 @@ class VmCreate(TemplateView):
return context return context
# TODO handle not ajax posts
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
if self.request.user.is_authenticated(): if self.request.user.is_authenticated():
user = self.request.user user = self.request.user
else: else:
user = None user = None
resp = request.POST.copy() resp = {}
resp['managed-vlans'] = request.POST.getlist('managed-vlans') try:
resp['unmanaged-vlans'] = request.POST.getlist('unmanaged-vlans') ikwargs = {
resp['disks'] = request.POST.getlist('disks') '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( template = InstanceTemplate.objects.get(
pk=request.POST.get('template-pk')) pk=request.POST.get('template-pk'))
inst = Instance.create_from_template(template=template, owner=user) inst = Instance.create_from_template(template=template,
owner=user, **ikwargs)
inst.deploy_async() inst.deploy_async()
# TODO handle response resp['pk'] = inst.pk
return HttpResponse(json.dumps(resp), content_type="application/json") except InstanceTemplate.DoesNotExist:
resp['error'] = True
except:
resp['error'] = True
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