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

Add new options for migrate: Auto converge, postcopy and compress

This commit is contained in:
catborise 2019-12-19 16:06:51 +03:00
parent c6cdb4929c
commit 2fa5a98844
3 changed files with 49 additions and 20 deletions

View file

@ -1035,7 +1035,7 @@
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Live migration" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="live_migrate" value="true" id="vm_live_migrate" {% ifequal status 1 %}checked{% endifequal %}>
<input type="checkbox" name="live_migrate" value="true" id="vm_live_migrate" {% ifnotequal status 5 %}checked{% else %}disabled{% endifnotequal %}>
</div>
</div>
<div class="form-group">
@ -1053,7 +1053,25 @@
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Offline migration" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="offline_migrate" value="true" id="offline_migrate" {% ifequal status 5 %}checked{% endifequal %}>
<input type="checkbox" name="offline_migrate" value="true" id="offline_migrate" {% ifequal status 5 %}checked{% else %}disabled{% endifequal %}>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">{% trans "Post copy" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="postcopy" value="true" id="postcopy" {% ifnotequal status 1 %}disabled{% endifnotequal %}>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" title="{% trans 'Forces CPU convergence during live migration' %}">{% trans "Auto converge" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="autoconverge" value="true" id="autoconverge" {% ifnotequal status 1 %}disabled{% endifnotequal %}>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" title="{% trans 'Compress instance memory for fast migration' %}">{% trans "Compressed" %}</label>
<div class="col-sm-6">
<input type="checkbox" name="compress" value="true" id="compress" {% ifnotequal status 1 %}disabled{% endifnotequal %}>
</div>
</div>
{% if computes_count != 1 %}

View file

@ -230,7 +230,7 @@ def instance(request, compute_id, vname):
else:
return network_source_pack[0], 'net'
def migrate_instance(new_compute, instance, live=False, unsafe=False, xml_del=False, offline=False):
def migrate_instance(new_compute, instance, live=False, unsafe=False, xml_del=False, offline=False, autoconverge=False, compress=False, postcopy=False):
status = connection_manager.host_is_up(new_compute.type, new_compute.hostname)
if not status:
return
@ -238,11 +238,11 @@ def instance(request, compute_id, vname):
return
try:
conn_migrate = wvmInstances(new_compute.hostname,
new_compute.login,
new_compute.password,
new_compute.type)
new_compute.login,
new_compute.password,
new_compute.type)
conn_migrate.moveto(conn, instance.name, live, unsafe, xml_del, offline)
conn_migrate.moveto(conn, instance.name, live, unsafe, xml_del, offline, autoconverge, compress, postcopy)
finally:
conn_migrate.close()
@ -812,16 +812,24 @@ def instance(request, compute_id, vname):
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)
unsafe = request.POST.get('unsafe_migrate', False)
xml_del = request.POST.get('xml_delete', False)
offline = request.POST.get('offline_migrate', False)
autoconverge = request.POST.get('autoconverge', False)
compress = request.POST.get('compress', False)
postcopy = request.POST.get('postcopy', False)
new_compute = Compute.objects.get(id=compute_id)
migrate_instance(new_compute, instance, live, unsafe, xml_del, offline)
return HttpResponseRedirect(reverse('instance', args=[new_compute.id, vname]))
try:
migrate_instance(new_compute, instance, live, unsafe, xml_del, offline)
return HttpResponseRedirect(reverse('instance', args=[new_compute.id, vname]))
except libvirtError as err:
messages.error(request, err)
addlogmsg(request.user.username, instance.name, err)
return HttpResponseRedirect(request.get_full_path() + '#migrate')
if 'change_network' in request.POST:
msg = _("Change network")
@ -1240,7 +1248,8 @@ def inst_graph(request, compute_id, vname):
def _get_dhcp_mac_address(vname):
dhcp_file = '/srv/webvirtcloud/dhcpd.conf'
dhcp_file = settings.BASE_DIR + '/dhcpd.conf'
mac = ''
if os.path.isfile(dhcp_file):
with open(dhcp_file, 'r') as f:

View file

@ -2,15 +2,15 @@ import time
import os.path
try:
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE, VIR_DOMAIN_RUNNING, VIR_DOMAIN_AFFECT_LIVE, \
VIR_DOMAIN_AFFECT_CONFIG, VIR_DOMAIN_UNDEFINE_NVRAM, VIR_DOMAIN_UNDEFINE_KEEP_NVRAM,\
VIR_DOMAIN_START_PAUSED
VIR_DOMAIN_AFFECT_CONFIG, VIR_DOMAIN_UNDEFINE_NVRAM, VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, VIR_DOMAIN_START_PAUSED
from libvirt import VIR_MIGRATE_LIVE, \
VIR_MIGRATE_UNSAFE, \
VIR_MIGRATE_PERSIST_DEST, \
VIR_MIGRATE_UNDEFINE_SOURCE, \
VIR_MIGRATE_OFFLINE,\
VIR_MIGRATE_COMPRESSED, \
VIR_MIGRATE_AUTO_CONVERGE
VIR_MIGRATE_AUTO_CONVERGE, \
VIR_MIGRATE_POSTCOPY
except:
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE, VIR_MIGRATE_LIVE
@ -80,20 +80,22 @@ class wvmInstances(wvmConnect):
dom = self.get_instance(name)
dom.resume()
def moveto(self, conn, name, live, unsafe, undefine, offline, autoconverge=False, compress=False):
def moveto(self, conn, name, live, unsafe, undefine, offline, autoconverge=False, compress=False, postcopy=False):
flags = VIR_MIGRATE_PERSIST_DEST
if live and conn.get_status() == 1:
if live and conn.get_status() != 5:
flags |= VIR_MIGRATE_LIVE
if unsafe and conn.get_status() == 1:
flags |= VIR_MIGRATE_UNSAFE
if undefine:
flags |= VIR_MIGRATE_UNDEFINE_SOURCE
if offline:
if offline and conn.get_status() == 5:
flags |= VIR_MIGRATE_OFFLINE
if not offline and autoconverge:
flags |= VIR_MIGRATE_AUTO_CONVERGE
if compress:
if not offline and compress and conn.get_status() == 1:
flags |= VIR_MIGRATE_COMPRESSED
if not offline and postcopy and conn.get_status() == 1:
flags |= VIR_MIGRATE_POSTCOPY
if undefine:
flags |= VIR_MIGRATE_UNDEFINE_SOURCE
dom = conn.get_instance(name)