1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

Added is_template attribute to instances. If true, instance cannot be started.

This commit is contained in:
Jan Krcmar 2016-01-20 15:40:09 +01:00
parent 4ab8561360
commit 646bdbbe0e
4 changed files with 39 additions and 3 deletions

View file

@ -6,6 +6,7 @@ class Instance(models.Model):
compute = models.ForeignKey(Compute) compute = models.ForeignKey(Compute)
name = models.CharField(max_length=20) name = models.CharField(max_length=20)
uuid = models.CharField(max_length=36) uuid = models.CharField(max_length=36)
is_template = models.BooleanField(default=False)
def __unicode__(self): def __unicode__(self):
return self.name return self.name

View file

@ -204,7 +204,12 @@
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="boot"> <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="boot">
<p>{% trans "Click on Boot button to start this instance." %}</p> <p>{% trans "Click on Boot button to start this instance." %}</p>
<form action="" method="post" role="form">{% csrf_token %} <form action="" method="post" role="form">{% csrf_token %}
{% if instance.is_template %}
<p>{% trans "Template instance cannot be started." %}</p>
<input type="submit" name="poweron" class="btn btn-lg btn-success pull-right disabled" value="{% trans "Power On" %}">
{% else %}
<input type="submit" name="poweron" class="btn btn-lg btn-success pull-right" value="{% trans "Power On" %}"> <input type="submit" name="poweron" class="btn btn-lg btn-success pull-right" value="{% trans "Power On" %}">
{% endif %}
<div class="clearfix"></div> <div class="clearfix"></div>
</form> </form>
</div> </div>
@ -511,6 +516,11 @@
{% trans "XML" %} {% trans "XML" %}
</a> </a>
</li> </li>
<li role="presentation">
<a href="#template" aria-controls="template" role="tab" data-toggle="tab">
{% trans "Template" %}
</a>
</li>
{% endif %} {% endif %}
</ul> </ul>
<!-- Tab panes --> <!-- Tab panes -->
@ -684,6 +694,23 @@
</form> </form>
<div class="clearfix"></div> <div class="clearfix"></div>
</div> </div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="template">
<p>{% trans "Is this instance template?" %}</p>
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Is template" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="is_template" value="true" id="is_template" {% if instance.is_template %}checked{% endif %}>
</div>
</div>
{% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" name="change_template">{% trans "Change" %}</button>
{% else %}
<button class="btn btn-lg btn-success pull-right disabled" name="change_template">{% trans "Change" %}</button>
{% endifequal %}
</form>
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="clone"> <div role="tabpanel" class="tab-pane tab-pane-bordered" id="clone">
<p style="font-weight:bold;">{% trans "Create a clone" %}</p> <p style="font-weight:bold;">{% trans "Create a clone" %}</p>
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %} <form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}
@ -1149,7 +1176,7 @@
} }
}); });
} }
if (~$.inArray(hash, ['#media', '#network', '#clone', '#autostart', '#xmledit', '#vncsettings', '#migrate'])) { if (~$.inArray(hash, ['#media', '#network', '#clone', '#autostart', '#xmledit', '#vncsettings', '#migrate', '#template'])) {
var btnsect = $('#navbtn>li>a'); var btnsect = $('#navbtn>li>a');
$(btnsect).each(function () { $(btnsect).each(function () {
if ($(this).attr('href') === '#settings') { if ($(this).attr('href') === '#settings') {

View file

@ -69,7 +69,7 @@
<input type="hidden" name="name" value="{{ vm }}"/> <input type="hidden" name="name" value="{{ vm }}"/>
<input type="hidden" name="compute_id" value="{{ host.0 }}"/> <input type="hidden" name="compute_id" value="{{ host.0 }}"/>
{% ifequal info.status 5 %} {% ifequal info.status 5 %}
<button class="btn btn-sm btn-default" type="submit" name="poweron" title="{% trans "Power On" %}"> <button class="btn btn-sm btn-default {% if info.is_template %}disabled{% endif %}" type="submit" name="poweron" title="{% trans "Power On" %}">
<span class="glyphicon glyphicon-play"></span> <span class="glyphicon glyphicon-play"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "Suspend" %}">

View file

@ -66,6 +66,7 @@ def instances(request):
check_uuid = Instance.objects.get(compute_id=comp.id, name=vm) check_uuid = Instance.objects.get(compute_id=comp.id, name=vm)
if check_uuid.uuid != info['uuid']: if check_uuid.uuid != info['uuid']:
check_uuid.save() check_uuid.save()
all_host_vms[comp.id, comp.name][vm]['is_template'] = check_uuid.is_template
except Instance.DoesNotExist: except Instance.DoesNotExist:
check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid']) check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid'])
check_uuid.save() check_uuid.save()
@ -515,6 +516,13 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#network') return HttpResponseRedirect(request.get_full_path() + '#network')
if 'change_template' in request.POST:
instance.is_template = request.POST.get('is_template', False)
instance.save()
msg = _("Edit template %s" % instance.is_template)
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#template')
conn.close() conn.close()
except libvirtError as lib_err: except libvirtError as lib_err: