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

changing video card model functionality added to options.

This commit is contained in:
catborise 2019-11-20 16:24:01 +03:00
parent 60684cc7b1
commit 74eb8004d7
5 changed files with 77 additions and 7 deletions

View file

@ -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

View file

@ -1290,6 +1290,8 @@
<div class="clearfix"></div>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="options">
<div class="well">
<p>{% trans "To set instance template name description, shutdown the instance." %}</p>
<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>
@ -1309,14 +1311,44 @@
<input type="checkbox" name="is_template" value="True" id="is_template" {% if instance.is_template %}checked{% endif %} {% if not request.user.is_superuser %}disabled{% endif %}>
</div>
</div>
{% ifequal status 5 %}
<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_options">{% trans "Change" %}</button>
{% endifequal %}
<div class="form-group ">
<div class="col-sm-offset-3 col-sm-6">
{% ifequal status 5 %}
<button type="submit" class="btn btn-block btn-success" name="change_options">{% trans "Change" %}</button>
{% else %}
<button class="btn btn-block btn-success disabled" name="change_options">{% trans "Change" %}</button>
{% endifequal %}
</div>
</div>
</form>
</div>
<div class="well">
<p>{% trans "To set instance video model, shutdown the instance." %}</p>
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group">
<label for="video_model_select" class="col-sm-3 control-label">{% trans "Primary Video Model" %}</label>
<div class="col-sm-6">
<div class="input-group">
<select id="video_model_select" class="form-control" name="video_model">
<option value="" style="font-weight: bold">{% trans "please choose" %}</option>
{% for vmodel in videos_host %}
<option value="{{ vmodel }}">{{ vmodel }}</option>
{% endfor %}
</select>
<span class="input-group-btn">
{% ifequal status 5 %}
<button type="submit" class="btn btn-success" name="set_video_model">{% trans "Set" %}</button>
{% else %}
<button class="btn btn-success disabled" name="set_video_model">{% trans "Set" %}</button>
{% endifequal %}
</span>
</div>
</div>
</div>
</form>
<div class="clearfix"></div>
</div>
</div>
{% endif %}
</div>
</div>
@ -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) {

View file

@ -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)

View file

@ -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 = []

View file

@ -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 = "<model type='{}'/>".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.