mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
[VMware] Disconnect/Detach config drive ISO (if exists) on stop VM (#9468)
This commit is contained in:
parent
11497c601f
commit
6c0492366c
@ -55,6 +55,7 @@ import com.vmware.vim25.FileQueryFlags;
|
|||||||
import com.vmware.vim25.FolderFileInfo;
|
import com.vmware.vim25.FolderFileInfo;
|
||||||
import com.vmware.vim25.HostDatastoreBrowserSearchResults;
|
import com.vmware.vim25.HostDatastoreBrowserSearchResults;
|
||||||
import com.vmware.vim25.HostDatastoreBrowserSearchSpec;
|
import com.vmware.vim25.HostDatastoreBrowserSearchSpec;
|
||||||
|
import com.vmware.vim25.VirtualCdromIsoBackingInfo;
|
||||||
import com.vmware.vim25.VirtualMachineConfigSummary;
|
import com.vmware.vim25.VirtualMachineConfigSummary;
|
||||||
import org.apache.cloudstack.api.ApiConstants;
|
import org.apache.cloudstack.api.ApiConstants;
|
||||||
import org.apache.cloudstack.backup.PrepareForBackupRestorationCommand;
|
import org.apache.cloudstack.backup.PrepareForBackupRestorationCommand;
|
||||||
@ -2738,8 +2739,9 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
|
|
||||||
private DiskTO[] getDisks(DiskTO[] sortedDisks) {
|
private DiskTO[] getDisks(DiskTO[] sortedDisks) {
|
||||||
return Arrays.stream(sortedDisks).filter(vol -> ((vol.getPath() != null &&
|
return Arrays.stream(sortedDisks).filter(vol -> ((vol.getPath() != null &&
|
||||||
vol.getPath().contains("configdrive"))) || (vol.getType() != Volume.Type.ISO)).toArray(DiskTO[]::new);
|
vol.getPath().contains(ConfigDrive.CONFIGDRIVEDIR))) || (vol.getType() != Volume.Type.ISO)).toArray(DiskTO[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureIso(VmwareHypervisorHost hyperHost, VirtualMachineMO vmMo, DiskTO vol,
|
private void configureIso(VmwareHypervisorHost hyperHost, VirtualMachineMO vmMo, DiskTO vol,
|
||||||
VirtualDeviceConfigSpec[] deviceConfigSpecArray, int ideUnitNumber, int i) throws Exception {
|
VirtualDeviceConfigSpec[] deviceConfigSpecArray, int ideUnitNumber, int i) throws Exception {
|
||||||
TemplateObjectTO iso = (TemplateObjectTO) vol.getData();
|
TemplateObjectTO iso = (TemplateObjectTO) vol.getData();
|
||||||
@ -4448,6 +4450,8 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
msg = "Have problem in powering off VM " + cmd.getVmName() + ", let the process continue";
|
msg = "Have problem in powering off VM " + cmd.getVmName() + ", let the process continue";
|
||||||
s_logger.warn(msg);
|
s_logger.warn(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
disconnectConfigDriveIsoIfExists(vmMo);
|
||||||
return new StopAnswer(cmd, msg, true);
|
return new StopAnswer(cmd, msg, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4466,6 +4470,30 @@ public class VmwareResource extends ServerResourceBase implements StoragePoolRes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
s_logger.warn(String.format("Couldn't check/disconnect config drive, error: %s", e.getMessage()), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected Answer execute(RebootRouterCommand cmd) {
|
protected Answer execute(RebootRouterCommand cmd) {
|
||||||
RebootAnswer answer = (RebootAnswer) execute((RebootCommand) cmd);
|
RebootAnswer answer = (RebootAnswer) execute((RebootCommand) cmd);
|
||||||
|
|
||||||
|
|||||||
@ -3203,6 +3203,14 @@ public class VirtualMachineMO extends BaseMO {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<VirtualDevice> getIsoDevices() throws Exception {
|
||||||
|
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
|
||||||
|
if (CollectionUtils.isEmpty(devices)) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
return devices.stream().filter(device -> device instanceof VirtualCdrom).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
public VirtualDevice getIsoDevice(int key) throws Exception {
|
public VirtualDevice getIsoDevice(int key) throws Exception {
|
||||||
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
|
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
|
||||||
if (devices != null && devices.size() > 0) {
|
if (devices != null && devices.size() > 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user