1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-10-31 19:44:16 +00:00

section #template renamed to #options, added title and description fields

This commit is contained in:
Jan Krcmar 2016-02-23 14:43:32 +01:00
parent 510e0e6ee5
commit 2ceb456a4f
3 changed files with 56 additions and 11 deletions

View file

@ -517,8 +517,8 @@
</a>
</li>
<li role="presentation">
<a href="#template" aria-controls="template" role="tab" data-toggle="tab">
{% trans "Template" %}
<a href="#options" aria-controls="options" role="tab" data-toggle="tab">
{% trans "Options" %}
</a>
</li>
{% endif %}
@ -690,9 +690,20 @@
</form>
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="template">
<p>{% trans "Is this instance template?" %}</p>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="options">
<form class="form-horizontal" action="" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Title" %}</label>
<div class="col-sm-6">
<input type="text" name="title" class="form-control" value="{{ title }}">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Description" %}</label>
<div class="col-sm-6">
<textarea name="description" class="form-control">{{ description }}</textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Is template" %}</label>
<div class="col-sm-6">
@ -700,9 +711,9 @@
</div>
</div>
{% ifequal status 5 %}
<button type="submit" class="btn btn-lg btn-success pull-right" name="change_template">{% trans "Change" %}</button>
<button type="submit" class="btn btn-lg btn-success pull-right" name="change_options">{% trans "Change" %}</button>
{% else %}
<button class="btn btn-lg btn-success pull-right disabled" name="change_template">{% trans "Change" %}</button>
<button class="btn btn-lg btn-success pull-right disabled" name="change_options">{% trans "Change" %}</button>
{% endifequal %}
</form>
<div class="clearfix"></div>
@ -1207,7 +1218,7 @@
}
});
}
if (~$.inArray(hash, ['#media', '#network', '#clone', '#autostart', '#xmledit', '#vncsettings', '#migrate', '#template'])) {
if (~$.inArray(hash, ['#media', '#network', '#clone', '#autostart', '#xmledit', '#vncsettings', '#migrate', '#options'])) {
var btnsect = $('#navbtn>li>a');
$(btnsect).each(function () {
if ($(this).attr('href') === '#settings') {

View file

@ -218,6 +218,7 @@ def instance(request, compute_id, vname):
uuid = conn.get_uuid()
memory = conn.get_memory()
cur_memory = conn.get_cur_memory()
title = conn.get_title()
description = conn.get_description()
disks = conn.get_disk_device()
media = conn.get_media_device()
@ -525,12 +526,19 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#network')
if 'change_template' in request.POST:
if 'change_options' in request.POST:
instance.is_template = request.POST.get('is_template', False)
instance.save()
msg = _("Edit template %s" % instance.is_template)
options = {}
for post in request.POST:
if post in ['title', 'description']:
options[post] = request.POST.get(post, '')
conn.set_options(options)
msg = _("Edit options")
addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#template')
return HttpResponseRedirect(request.get_full_path() + '#options')
conn.close()

View file

@ -185,8 +185,13 @@ class wvmInstance(wvmConnect):
mem = util.get_xml_path(self._XMLDesc(0), "/domain/currentMemory")
return int(mem) / 1024
def get_title(self):
title = util.get_xml_path(self._XMLDesc(0), "/domain/title")
return title if title else ''
def get_description(self):
return util.get_xml_path(self._XMLDesc(0), "/domain/description")
description = util.get_xml_path(self._XMLDesc(0), "/domain/description")
return description if description else ''
def get_max_memory(self):
return self.wvm.getInfo()[1] * 1048576
@ -703,3 +708,24 @@ class wvmInstance(wvmConnect):
new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml)
def set_options(self, options):
"""
Function change description, title
"""
xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE)
tree = ElementTree.fromstring(xml)
for o in ['title', 'description']:
option = tree.find(o)
option_value = str(options[o]).strip()
if not option_value:
if not option is None:
tree.remove(option)
else:
if option is None:
option = ElementTree.SubElement(tree, o)
option.text = option_value
new_xml = ElementTree.tostring(tree)
self._defineXML(new_xml)