REQUESTED

detachISO from a running virtualmachine

Overview

trying to detachiso from running vm using java sdk but not able to.
Able to get runtimeinfo object and able get runtime power state and config details.
But when question object is returning null.Able to see question window from vsphere client but not from sdk

Here is the sample code for reference ;

String labelName="CD/DVD Drive 1";
String dsName = "Local_ex05";
List<VirtualDevice> deviceArr = ((ArrayOfVirtualDevice)entityProps(vimPort, serviceContent,clonevmMor,new String[]{"config.hardware.device"}).get("config.hardware.device")).getVirtualDevice();

VirtualDevice cdRom = null;
for (VirtualDevice device : deviceArr) {
if (device instanceof VirtualCdrom) {
Description info = device.getDeviceInfo();
if (info != null) {
if (info.getLabel().equalsIgnoreCase(labelName)) {
cdRom = device;
break;
}
}
}
}

VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);

VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
backingInfo.setDeviceName("");

cdRom.setBacking(backingInfo);
deviceConfigSpec.setDevice(cdRom);

List<VirtualDeviceConfigSpec> deviceConfigSpecArr = new ArrayList<VirtualDeviceConfigSpec>();
deviceConfigSpecArr.add(deviceConfigSpec);

VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
configSpec.getDeviceChange().addAll(deviceConfigSpecArr);
ManagedObjectReference editcdtask = vimPort.reconfigVMTask(clonevmMor, configSpec);

Map<String,Object> vmsumArr = entityProps(vimPort, serviceContent,clonevmMor,new String[]{"summary"});
final VirtualMachineSummary vmsum = (VirtualMachineSummary)vmsumArr.get("summary");
System.out.println("power state : "+ vmsum.getRuntime().getPowerState());
Thread.sleep(10000);
System.out.println("vm Name :"+vmsum.getConfig().getName());
final Boolean[] flags = {false};

ExecutorService executorService = Executors.newSingleThreadExecutor();

Future<?> future = executorService.submit(new Runnable() {
@Override
public void run() {
System.out.println("inside run");
VirtualMachineRuntimeInfo runtimeInfo = vmsum.getRuntime();
VirtualMachineQuestionInfo question = runtimeInfo.getQuestion();
if (question != null) {
if (question.getMessage() != null) {
for (VirtualMachineMessage msg : question.getMessage()) {
if ("msg.cdromdisconnect.locked".equalsIgnoreCase(msg.getId())) {
System.out.println("Found that VM has a pending question that we need to answer programmatically, question id: " + msg.getId() +
", for safe operation we will automatically decline it");
// vmMo.answerVM(question.getId(), "1");
break;
}
}
} else if (question.getText() != null) {
String text = question.getText();
System.out.println("Message : "+question.getText());
String msgId;
String msgText;
String[] tokens = text.split(":");
msgId = tokens[0];
msgText = tokens[1];
if ("msg.cdromdisconnect.locked".equalsIgnoreCase(msgId)) {
System.out.println("Found that VM has a pending question that we need to answer programmatically, question id: " + question.getId() +
". Message id : " + msgId + ". Message text : " + msgText + ", for safe operation we will automatically decline it.");
// vmMo.answerVM(question.getId(), "1");
}
}

}

}
});

future.get();