diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 948fd7d..4eeb659 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -517,8 +517,8 @@
  • - - {% trans "Template" %} + + {% trans "Options" %}
  • {% endif %} @@ -690,9 +690,20 @@
    -
    -

    {% trans "Is this instance template?" %}

    +
    {% csrf_token %} +
    + +
    + +
    +
    +
    + +
    + +
    +
    @@ -700,9 +711,9 @@
    {% ifequal status 5 %} - + {% else %} - + {% endifequal %}
    @@ -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') { diff --git a/instances/views.py b/instances/views.py index f69f356..5938f29 100644 --- a/instances/views.py +++ b/instances/views.py @@ -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() diff --git a/vrtManager/instance.py b/vrtManager/instance.py index c1009eb..3df2483 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -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) +