diff --git a/create/views.py b/create/views.py index d44ad26..f8b4bc1 100644 --- a/create/views.py +++ b/create/views.py @@ -43,7 +43,7 @@ def create_instance(request, compute_id): compute.type) instances = conn.get_instances() - videos = conn.get_video() + videos = conn.get_video_models() cache_modes = sorted(conn.get_cache_modes().items()) default_cache = INSTANCE_VOLUME_DEFAULT_CACHE listener_addr = QEMU_CONSOLE_LISTEN_ADDRESSES diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 471901a..22b7eb6 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -1290,6 +1290,8 @@
+
+

{% trans "To set instance template name description, shutdown the instance." %}

{% csrf_token %}
@@ -1309,14 +1311,44 @@
- {% ifequal status 5 %} - - {% else %} - - {% endifequal %} +
+
+ {% ifequal status 5 %} + + {% else %} + + {% endifequal %} +
+
+ +
+
+

{% trans "To set instance video model, shutdown the instance." %}

+
{% csrf_token %} +
+ +
+
+ + + {% ifequal status 5 %} + + {% else %} + + {% endifequal %} + +
+
+
+ {% endif %} @@ -1597,6 +1629,13 @@ $("#console_select_listen_address option[value='" + console_listen_address + "']").prop('selected', true); } }); + $(document).ready(function () { + // get video model or fall back to default + let video_model = "{{ video_model }}" + if (video_model != '') { + $("#video_model_select option[value='" + video_model + "']").prop('selected', true); + } + }); $(document).ready(function () { // set vdi url $.get("{% url 'vdi_url' vname %}", function(data) { diff --git a/instances/views.py b/instances/views.py index ae1e189..51246ce 100644 --- a/instances/views.py +++ b/instances/views.py @@ -291,6 +291,7 @@ def instance(request, compute_id, vname): console_port = conn.get_console_port() console_keymap = conn.get_console_keymap() console_listen_address = conn.get_console_listen_addr() + video_model = conn.get_video_model() snapshots = sorted(conn.get_snapshot(), reverse=True, key=lambda k: k['date']) inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE) has_managed_save_image = conn.get_managed_save_image() @@ -328,6 +329,7 @@ def instance(request, compute_id, vname): vcpu_host = len(vcpu_range) memory_host = conn.get_max_memory() bus_host = conn.get_disk_bus_types() + videos_host = conn.get_video_models() networks_host = sorted(conn.get_networks()) interfaces_host = sorted(conn.get_ifaces()) nwfilters_host = conn.get_nwfilters() @@ -764,6 +766,13 @@ def instance(request, compute_id, vname): return HttpResponseRedirect(request.get_full_path() + '#vncsettings') if request.user.is_superuser: + if 'set_video_model' in request.POST: + video_model = request.POST.get('video_model', 'vga') + conn.set_video_model(video_model) + msg = _("Set Video Model") + addlogmsg(request.user.username, instance.name, msg) + return HttpResponseRedirect(request.get_full_path() + '#options') + if 'migrate' in request.POST: compute_id = request.POST.get('compute_id', '') live = request.POST.get('live_migrate', False) diff --git a/vrtManager/connection.py b/vrtManager/connection.py index ccd0d51..e186854 100644 --- a/vrtManager/connection.py +++ b/vrtManager/connection.py @@ -480,7 +480,7 @@ class wvmConnect(object): """Get available image filename extensions""" return ['img', 'qcow', 'qcow2'] - def get_video(self): + def get_video_models(self): """ Get available graphics video types """ def get_video_list(ctx): result = [] diff --git a/vrtManager/instance.py b/vrtManager/instance.py index 6bf46f1..9fe7d67 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -763,6 +763,28 @@ class wvmInstance(wvmConnect): def get_console_keymap(self): return util.get_xml_path(self._XMLDesc(VIR_DOMAIN_XML_SECURE), "/domain/devices/graphics/@keymap") or '' + def get_video_model(self): + """ :return only primary video card""" + xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE) + tree = etree.fromstring(xml) + video_models = tree.xpath("/domain/devices/video/model") + for model in video_models: + if model.get('primary') == 'yes' or len(video_models) == 1: + return model.get('type') + + def set_video_model(self, model): + """ Changes only primary video card""" + xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE) + tree = etree.fromstring(xml) + video_models = tree.xpath("/domain/devices/video/model") + video_xml = "".format(model) + for model in video_models: + if model.get('primary') == 'yes' or len(video_models) == 1: + parent = model.getparent() + parent.remove(model) + parent.append(etree.fromstring(video_xml)) + self._defineXML(etree.tostring(tree)) + def resize(self, cur_memory, memory, cur_vcpu, vcpu, disks=[]): """ Function change ram and cpu on vds.