From a709f34ff93579981afbd4df0f4334b61ada29a8 Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Mon, 16 Sep 2013 11:36:21 +0200 Subject: [PATCH] kvm: During migrate change the VNC listen address The migrate method from libvirt supports passing down a different XML for running the instance of the target hypervisor. This enables the VNC to bind to the private IP Address of the hypervisor and during migration this will be changed to the private IP address of the target host. This way VNC doesn't listen world wide and is much safer. --- .../en-US/hypervisor-host-install-libvirt.xml | 5 ---- .../resource/LibvirtComputingResource.java | 23 ++++++++++++++++--- pom.xml | 4 ++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/docs/en-US/hypervisor-host-install-libvirt.xml b/docs/en-US/hypervisor-host-install-libvirt.xml index c4be67e643f..d3d6b9b4e80 100644 --- a/docs/en-US/hypervisor-host-install-libvirt.xml +++ b/docs/en-US/hypervisor-host-install-libvirt.xml @@ -46,11 +46,6 @@ so it looks like: libvirtd_opts="-d -l" - - In order to have the VNC Console work we have to make sure it will bind on 0.0.0.0. We do this by editing /etc/libvirt/qemu.conf - Make sure this parameter is set: - vnc_listen = "0.0.0.0" - Restart libvirt In RHEL or CentOS: diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 94ee9ae676e..203587a06f6 100755 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -2878,17 +2878,34 @@ ServerResource { Connect dconn = null; Domain destDomain = null; Connect conn = null; + String xmlDesc = null; try { conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName()); ifaces = getInterfaces(conn, vmName); - dm = conn.domainLookupByName(vmName); + dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName + .getBytes())); + /* + We replace the private IP address with the address of the destination host. + This is because the VNC listens on the private IP address of the hypervisor, + but that address is ofcourse different on the target host. + + MigrateCommand.getDestinationIp() returns the private IP address of the target + hypervisor. So it's safe to use. + + The Domain.migrate method from libvirt supports passing a different XML + description for the instance to be used on the target host. + + This is supported by libvirt-java from version 0.50.0 + */ + xmlDesc = dm.getXMLDesc(0).replace(_privateIp, cmd.getDestinationIp()); + dconn = new Connect("qemu+tcp://" + cmd.getDestinationIp() + "/system"); /* * Hard code lm flags: VIR_MIGRATE_LIVE(1<<0) and * VIR_MIGRATE_PERSIST_DEST(1<<3) */ - destDomain = dm.migrate(dconn, (1 << 0) | (1 << 3), vmName, "tcp:" + destDomain = dm.migrate(dconn, (1 << 0) | (1 << 3), xmlDesc, vmName, "tcp:" + cmd.getDestinationIp(), _migrateSpeed); } catch (LibvirtException e) { s_logger.debug("Can't migrate domain: " + e.getMessage()); @@ -3441,7 +3458,7 @@ ServerResource { //add the VNC port passwd here, get the passwd from the vmInstance. String passwd = vmTO.getVncPassword(); - GraphicDef grap = new GraphicDef("vnc", (short) 0, true, null, passwd, + GraphicDef grap = new GraphicDef("vnc", (short) 0, true, vmTO.getVncAddr(), passwd, null); devices.addDevice(grap); diff --git a/pom.xml b/pom.xml index 4013fa63acb..6d9a30f101b 100644 --- a/pom.xml +++ b/pom.xml @@ -81,11 +81,11 @@ 0.9.8 0.10 build/replace.properties - 0.4.9 + 0.5.0 0.1.3 target 1.0.10 - 3.0.9 + 4.0.0