mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
VMware Import - Support external VMs in any folders/subfolders other than the root folder ('vm') of datacenter (#10411)
This commit is contained in:
parent
b6cebe22f9
commit
b9ebc7b721
@ -27,6 +27,7 @@ public class RemoteInstanceTO implements Serializable {
|
|||||||
|
|
||||||
private Hypervisor.HypervisorType hypervisorType;
|
private Hypervisor.HypervisorType hypervisorType;
|
||||||
private String instanceName;
|
private String instanceName;
|
||||||
|
private String instancePath;
|
||||||
|
|
||||||
// VMware Remote Instances parameters (required for exporting OVA through ovftool)
|
// VMware Remote Instances parameters (required for exporting OVA through ovftool)
|
||||||
// TODO: cloud.agent.transport.Request#getCommands() cannot handle gsoc decode for polymorphic classes
|
// TODO: cloud.agent.transport.Request#getCommands() cannot handle gsoc decode for polymorphic classes
|
||||||
@ -44,9 +45,10 @@ public class RemoteInstanceTO implements Serializable {
|
|||||||
this.instanceName = instanceName;
|
this.instanceName = instanceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RemoteInstanceTO(String instanceName, String vcenterHost, String vcenterUsername, String vcenterPassword, String datacenterName) {
|
public RemoteInstanceTO(String instanceName, String instancePath, String vcenterHost, String vcenterUsername, String vcenterPassword, String datacenterName) {
|
||||||
this.hypervisorType = Hypervisor.HypervisorType.VMware;
|
this.hypervisorType = Hypervisor.HypervisorType.VMware;
|
||||||
this.instanceName = instanceName;
|
this.instanceName = instanceName;
|
||||||
|
this.instancePath = instancePath;
|
||||||
this.vcenterHost = vcenterHost;
|
this.vcenterHost = vcenterHost;
|
||||||
this.vcenterUsername = vcenterUsername;
|
this.vcenterUsername = vcenterUsername;
|
||||||
this.vcenterPassword = vcenterPassword;
|
this.vcenterPassword = vcenterPassword;
|
||||||
@ -61,6 +63,10 @@ public class RemoteInstanceTO implements Serializable {
|
|||||||
return this.instanceName;
|
return this.instanceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getInstancePath() {
|
||||||
|
return this.instancePath;
|
||||||
|
}
|
||||||
|
|
||||||
public String getVcenterUsername() {
|
public String getVcenterUsername() {
|
||||||
return vcenterUsername;
|
return vcenterUsername;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,8 @@ public class UnmanagedInstanceTO {
|
|||||||
|
|
||||||
private String internalCSName;
|
private String internalCSName;
|
||||||
|
|
||||||
|
private String path;
|
||||||
|
|
||||||
private PowerState powerState;
|
private PowerState powerState;
|
||||||
|
|
||||||
private PowerState cloneSourcePowerState;
|
private PowerState cloneSourcePowerState;
|
||||||
@ -75,6 +77,14 @@ public class UnmanagedInstanceTO {
|
|||||||
this.internalCSName = internalCSName;
|
this.internalCSName = internalCSName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
public PowerState getPowerState() {
|
public PowerState getPowerState() {
|
||||||
return powerState;
|
return powerState;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,7 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
|||||||
RemoteInstanceTO sourceInstance = cmd.getSourceInstance();
|
RemoteInstanceTO sourceInstance = cmd.getSourceInstance();
|
||||||
Hypervisor.HypervisorType sourceHypervisorType = sourceInstance.getHypervisorType();
|
Hypervisor.HypervisorType sourceHypervisorType = sourceInstance.getHypervisorType();
|
||||||
String sourceInstanceName = sourceInstance.getInstanceName();
|
String sourceInstanceName = sourceInstance.getInstanceName();
|
||||||
|
String sourceInstancePath = sourceInstance.getInstancePath();
|
||||||
Hypervisor.HypervisorType destinationHypervisorType = cmd.getDestinationHypervisorType();
|
Hypervisor.HypervisorType destinationHypervisorType = cmd.getDestinationHypervisorType();
|
||||||
DataStoreTO conversionTemporaryLocation = cmd.getConversionTemporaryLocation();
|
DataStoreTO conversionTemporaryLocation = cmd.getConversionTemporaryLocation();
|
||||||
long timeout = (long) cmd.getWait() * 1000;
|
long timeout = (long) cmd.getWait() * 1000;
|
||||||
@ -177,9 +178,15 @@ public class LibvirtConvertInstanceCommandWrapper extends CommandWrapper<Convert
|
|||||||
String password = vmwareInstance.getVcenterPassword();
|
String password = vmwareInstance.getVcenterPassword();
|
||||||
String datacenter = vmwareInstance.getDatacenterName();
|
String datacenter = vmwareInstance.getDatacenterName();
|
||||||
String vm = vmwareInstance.getInstanceName();
|
String vm = vmwareInstance.getInstanceName();
|
||||||
|
String path = vmwareInstance.getInstancePath();
|
||||||
|
|
||||||
String encodedUsername = encodeUsername(username);
|
String encodedUsername = encodeUsername(username);
|
||||||
String encodedPassword = encodeUsername(password);
|
String encodedPassword = encodeUsername(password);
|
||||||
|
if (StringUtils.isNotBlank(path)) {
|
||||||
|
s_logger.info("VM path: " + path);
|
||||||
|
return String.format("vi://%s:%s@%s/%s/%s/%s",
|
||||||
|
encodedUsername, encodedPassword, vcenter, datacenter, path, vm);
|
||||||
|
}
|
||||||
return String.format("vi://%s:%s@%s/%s/vm/%s",
|
return String.format("vi://%s:%s@%s/%s/vm/%s",
|
||||||
encodedUsername, encodedPassword, vcenter, datacenter, vm);
|
encodedUsername, encodedPassword, vcenter, datacenter, vm);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1947,7 +1947,7 @@ public class UnmanagedVMsManagerImpl implements UnmanagedVMsManager {
|
|||||||
LOGGER.debug(String.format("Delegating the conversion of instance %s from VMware to KVM to the host %s (%s) after OVF export through ovftool",
|
LOGGER.debug(String.format("Delegating the conversion of instance %s from VMware to KVM to the host %s (%s) after OVF export through ovftool",
|
||||||
sourceVM, convertHost.getId(), convertHost.getName()));
|
sourceVM, convertHost.getId(), convertHost.getName()));
|
||||||
|
|
||||||
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO(sourceVMwareInstance.getName(), vcenterHost, vcenterUsername, vcenterPassword, datacenterName);
|
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO(sourceVMwareInstance.getName(), sourceVMwareInstance.getPath(), vcenterHost, vcenterUsername, vcenterPassword, datacenterName);
|
||||||
List<String> destinationStoragePools = selectInstanceConversionStoragePools(convertStoragePools, sourceVMwareInstance.getDisks(), serviceOffering, dataDiskOfferingMap);
|
List<String> destinationStoragePools = selectInstanceConversionStoragePools(convertStoragePools, sourceVMwareInstance.getDisks(), serviceOffering, dataDiskOfferingMap);
|
||||||
ConvertInstanceCommand cmd = new ConvertInstanceCommand(remoteInstanceTO,
|
ConvertInstanceCommand cmd = new ConvertInstanceCommand(remoteInstanceTO,
|
||||||
Hypervisor.HypervisorType.KVM, temporaryConvertLocation, null, false, true);
|
Hypervisor.HypervisorType.KVM, temporaryConvertLocation, null, false, true);
|
||||||
|
|||||||
@ -891,6 +891,27 @@ public class VirtualMachineMO extends BaseMO {
|
|||||||
return fileLayout;
|
return fileLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPath() throws Exception {
|
||||||
|
List<String> subPaths = new ArrayList<>();
|
||||||
|
ManagedObjectReference mor = _context.getVimClient().getDynamicProperty(_mor, "parent");
|
||||||
|
while (mor != null && mor.getType().equalsIgnoreCase("Folder")) {
|
||||||
|
String subPath = _context.getVimClient().getDynamicProperty(mor, "name");
|
||||||
|
if (StringUtils.isBlank(subPath)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
subPaths.add(subPath);
|
||||||
|
mor = _context.getVimClient().getDynamicProperty(mor, "parent");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!subPaths.isEmpty()) {
|
||||||
|
Collections.reverse(subPaths);
|
||||||
|
String path = StringUtils.join(subPaths, "/");
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ManagedObjectReference getParentMor() throws Exception {
|
public ManagedObjectReference getParentMor() throws Exception {
|
||||||
return _context.getVimClient().getDynamicProperty(_mor, "parent");
|
return _context.getVimClient().getDynamicProperty(_mor, "parent");
|
||||||
|
|||||||
@ -801,6 +801,7 @@ public class VmwareHelper {
|
|||||||
instance = new UnmanagedInstanceTO();
|
instance = new UnmanagedInstanceTO();
|
||||||
instance.setName(vmMo.getVmName());
|
instance.setName(vmMo.getVmName());
|
||||||
instance.setInternalCSName(vmMo.getInternalCSName());
|
instance.setInternalCSName(vmMo.getInternalCSName());
|
||||||
|
instance.setPath((vmMo.getPath()));
|
||||||
instance.setCpuCoresPerSocket(vmMo.getCoresPerSocket());
|
instance.setCpuCoresPerSocket(vmMo.getCoresPerSocket());
|
||||||
instance.setOperatingSystemId(vmMo.getVmGuestInfo().getGuestId());
|
instance.setOperatingSystemId(vmMo.getVmGuestInfo().getGuestId());
|
||||||
VirtualMachineConfigSummary configSummary = vmMo.getConfigSummary();
|
VirtualMachineConfigSummary configSummary = vmMo.getConfigSummary();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user