Commit 82dccc14 by tarokkk

one: add create vm by share

parent a7bcad7d
......@@ -18,6 +18,7 @@ urlpatterns = patterns('',
url(r'^login/$', 'school.views.login', name='login'),
url(r'^logout/$', 'school.views.logout', name='logout'),
url(r'^vm/new/(?P<template>\d+)/$', 'one.views.vm_new', name='vm_new'),
url(r'^vm/new/s(?P<share>\d+)/$', 'one.views.vm_new', name='vm_new'),
url(r'^vm/show/(?P<iid>\d+)/$', 'one.views.vm_show', name='vm_show'),
url(r'^vm/delete/(?P<iid>\d+)/$', 'one.views.vm_delete', name='vm_delete'),
url(r'^vm/stop/(?P<iid>\d+)/$', 'one.views.vm_stop', name='vm_stop'),
......
......@@ -16,19 +16,19 @@
</div>
</li>
<li id="new-wm" style="display: none">
<h2>{% trans "Available templates" %}</h2>
<h2>{% trans "Available shares" %}</h2>
<p>
{% trans "Choose one of the following templates to launch." %}
{% trans "Choose one of the following shared templates to launch." %}
</p>
<div class="container">
<ul class="wm-list modal">
{% for m in templates %}
{% for s in shares %}
<li class="wm">
<div class="summary">
<div class="quota">
<div class="used" style="width: 40%"></div>
</div>
<div class="name wm-on">{{m.name}}</div>
<div class="name wm-on">{{s.name}}</div>
<div class="status">
3/10
</div>
......@@ -37,16 +37,17 @@
<div class="details">
<div class="details-container">
<ul>
<li class="os-{{m.os_type}}">{% trans "System" %}: <span class="value">{{m.system}}</span><div class="clear"></div></li>
<li class="type">{% trans "Size" %}: <span class="value">{{m.instance_type.name}}</span></li>
<li class="os-{{s.template.os_type}}">{% trans "System" %}: <span class="value">{{s.template.system}}</span><div class="clear"></div></li>
<li class="type">{% trans "Size" %}: <span class="value">{{s.template.instance_type.name}}</span></li>
<li class="share-type">{% trans "Type" %}: <span class="value">{{s.type }}</span></li>
<li class="memory">{% trans "Memory" %}:
<span class="value">{% blocktrans with m=m.instance_type.RAM %}{{m}} MiB{% endblocktrans %}</span></li>
<li class="cpu">{% trans "CPU cores" %}: <span class="value">{{m.instance_type.CPU}}</span></li>
<li class="description">{% trans "Description" %}:<span class="value">{{m.description}}</span><div class="clear"></div></li>
<span class="value">{% blocktrans with m=s.template.instance_type.RAM %}{{m}} MiB{% endblocktrans %}</span></li>
<li class="cpu">{% trans "CPU cores" %}: <span class="value">{{s.template.instance_type.CPU}}</span></li>
<li class="description">{% trans "Description" %}:<span class="value">{{s.description}}</span><div class="clear"></div></li>
<li>
&nbsp;
<span class="value">
<form method="POST" action="/vm/new/{{m.pk}}/">{% csrf_token %}
<form method="POST" action="/vm/new/s{{s.pk}}/">{% csrf_token %}
<input type="submit" value="{% trans "Launch" %}"/>
</form>
</span>
......
......@@ -74,6 +74,7 @@ def _list_instances(request):
@login_required
def home(request):
return render_to_response("home.html", RequestContext(request, {
'shares': request.user.person_set.all()[0].get_shares(),
'templates': Template.objects.filter(state='READY'),
'mytemplates': Template.objects.filter(owner=request.user),
'publictemplates': Template.objects.filter(public=True, state='READY'),
......@@ -191,13 +192,18 @@ def vm_saveas(request, vmid):
@require_POST
@login_required
def vm_new(request, template):
def vm_new(request, template=None, share=None):
base = None
if template:
base = get_object_or_404(Template, pk=template)
else:
share = get_object_or_404(Share, pk=share)
base = share.template
if "name" in request.POST:
if base.owner != request.user and not base.public and not request.user.is_superuser:
raise PermissionDenied()
name = request.POST['name']
t = Template.objects.create(name=name, disk=base.disk, instance_type_id=request.POST['size'], network=base.network, owner=request.user)
t = Template.objects.create(name=name, disk=base.disk, instance_type_id=request.POST['size'], network=base.network, owner=request.user, share=share)
t.access_type = base.access_type
t.description = request.POST['description']
t.system = base.system
......
......@@ -5,6 +5,7 @@ from django.db.models.signals import post_save
from django.core.exceptions import ValidationError
from datetime import datetime
from django.conf import settings
import one.models
LANGUAGE_CODE = settings.LANGUAGE_CODE
......@@ -28,6 +29,9 @@ class Person(models.Model):
choices=LANGUAGE_CHOICES, default=LANGUAGE_CODE)
code = models.CharField(_('code'), max_length=30, unique=True)
def get_shares(self):
return one.models.Share.objects.filter(group__in=self.course_groups.all())
def short_name(self):
if self.user.last_name:
return self.user.last_name
......
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