Skip to content

Commit 48e91a1

Browse files
authored
Merge pull request #691 from jschoiRR/mold-main#2025
[Mold API] VMware 가져오기 - 데이터 센터의 루트 폴더('vm')가 아닌 모든 폴더/하위 폴더에 있는 외부 VM 지원
2 parents 59c2ea8 + 360f5a9 commit 48e91a1

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
lines changed

api/src/main/java/com/cloud/agent/api/to/RemoteInstanceTO.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class RemoteInstanceTO implements Serializable {
2727

2828
private Hypervisor.HypervisorType hypervisorType;
2929
private String instanceName;
30+
private String instancePath;
3031

3132
// VMware Remote Instances parameters (required for exporting OVA through ovftool)
3233
// TODO: cloud.agent.transport.Request#getCommands() cannot handle gsoc decode for polymorphic classes
@@ -44,9 +45,10 @@ public RemoteInstanceTO(String instanceName) {
4445
this.instanceName = instanceName;
4546
}
4647

47-
public RemoteInstanceTO(String instanceName, String vcenterHost, String vcenterUsername, String vcenterPassword, String datacenterName) {
48+
public RemoteInstanceTO(String instanceName, String instancePath, String vcenterHost, String vcenterUsername, String vcenterPassword, String datacenterName) {
4849
this.hypervisorType = Hypervisor.HypervisorType.VMware;
4950
this.instanceName = instanceName;
51+
this.instancePath = instancePath;
5052
this.vcenterHost = vcenterHost;
5153
this.vcenterUsername = vcenterUsername;
5254
this.vcenterPassword = vcenterPassword;
@@ -61,6 +63,10 @@ public String getInstanceName() {
6163
return this.instanceName;
6264
}
6365

66+
public String getInstancePath() {
67+
return this.instancePath;
68+
}
69+
6470
public String getVcenterUsername() {
6571
return vcenterUsername;
6672
}

api/src/main/java/org/apache/cloudstack/vm/UnmanagedInstanceTO.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public enum PowerState {
3333

3434
private String internalCSName;
3535

36+
private String path;
37+
3638
private PowerState powerState;
3739

3840
private PowerState cloneSourcePowerState;
@@ -75,6 +77,14 @@ public void setInternalCSName(String internalCSName) {
7577
this.internalCSName = internalCSName;
7678
}
7779

80+
public String getPath() {
81+
return path;
82+
}
83+
84+
public void setPath(String path) {
85+
this.path = path;
86+
}
87+
7888
public PowerState getPowerState() {
7989
return powerState;
8090
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,15 @@ private String getExportOVAUrlFromRemoteInstance(RemoteInstanceTO vmwareInstance
171171
String password = vmwareInstance.getVcenterPassword();
172172
String datacenter = vmwareInstance.getDatacenterName();
173173
String vm = vmwareInstance.getInstanceName();
174+
String path = vmwareInstance.getInstancePath();
174175

175176
String encodedUsername = encodeUsername(username);
176177
String encodedPassword = encodeUsername(password);
178+
if (StringUtils.isNotBlank(path)) {
179+
logger.info("VM path: {}", path);
180+
return String.format("vi://%s:%s@%s/%s/%s/%s",
181+
encodedUsername, encodedPassword, vcenter, datacenter, path, vm);
182+
}
177183
return String.format("vi://%s:%s@%s/%s/vm/%s",
178184
encodedUsername, encodedPassword, vcenter, datacenter, vm);
179185
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ private UnmanagedInstanceTO convertVmwareInstanceToKVMAfterExportingOVFToConvert
19821982
logger.debug(String.format("Delegating the conversion of instance %s from VMware to KVM to the host %s (%s) after OVF export through ovftool",
19831983
sourceVM, convertHost.getId(), convertHost.getName()));
19841984

1985-
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO(sourceVMwareInstance.getName(), vcenterHost, vcenterUsername, vcenterPassword, datacenterName);
1985+
RemoteInstanceTO remoteInstanceTO = new RemoteInstanceTO(sourceVMwareInstance.getName(), sourceVMwareInstance.getPath(), vcenterHost, vcenterUsername, vcenterPassword, datacenterName);
19861986
List<String> destinationStoragePools = selectInstanceConversionStoragePools(convertStoragePools, sourceVMwareInstance.getDisks(), serviceOffering, dataDiskOfferingMap);
19871987
ConvertInstanceCommand cmd = new ConvertInstanceCommand(remoteInstanceTO,
19881988
Hypervisor.HypervisorType.KVM, temporaryConvertLocation, null, false, true);

vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,27 @@ public VirtualMachineFileLayoutEx getFileLayout() throws Exception {
996996
return fileLayout;
997997
}
998998

999+
public String getPath() throws Exception {
1000+
List<String> subPaths = new ArrayList<>();
1001+
ManagedObjectReference mor = _context.getVimClient().getDynamicProperty(_mor, "parent");
1002+
while (mor != null && mor.getType().equalsIgnoreCase("Folder")) {
1003+
String subPath = _context.getVimClient().getDynamicProperty(mor, "name");
1004+
if (StringUtils.isBlank(subPath)) {
1005+
return null;
1006+
}
1007+
subPaths.add(subPath);
1008+
mor = _context.getVimClient().getDynamicProperty(mor, "parent");
1009+
}
1010+
1011+
if (!subPaths.isEmpty()) {
1012+
Collections.reverse(subPaths);
1013+
String path = StringUtils.join(subPaths, "/");
1014+
return path;
1015+
}
1016+
1017+
return null;
1018+
}
1019+
9991020
@Override
10001021
public ManagedObjectReference getParentMor() throws Exception {
10011022
return (ManagedObjectReference)_context.getVimClient().getDynamicProperty(_mor, "parent");

vmware-base/src/main/java/com/cloud/hypervisor/vmware/util/VmwareHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,7 @@ public static UnmanagedInstanceTO getUnmanagedInstance(VmwareHypervisorHost hype
802802
instance = new UnmanagedInstanceTO();
803803
instance.setName(vmMo.getVmName());
804804
instance.setInternalCSName(vmMo.getInternalCSName());
805+
instance.setPath((vmMo.getPath()));
805806
instance.setCpuCoresPerSocket(vmMo.getCoresPerSocket());
806807
instance.setOperatingSystemId(vmMo.getVmGuestInfo().getGuestId());
807808
VirtualMachineConfigSummary configSummary = vmMo.getConfigSummary();

0 commit comments

Comments
 (0)