Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions agent/conf/agent.properties
Original file line number Diff line number Diff line change
Expand Up @@ -457,3 +457,19 @@ iscsi.session.cleanup.enabled=false

# Instance conversion VIRT_V2V_TMPDIR env var
#convert.instance.env.virtv2v.tmpdir=

# LIBGUESTFS backend to use for VMware to KVM conversion via VDDK (default: direct)
#libguestfs.backend=direct

# Path to the VDDK library directory for VMware to KVM conversion via VDDK,
# passed to virt-v2v as -io vddk-libdir=<path>
#vddk.lib.dir=

# Ordered VDDK transport preference for VMware to KVM conversion via VDDK, passed as
# -io vddk-transports=<value> to virt-v2v. Example: nbd:nbdssl
#vddk.transports=

# Optional vCenter SHA1 thumbprint for VMware to KVM conversion via VDDK, passed as
# -io vddk-thumbprint=<value>. If unset, CloudStack computes it on the KVM host via openssl.
#vddk.thumbprint=

Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,37 @@ public Property<Integer> getWorkers() {
*/
public static final Property<String> CONVERT_ENV_VIRTV2V_TMPDIR = new Property<>("convert.instance.env.virtv2v.tmpdir", null, String.class);

/**
* Path to the VDDK library directory on the KVM conversion host, used when converting VMs from VMware to KVM via VDDK.
* This directory is passed to virt-v2v as <code>-io vddk-libdir=&lt;path&gt;</code>.
* Data type: String.<br>
* Default value: <code>null</code>
*/
public static final Property<String> VDDK_LIB_DIR = new Property<>("vddk.lib.dir", null, String.class);

/**
* Value for the LIBGUESTFS_BACKEND env var used during VMware to KVM conversion via VDDK.
* Data type: String.<br>
* Default value: <code>direct</code>
*/
public static final Property<String> LIBGUESTFS_BACKEND = new Property<>("libguestfs.backend", "direct", String.class);

/**
* Ordered list of VDDK transports for virt-v2v, passed as <code>-io vddk-transports=&lt;value&gt;</code>.
* Example: <code>nbd:nbdssl</code>.
* Data type: String.<br>
* Default value: <code>null</code>
*/
public static final Property<String> VDDK_TRANSPORTS = new Property<>("vddk.transports", null, String.class);

/**
* vCenter TLS certificate thumbprint used by virt-v2v VDDK mode, passed as <code>-io vddk-thumbprint=&lt;value&gt;</code>.
* If unset, the KVM host computes it at runtime from the vCenter endpoint.
* Data type: String.<br>
* Default value: <code>null</code>
*/
public static final Property<String> VDDK_THUMBPRINT = new Property<>("vddk.thumbprint", null, String.class);

/**
* BGP controll CIDR
* Data type: String.<br>
Expand Down
20 changes: 19 additions & 1 deletion api/src/main/java/com/cloud/agent/api/to/RemoteInstanceTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ public class RemoteInstanceTO implements Serializable {
private String vcenterPassword;
private String vcenterHost;
private String datacenterName;
private String clusterName;
private String hostName;

public RemoteInstanceTO() {
}

public RemoteInstanceTO(String instanceName) {
public RemoteInstanceTO(String instanceName, String clusterName, String hostName) {
this.hypervisorType = Hypervisor.HypervisorType.VMware;
this.instanceName = instanceName;
this.clusterName = clusterName;
this.hostName = hostName;
}

public RemoteInstanceTO(String instanceName, String instancePath, String vcenterHost, String vcenterUsername, String vcenterPassword, String datacenterName) {
Expand All @@ -55,6 +59,12 @@ public RemoteInstanceTO(String instanceName, String instancePath, String vcenter
this.datacenterName = datacenterName;
}

public RemoteInstanceTO(String instanceName, String instancePath, String vcenterHost, String vcenterUsername, String vcenterPassword, String datacenterName, String clusterName, String hostName) {
this(instanceName, instancePath, vcenterHost, vcenterUsername, vcenterPassword, datacenterName);
this.clusterName = clusterName;
this.hostName = hostName;
}

public Hypervisor.HypervisorType getHypervisorType() {
return this.hypervisorType;
}
Expand Down Expand Up @@ -82,4 +92,12 @@ public String getVcenterHost() {
public String getDatacenterName() {
return datacenterName;
}

public String getClusterName() {
return clusterName;
}

public String getHostName() {
return hostName;
}
}
1 change: 1 addition & 0 deletions api/src/main/java/com/cloud/host/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static String[] toStrings(Host.Type... types) {
String HOST_UEFI_ENABLE = "host.uefi.enable";
String HOST_VOLUME_ENCRYPTION = "host.volume.encryption";
String HOST_INSTANCE_CONVERSION = "host.instance.conversion";
String HOST_VDDK_SUPPORT = "host.vddk.support";
String HOST_OVFTOOL_VERSION = "host.ovftool.version";
String HOST_VIRTV2V_VERSION = "host.virtv2v.version";
String HOST_SSH_PORT = "host.ssh.port";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@ public class ApiConstants {
public static final String USER_CONFIGURABLE = "userconfigurable";
public static final String USER_SECURITY_GROUP_LIST = "usersecuritygrouplist";
public static final String USER_SECRET_KEY = "usersecretkey";
public static final String USE_VDDK = "usevddk";
public static final String USE_VIRTUAL_NETWORK = "usevirtualnetwork";
public static final String USE_VIRTUAL_ROUTER_IP_RESOLVER = "userouteripresolver";
public static final String UPDATE_IN_SEQUENCE = "updateinsequence";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ public class ImportVmCmd extends ImportUnmanagedInstanceCmd {
description = "(only for importing VMs from VMware to KVM) optional - the ID of the guest OS for the imported VM.")
private Long guestOsId;

@Parameter(name = ApiConstants.USE_VDDK,
type = CommandType.BOOLEAN,
since = "4.22.1",
description = "(only for importing VMs from VMware to KVM) optional - if true, uses VDDK on the KVM conversion host for converting the VM. " +
"This parameter is mutually exclusive with " + ApiConstants.FORCE_MS_TO_IMPORT_VM_FILES + ".")
private Boolean useVddk;


/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -255,6 +263,10 @@ public Long getStoragePoolId() {
return storagePoolId;
}

public boolean getUseVddk() {
return BooleanUtils.toBooleanDefaultIfNull(useVddk, false);
}

public String getTmpPath() {
return tmpPath;
}
Expand Down
45 changes: 45 additions & 0 deletions core/src/main/java/com/cloud/agent/api/ConvertInstanceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class ConvertInstanceCommand extends Command {
private boolean exportOvfToConversionLocation;
private int threadsCountToExportOvf = 0;
private String extraParams;
private boolean useVddk;
private String libguestfsBackend;
private String vddkLibDir;
private String vddkTransports;
private String vddkThumbprint;

public ConvertInstanceCommand() {
}
Expand Down Expand Up @@ -90,6 +95,46 @@ public void setExtraParams(String extraParams) {
this.extraParams = extraParams;
}

public boolean isUseVddk() {
return useVddk;
}

public void setUseVddk(boolean useVddk) {
this.useVddk = useVddk;
}

public String getLibguestfsBackend() {
return libguestfsBackend;
}

public void setLibguestfsBackend(String libguestfsBackend) {
this.libguestfsBackend = libguestfsBackend;
}

public String getVddkLibDir() {
return vddkLibDir;
}

public void setVddkLibDir(String vddkLibDir) {
this.vddkLibDir = vddkLibDir;
}

public String getVddkTransports() {
return vddkTransports;
}

public void setVddkTransports(String vddkTransports) {
this.vddkTransports = vddkTransports;
}

public String getVddkThumbprint() {
return vddkThumbprint;
}

public void setVddkThumbprint(String vddkThumbprint) {
this.vddkThumbprint = vddkThumbprint;
}

@Override
public boolean executeInSequence() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -805,8 +805,9 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
String uefiEnabled = detailsMap.get(Host.HOST_UEFI_ENABLE);
String virtv2vVersion = detailsMap.get(Host.HOST_VIRTV2V_VERSION);
String ovftoolVersion = detailsMap.get(Host.HOST_OVFTOOL_VERSION);
String vddkSupport = detailsMap.get(Host.HOST_VDDK_SUPPORT);
logger.debug("Got HOST_UEFI_ENABLE [{}] for host [{}]:", uefiEnabled, host);
if (ObjectUtils.anyNotNull(uefiEnabled, virtv2vVersion, ovftoolVersion)) {
if (ObjectUtils.anyNotNull(uefiEnabled, virtv2vVersion, ovftoolVersion, vddkSupport)) {
_hostDao.loadDetails(host);
boolean updateNeeded = false;
if (StringUtils.isNotBlank(uefiEnabled) && !uefiEnabled.equals(host.getDetails().get(Host.HOST_UEFI_ENABLE))) {
Expand All @@ -821,6 +822,10 @@ protected AgentAttache notifyMonitorsOfConnection(final AgentAttache attache, fi
host.getDetails().put(Host.HOST_OVFTOOL_VERSION, ovftoolVersion);
updateNeeded = true;
}
if (StringUtils.isNotBlank(vddkSupport) && !vddkSupport.equals(host.getDetails().get(Host.HOST_VDDK_SUPPORT))) {
host.getDetails().put(Host.HOST_VDDK_SUPPORT, vddkSupport);
updateNeeded = true;
}
if (updateNeeded) {
_hostDao.saveDetails(host);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static com.cloud.host.Host.HOST_INSTANCE_CONVERSION;
import static com.cloud.host.Host.HOST_OVFTOOL_VERSION;
import static com.cloud.host.Host.HOST_VDDK_SUPPORT;
import static com.cloud.host.Host.HOST_VIRTV2V_VERSION;
import static com.cloud.host.Host.HOST_VOLUME_ENCRYPTION;
import static org.apache.cloudstack.utils.linux.KVMHostInfo.isHostS390x;
Expand Down Expand Up @@ -883,10 +884,15 @@ protected enum HealthCheckResult {

private boolean convertInstanceVerboseMode = false;
private Map<String, String> convertInstanceEnv = null;
private String vddkLibDir = null;
private String libguestfsBackend = "direct";
protected boolean dpdkSupport = false;
protected String dpdkOvsPath;
protected String directDownloadTemporaryDownloadPath;
protected String cachePath;
private String vddkTransports = null;
private String vddkThumbprint = null;
private String detectedPasswordFileOption = null;
protected String javaTempDir = System.getProperty("java.io.tmpdir");

private String getEndIpFromStartIp(final String startIp, final int numIps) {
Expand Down Expand Up @@ -951,6 +957,22 @@ public Map<String, String> getConvertInstanceEnv() {
return convertInstanceEnv;
}

public String getVddkLibDir() {
return vddkLibDir;
}

public String getLibguestfsBackend() {
return libguestfsBackend;
}

public String getVddkTransports() {
return vddkTransports;
}

public String getVddkThumbprint() {
return vddkThumbprint;
}

/**
* Defines resource's public and private network interface according to what is configured in agent.properties.
*/
Expand Down Expand Up @@ -1156,6 +1178,21 @@ public boolean configure(final String name, final Map<String, Object> params) th

setConvertInstanceEnv(convertEnvTmpDir, convertEnvVirtv2vTmpDir);

vddkLibDir = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VDDK_LIB_DIR);
libguestfsBackend = StringUtils.defaultIfBlank(
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.LIBGUESTFS_BACKEND), "direct");
vddkTransports = StringUtils.trimToNull(
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VDDK_TRANSPORTS));
vddkThumbprint = StringUtils.trimToNull(
AgentPropertiesFileHandler.getPropertyValue(AgentProperties.VDDK_THUMBPRINT));

