Skip to content

Commit e35d12e

Browse files
Add vddk version details
1 parent 2976142 commit e35d12e

6 files changed

Lines changed: 104 additions & 14 deletions

File tree

api/src/main/java/com/cloud/host/Host.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public static String[] toStrings(Host.Type... types) {
5858
String HOST_VOLUME_ENCRYPTION = "host.volume.encryption";
5959
String HOST_INSTANCE_CONVERSION = "host.instance.conversion";
6060
String HOST_VDDK_SUPPORT = "host.vddk.support";
61+
String HOST_VDDK_LIB_DIR = "vddk.lib.dir";
62+
String HOST_VDDK_VERSION = "host.vddk.version";
6163
String HOST_OVFTOOL_VERSION = "host.ovftool.version";
6264
String HOST_VIRTV2V_VERSION = "host.virtv2v.version";
6365
String HOST_SSH_PORT = "host.ssh.port";

engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,10 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
806806
String virtv2vVersion = detailsMap.get(Host.HOST_VIRTV2V_VERSION);
807807
String ovftoolVersion = detailsMap.get(Host.HOST_OVFTOOL_VERSION);
808808
String vddkSupport = detailsMap.get(Host.HOST_VDDK_SUPPORT);
809+
String vddkLibDir = detailsMap.get(Host.HOST_VDDK_LIB_DIR);
810+
String vddkVersion = detailsMap.get(Host.HOST_VDDK_VERSION);
809811
logger.debug("Got HOST_UEFI_ENABLE [{}] for host [{}]:", uefiEnabled, host);
810-
if (ObjectUtils.anyNotNull(uefiEnabled, virtv2vVersion, ovftoolVersion, vddkSupport)) {
812+
if (ObjectUtils.anyNotNull(uefiEnabled, virtv2vVersion, ovftoolVersion, vddkSupport, vddkLibDir, vddkVersion)) {
811813
_hostDao.loadDetails(host);
812814
boolean updateNeeded = false;
813815
if (StringUtils.isNotBlank(uefiEnabled) && !uefiEnabled.equals(host.getDetails().get(Host.HOST_UEFI_ENABLE))) {
@@ -826,6 +828,22 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
826828
host.getDetails().put(Host.HOST_VDDK_SUPPORT, vddkSupport);
827829
updateNeeded = true;
828830
}
831+
if (!StringUtils.defaultString(vddkLibDir).equals(StringUtils.defaultString(host.getDetails().get(Host.HOST_VDDK_LIB_DIR)))) {
832+
if (StringUtils.isBlank(vddkLibDir)) {
833+
host.getDetails().remove(Host.HOST_VDDK_LIB_DIR);
834+
} else {
835+
host.getDetails().put(Host.HOST_VDDK_LIB_DIR, vddkLibDir);
836+
}
837+
updateNeeded = true;
838+
}
839+
if (!StringUtils.defaultString(vddkVersion).equals(StringUtils.defaultString(host.getDetails().get(Host.HOST_VDDK_VERSION)))) {
840+
if (StringUtils.isBlank(vddkVersion)) {
841+
host.getDetails().remove(Host.HOST_VDDK_VERSION);
842+
} else {
843+
host.getDetails().put(Host.HOST_VDDK_VERSION, vddkVersion);
844+
}
845+
updateNeeded = true;
846+
}
829847
if (updateNeeded) {
830848
_hostDao.saveDetails(host);
831849
}

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

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import static com.cloud.host.Host.HOST_INSTANCE_CONVERSION;
2020
import static com.cloud.host.Host.HOST_OVFTOOL_VERSION;
21+
import static com.cloud.host.Host.HOST_VDDK_LIB_DIR;
2122
import static com.cloud.host.Host.HOST_VDDK_SUPPORT;
23+
import static com.cloud.host.Host.HOST_VDDK_VERSION;
2224
import static com.cloud.host.Host.HOST_VIRTV2V_VERSION;
2325
import static com.cloud.host.Host.HOST_VOLUME_ENCRYPTION;
2426
import static org.apache.cloudstack.utils.linux.KVMHostInfo.isHostS390x;
@@ -364,6 +366,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
364366
public static final String WINDOWS_GUEST_CONVERSION_SUPPORTED_CHECK_CMD = "rpm -qa | grep -i virtio-win";
365367
public static final String UBUNTU_WINDOWS_GUEST_CONVERSION_SUPPORTED_CHECK_CMD = "dpkg -l virtio-win";
366368
public static final String UBUNTU_NBDKIT_PKG_CHECK_CMD = "dpkg -l nbdkit";
369+
public static final String VDDK_AUTODETECT_PATH_CMD = "find / -type d -name 'vmware-vix-disklib-distrib' 2>/dev/null | head -n 1";
367370

368371
public static final int LIBVIRT_CGROUP_CPU_SHARES_MIN = 2;
369372
public static final int LIBVIRT_CGROUP_CPU_SHARES_MAX = 262144;
@@ -892,6 +895,7 @@ protected enum HealthCheckResult {
892895
protected String cachePath;
893896
private String vddkTransports = null;
894897
private String vddkThumbprint = null;
898+
private String vddkVersion = null;
895899
private String detectedPasswordFileOption = null;
896900
protected String javaTempDir = System.getProperty("java.io.tmpdir");
897901

@@ -973,6 +977,10 @@ public String getVddkThumbprint() {
973977
return vddkThumbprint;
974978
}
975979

980+
public String getVddkVersion() {
981+
return vddkVersion;
982+
}
983+
976984
/**
977985
* Defines resource's public and private network interface according to what is configured in agent.properties.
978986
*/
@@ -1178,7 +1186,25 @@ public boolean configure(final String name, final Map<String, Object> params) th
11781186

11791187
setConvertInstanceEnv(convertEnvTmpDir, convertEnvVirtv2vTmpDir);
11801188

1181-
vddkLibDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VDDK_LIB_DIR);
1189+
vddkLibDir = StringUtils.trimToNull(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VDDK_LIB_DIR));
1190+
if (StringUtils.isNotBlank(vddkLibDir) && !isVddkLibDirValid(vddkLibDir)) {
1191+
LOGGER.warn("Configured VDDK library dir [{}] is invalid (missing lib64/libvixDiskLib.so), attempting auto-detection", vddkLibDir);
1192+
vddkLibDir = null;
1193+
}
1194+
if (StringUtils.isBlank(vddkLibDir)) {
1195+
vddkLibDir = detectVddkLibDir();
1196+
}
1197+
if (StringUtils.isNotBlank(vddkLibDir)) {
1198+
LOGGER.info("Detected VDDK library dir: {}", vddkLibDir);
1199+
} else {
1200+
LOGGER.warn("Could not detect a valid VDDK library dir; VDDK conversion will be unavailable");
1201+
}
1202+
1203+
vddkVersion = detectVddkVersion();
1204+
if (StringUtils.isNotBlank(vddkVersion)) {
1205+
LOGGER.info("Detected nbdkit VDDK plugin version: {}", vddkVersion);
1206+
}
1207+
11821208
libguestfsBackend = StringUtils.defaultIfBlank(
11831209
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBGUESTFS_BACKEND), "direct");
11841210
vddkTransports = StringUtils.trimToNull(
@@ -4255,6 +4281,12 @@ public StartupCommand[] initialize() {
42554281
boolean instanceConversionSupported = hostSupportsInstanceConversion();
42564282
cmd.getHostDetails().put(HOST_INSTANCE_CONVERSION, String.valueOf(instanceConversionSupported));
42574283
cmd.getHostDetails().put(HOST_VDDK_SUPPORT, String.valueOf(hostSupportsVddk()));
4284+
if (StringUtils.isNotBlank(vddkLibDir)) {
4285+
cmd.getHostDetails().put(HOST_VDDK_LIB_DIR, vddkLibDir);
4286+
}
4287+
if (StringUtils.isNotBlank(vddkVersion)) {
4288+
cmd.getHostDetails().put(HOST_VDDK_VERSION, vddkVersion);
4289+
}
42584290
if (instanceConversionSupported) {
42594291
cmd.getHostDetails().put(HOST_VIRTV2V_VERSION, getHostVirtV2vVersion());
42604292
}
@@ -5971,7 +6003,52 @@ public boolean hostSupportsInstanceConversion() {
59716003
}
59726004

59736005
public boolean hostSupportsVddk() {
5974-
return hostSupportsInstanceConversion() && StringUtils.isNotBlank(vddkLibDir) && new File(vddkLibDir).isDirectory();
6006+
return hostSupportsInstanceConversion() && isVddkLibDirValid(vddkLibDir) && StringUtils.isNotBlank(vddkVersion);
6007+
}
6008+
6009+
protected boolean isVddkLibDirValid(String path) {
6010+
if (StringUtils.isBlank(path)) {
6011+
return false;
6012+
}
6013+
File libDir = new File(path, "lib64");
6014+
if (!libDir.isDirectory()) {
6015+
return false;
6016+
}
6017+
File[] libs = libDir.listFiles((dir, name) -> name.startsWith("libvixDiskLib.so"));
6018+
return libs != null && libs.length > 0;
6019+
}
6020+
6021+
protected String detectVddkLibDir() {
6022+
String detectedPath = StringUtils.trimToNull(Script.runSimpleBashScript(VDDK_AUTODETECT_PATH_CMD));
6023+
if (StringUtils.isNotBlank(detectedPath) && isVddkLibDirValid(detectedPath)) {
6024+
return detectedPath;
6025+
}
6026+
return null;
6027+
}
6028+
6029+
protected String detectVddkVersion() {
6030+
try {
6031+
ProcessBuilder pb = new ProcessBuilder("nbdkit", "vddk", "--version");
6032+
Process process = pb.start();
6033+
6034+
String output = new String(process.getInputStream().readAllBytes());
6035+
process.waitFor();
6036+
6037+
if (StringUtils.isBlank(output)) {
6038+
return null;
6039+
}
6040+
6041+
for (String line : output.split("\\R")) {
6042+
String trimmed = StringUtils.trimToEmpty(line);
6043+
if (trimmed.startsWith("vddk ")) {
6044+
return StringUtils.trimToNull(trimmed.substring("vddk ".length()));
6045+
}
6046+
}
6047+
return null;
6048+
} catch (Exception e) {
6049+
LOGGER.error("Failed to detect vddk version: {}", e.getMessage());
6050+
return null;
6051+
}
59756052
}
59766053

59776054
public boolean hostSupportsWindowsGuestConversion() {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.cloud.resource.CommandWrapper;
3535
import com.cloud.resource.ResourceWrapper;
3636
import com.cloud.utils.script.Script;
37+
import org.apache.commons.lang3.StringUtils;
3738

3839
@ResourceWrapper(handles = ReadyCommand.class)
3940
public final class LibvirtReadyCommandWrapper extends CommandWrapper<ReadyCommand, Answer, LibvirtComputingResource> {
@@ -51,6 +52,8 @@ public Answer execute(final ReadyCommand command, final LibvirtComputingResource
5152
hostDetails.put(Host.HOST_VIRTV2V_VERSION, libvirtComputingResource.getHostVirtV2vVersion());
5253
}
5354
hostDetails.put(Host.HOST_VDDK_SUPPORT, Boolean.toString(libvirtComputingResource.hostSupportsVddk()));
55+
hostDetails.put(Host.HOST_VDDK_LIB_DIR, StringUtils.defaultString(libvirtComputingResource.getVddkLibDir()));
56+
hostDetails.put(Host.HOST_VDDK_VERSION, StringUtils.defaultString(libvirtComputingResource.getVddkVersion()));
5457

5558
if (libvirtComputingResource.hostSupportsOvfExport()) {
5659
hostDetails.put(Host.HOST_OVFTOOL_VERSION, libvirtComputingResource.getHostOvfToolVersion());

server/src/main/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
209209
Arrays.asList(Storage.StoragePoolType.NetworkFilesystem, Storage.StoragePoolType.Filesystem,
210210
Storage.StoragePoolType.SharedMountPoint);
211211
private static final String DETAIL_LIBGUESTFS_BACKEND = "libguestfs.backend";
212-
private static final String DETAIL_VDDK_LIB_DIR = "vddk.lib.dir";
212+
private static final String DETAIL_VDDK_LIB_DIR = Host.HOST_VDDK_LIB_DIR;
213213
private static final String DETAIL_VDDK_TRANSPORTS = "vddk.transports";
214214
private static final String DETAIL_VDDK_THUMBPRINT = "vddk.thumbprint";
215215

server/src/test/java/org/apache/cloudstack/vm/UnmanagedVMsManagerImplTest.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,16 +1020,6 @@ public void testImportVmFromVmwareToKvmForceMsMutuallyExclusiveWithUseVddk() thr
10201020
baseTestImportVmFromVmwareToKvm(VcenterParameter.FORCE_MS_AND_USE_VDDK, false, false);
10211021
}
10221022

1023-
@Test
1024-
public void testImportVmFromVmwareToKvmUseVddkIsPassedToConvertCommand() throws OperationTimedoutException, AgentUnavailableException {
1025-
baseTestImportVmFromVmwareToKvm(VcenterParameter.USE_VDDK_OVF_SUPPORTED, false, false);
1026-
}
1027-
1028-
@Test
1029-
public void testImportVmFromVmwareToKvmDetailsOverrideVddkSettings() throws OperationTimedoutException, AgentUnavailableException {
1030-
baseTestImportVmFromVmwareToKvm(VcenterParameter.USE_VDDK_DETAILS_OVERRIDES, false, false);
1031-
}
1032-
10331023
@Test(expected = InvalidParameterValueException.class)
10341024
public void testValidateSelectedConversionStoragePoolForVddkFailsWhenPoolDoesNotSupportDiskOfferings() {
10351025
long poolId = 11L;

0 commit comments

Comments
 (0)