Skip to content

Commit a709f34

Browse files
committed
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.
1 parent 5410901 commit a709f34

3 files changed

Lines changed: 22 additions & 10 deletions

File tree

docs/en-US/hypervisor-host-install-libvirt.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,6 @@
4646
<para>so it looks like:</para>
4747
<programlisting>libvirtd_opts="-d -l"</programlisting>
4848
</listitem>
49-
<listitem>
50-
<para>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 <filename>/etc/libvirt/qemu.conf</filename></para>
51-
<para>Make sure this parameter is set:</para>
52-
<programlisting>vnc_listen = "0.0.0.0"</programlisting>
53-
</listitem>
5449
<listitem>
5550
<para>Restart libvirt</para>
5651
<para>In RHEL or CentOS:</para>

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2878,17 +2878,34 @@ private Answer execute(MigrateCommand cmd) {
28782878
Connect dconn = null;
28792879
Domain destDomain = null;
28802880
Connect conn = null;
2881+
String xmlDesc = null;
28812882
try {
28822883
conn = LibvirtConnection.getConnectionByVmName(cmd.getVmName());
28832884
ifaces = getInterfaces(conn, vmName);
2884-
dm = conn.domainLookupByName(vmName);
2885+
dm = conn.domainLookupByUUID(UUID.nameUUIDFromBytes(vmName
2886+
.getBytes()));
2887+
/*
2888+
We replace the private IP address with the address of the destination host.
2889+
This is because the VNC listens on the private IP address of the hypervisor,
2890+
but that address is ofcourse different on the target host.
2891+
2892+
MigrateCommand.getDestinationIp() returns the private IP address of the target
2893+
hypervisor. So it's safe to use.
2894+
2895+
The Domain.migrate method from libvirt supports passing a different XML
2896+
description for the instance to be used on the target host.
2897+
2898+
This is supported by libvirt-java from version 0.50.0
2899+
*/
2900+
xmlDesc = dm.getXMLDesc(0).replace(_privateIp, cmd.getDestinationIp());
2901+
28852902
dconn = new Connect("qemu+tcp://" + cmd.getDestinationIp()
28862903
+ "/system");
28872904
/*
28882905
* Hard code lm flags: VIR_MIGRATE_LIVE(1<<0) and
28892906
* VIR_MIGRATE_PERSIST_DEST(1<<3)
28902907
*/
2891-
destDomain = dm.migrate(dconn, (1 << 0) | (1 << 3), vmName, "tcp:"
2908+
destDomain = dm.migrate(dconn, (1 << 0) | (1 << 3), xmlDesc, vmName, "tcp:"
28922909
+ cmd.getDestinationIp(), _migrateSpeed);
28932910
} catch (LibvirtException e) {
28942911
s_logger.debug("Can't migrate domain: " + e.getMessage());
@@ -3441,7 +3458,7 @@ So if getMinSpeed() returns null we fall back to getSpeed().
34413458

34423459
//add the VNC port passwd here, get the passwd from the vmInstance.
34433460
String passwd = vmTO.getVncPassword();
3444-
GraphicDef grap = new GraphicDef("vnc", (short) 0, true, null, passwd,
3461+
GraphicDef grap = new GraphicDef("vnc", (short) 0, true, vmTO.getVncAddr(), passwd,
34453462
null);
34463463
devices.addDevice(grap);
34473464

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@
8181
<cs.reflections.version>0.9.8</cs.reflections.version>
8282
<cs.java-ipv6.version>0.10</cs.java-ipv6.version>
8383
<cs.replace.properties>build/replace.properties</cs.replace.properties>
84-
<cs.libvirt-java.version>0.4.9</cs.libvirt-java.version>
84+
<cs.libvirt-java.version>0.5.0</cs.libvirt-java.version>
8585
<cs.rados-java.version>0.1.3</cs.rados-java.version>
8686
<cs.target.dir>target</cs.target.dir>
8787
<cs.daemon.version>1.0.10</cs.daemon.version>
88-
<cs.jna.version>3.0.9</cs.jna.version>
88+
<cs.jna.version>4.0.0</cs.jna.version>
8989
</properties>
9090

9191
<distributionManagement>

0 commit comments

Comments
 (0)