shwstppr commented on code in PR #9468:
URL: https://github.com/apache/cloudstack/pull/9468#discussion_r1726592669
##########
vmware-base/src/main/java/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java:
##########
@@ -3203,6 +3203,19 @@ public VirtualDevice getIsoDevice() throws Exception {
return null;
}
+ public List<VirtualDevice> getIsoDevices() throws Exception {
+ List<VirtualDevice> isoDevices = new ArrayList<>();
+ List<VirtualDevice> devices =
_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
+ if (devices != null && devices.size() > 0) {
+ for (VirtualDevice device : devices) {
+ if (device instanceof VirtualCdrom) {
+ isoDevices.add(device);
+ }
+ }
+ }
+ return isoDevices;
Review Comment:
```suggestion
List<VirtualDevice> devices =
_context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
if (CollectionUtils.isEmpty(devices)) {
return new ArrayList<>();
}
return devices.stream().filter(d -> d instanceof
VirtualCdrom).collect(Collectors.toList());
```
##########
plugins/hypervisors/vmware/src/main/java/com/cloud/hypervisor/vmware/resource/VmwareResource.java:
##########
@@ -4466,6 +4470,28 @@ protected Answer execute(StopCommand cmd) {
}
}
+ private void disconnectConfigDriveIsoIfExists(VirtualMachineMO vmMo) {
+ try {
+ List<VirtualDevice> isoDevices = vmMo.getIsoDevices();
+ if (CollectionUtils.isEmpty(isoDevices)) {
+ return;
+ }
+
+ for (VirtualDevice isoDevice : isoDevices) {
+ if(isoDevice.getBacking() instanceof
VirtualCdromIsoBackingInfo) {
+ String isoFilePath =
((VirtualCdromIsoBackingInfo)isoDevice.getBacking()).getFileName();
+ if (isoFilePath.contains(ConfigDrive.CONFIGDRIVEDIR)) {
+ s_logger.info(String.format("Disconnecting config
drive at location: %s", isoFilePath));
+ vmMo.detachIso(isoFilePath, true);
+ return;
+ }
+ }
Review Comment:
```suggestion
if(!(isoDevice.getBacking() instanceof
VirtualCdromIsoBackingInfo)) {
continue;
}
String isoFilePath =
((VirtualCdromIsoBackingInfo)isoDevice.getBacking()).getFileName();
if (!isoFilePath.contains(ConfigDrive.CONFIGDRIVEDIR)) {
continue;
}
s_logger.info(String.format("Disconnecting config drive at
location: %s", isoFilePath));
vmMo.detachIso(isoFilePath, true);
return;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]