detectedPasswordFileOption = detectPasswordFileOption();
if (StringUtils.isNotBlank(detectedPasswordFileOption)) {
LOGGER.info("Detected virt-v2v password option: {}", detectedPasswordFileOption);
} else {
LOGGER.warn("Could not detect virt-v2v password option, VDDK conversions may fail");
}

pool = (String)params.get("pool");
if (pool == null) {
pool = "/root";
Expand Down Expand Up @@ -4217,6 +4254,7 @@ public StartupCommand[] initialize() {
cmd.setHostTags(getHostTags());
boolean instanceConversionSupported = hostSupportsInstanceConversion();
cmd.getHostDetails().put(HOST_INSTANCE_CONVERSION, String.valueOf(instanceConversionSupported));
cmd.getHostDetails().put(HOST_VDDK_SUPPORT, String.valueOf(hostSupportsVddk()));
if (instanceConversionSupported) {
cmd.getHostDetails().put(HOST_VIRTV2V_VERSION, getHostVirtV2vVersion());
}
Expand Down Expand Up @@ -5932,6 +5970,10 @@ public boolean hostSupportsInstanceConversion() {
return exitValue == 0;
}

public boolean hostSupportsVddk() {
return hostSupportsInstanceConversion() && StringUtils.isNotBlank(vddkLibDir) && new File(vddkLibDir).isDirectory();
}

public boolean hostSupportsWindowsGuestConversion() {
if (isUbuntuOrDebianHost()) {
int exitValue = Script.runSimpleBashScriptForExitValue(UBUNTU_WINDOWS_GUEST_CONVERSION_SUPPORTED_CHECK_CMD);
Expand All @@ -5946,6 +5988,40 @@ public boolean hostSupportsOvfExport() {
return exitValue == 0;
}

/**
* Detect which password option virt-v2v supports by examining its --help output
* @return "-ip" if supported (virt-v2v >= 2.8.1), "--password-file" if older version, or null if detection fails
*/
protected String detectPasswordFileOption() {
try {
ProcessBuilder pb = new ProcessBuilder("virt-v2v", "--help");
Process process = pb.start();

String output = new String(process.getInputStream().readAllBytes());
process.waitFor();

if (output.contains("-ip <filename>")) {
return "-ip";
} else if (output.contains("--password-file")) {
return "--password-file";
} else {
LOGGER.error("virt-v2v does not support -ip or --password-file");
return null;
}
} catch (Exception e) {
LOGGER.error("Failed to detect virt-v2v password option: {}", e.getMessage());
return null;
}
}

/**
* Get the detected password file option for virt-v2v
* @return the password option ("-ip" or "--password-file") or null if not detected
*/
public String getDetectedPasswordFileOption() {
return detectedPasswordFileOption;
}

public String getHostVirtV2vVersion() {
if (!hostSupportsInstanceConversion()) {
return "";
Expand Down
Loading
Loading