Skip to content

Commit 34f8732

Browse files
committed
kvm: remove Ipv6 brackets in vm definition xml
1 parent 4a242a7 commit 34f8732

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ public String toString() {
10951095
diskBuilder.append(">\n");
10961096
for (String sourceHost : _sourceHost.split(",")) {
10971097
diskBuilder.append("<host name='");
1098-
diskBuilder.append(sourceHost);
1098+
diskBuilder.append(sourceHost.replace("[", "").replace("]", ""));
10991099
if (_sourcePort != 0) {
11001100
diskBuilder.append("' port='");
11011101
diskBuilder.append(_sourcePort);

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,39 @@ public void testDiskDefWithMultipleHosts() {
271271
assertEquals(expected, diskdef.toString());
272272
}
273273

274+
@Test
275+
public void testDiskDefWithMultipleHostsIpv6() {
276+
String path = "/mnt/primary1";
277+
String host = "[fc00:1234::1],[fc00:1234::2],[fc00:1234::3]";
278+
int port = 3300;
279+
String authUsername = "admin";
280+
String uuid = "40b3f216-36b5-11ed-9357-9b4e21b0ed91";
281+
int devId = 2;
282+
283+
DiskDef diskdef = new DiskDef();
284+
diskdef.defNetworkBasedDisk(path, host, port, authUsername,
285+
uuid, devId, DiskDef.DiskBus.VIRTIO, DiskDef.DiskProtocol.RBD, DiskDef.DiskFmtType.RAW);
286+
287+
assertEquals(path, diskdef.getDiskPath());
288+
assertEquals(DiskDef.DiskType.NETWORK, diskdef.getDiskType());
289+
assertEquals(DiskDef.DiskFmtType.RAW, diskdef.getDiskFormatType());
290+
291+
String expected = "<disk device='disk' type='network'>\n" +
292+
"<driver name='qemu' type='raw' cache='none' />\n" +
293+
"<source protocol='rbd' name='/mnt/primary1'>\n" +
294+
"<host name='fc00:1234::1' port='3300'/>\n" +
295+
"<host name='fc00:1234::2' port='3300'/>\n" +
296+
"<host name='fc00:1234::3' port='3300'/>\n" +
297+
"</source>\n" +
298+
"<auth username='admin'>\n" +
299+
"<secret type='ceph' uuid='40b3f216-36b5-11ed-9357-9b4e21b0ed91'/>\n" +
300+
"</auth>\n" +
301+
"<target dev='vdc' bus='virtio'/>\n" +
302+
"</disk>\n";
303+
304+
assertEquals(expected, diskdef.toString());
305+
}
306+
274307
@Test
275308
public void testDiskDefWithBurst() {
276309
String filePath = "/var/lib/libvirt/images/disk.qcow2";

0 commit comments

Comments
 (0)