Search in sources :

Example 1 with VirtualCdromRemotePassthroughBackingInfo

use of com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo in project CloudStack-archive by CloudStack-extras.

the class VirtualMachineMO method detachIso.

public void detachIso(String isoDatastorePath) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.get_value() + ", isoDatastorePath: " + isoDatastorePath);
    VirtualDevice device = getIsoDevice();
    if (device == null) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - detachIso() done(failed)");
        throw new Exception("Unable to find a CDROM device");
    }
    VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
    backingInfo.setDeviceName("");
    device.setBacking(backingInfo);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(device);
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
    deviceConfigSpecArray[0] = deviceConfigSpec;
    reConfigSpec.setDeviceChange(deviceConfigSpecArray);
    ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, reConfigSpec);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (!result.equals("sucess")) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - detachIso() done(failed)");
        throw new Exception("Failed to detachIso due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    _context.waitForTaskProgressDone(morTask);
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso() done(successfully)");
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualCdromRemotePassthroughBackingInfo(com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with VirtualCdromRemotePassthroughBackingInfo

use of com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo in project CloudStack-archive by CloudStack-extras.

the class VmwareHelper method prepareIsoDevice.

public static Pair<VirtualDevice, Boolean> prepareIsoDevice(VirtualMachineMO vmMo, String isoDatastorePath, ManagedObjectReference morDs, boolean connect, boolean connectAtBoot, int deviceNumber, int contextNumber) throws Exception {
    boolean newCdRom = false;
    VirtualCdrom cdRom = (VirtualCdrom) vmMo.getIsoDevice();
    if (cdRom == null) {
        newCdRom = true;
        cdRom = new VirtualCdrom();
        assert (vmMo.getIDEDeviceControllerKey() >= 0);
        cdRom.setControllerKey(vmMo.getIDEDeviceControllerKey());
        if (deviceNumber < 0)
            deviceNumber = vmMo.getNextIDEDeviceNumber();
        cdRom.setUnitNumber(deviceNumber);
        cdRom.setKey(-contextNumber);
    }
    VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo();
    cInfo.setConnected(connect);
    cInfo.setStartConnected(connectAtBoot);
    cdRom.setConnectable(cInfo);
    if (isoDatastorePath != null) {
        VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo();
        backingInfo.setFileName(isoDatastorePath);
        backingInfo.setDatastore(morDs);
        cdRom.setBacking(backingInfo);
    } else {
        VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
        backingInfo.setDeviceName("");
        cdRom.setBacking(backingInfo);
    }
    return new Pair<VirtualDevice, Boolean>(cdRom, newCdRom);
}
Also used : VirtualCdromIsoBackingInfo(com.vmware.vim25.VirtualCdromIsoBackingInfo) VirtualCdrom(com.vmware.vim25.VirtualCdrom) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualCdromRemotePassthroughBackingInfo(com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo) Pair(com.cloud.utils.Pair)

Example 3 with VirtualCdromRemotePassthroughBackingInfo

use of com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo in project cloudstack by apache.

the class VirtualMachineMO method detachIso.

public void detachIso(String isoDatastorePath) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.getValue() + ", isoDatastorePath: " + isoDatastorePath);
    VirtualDevice device = getIsoDevice();
    if (device == null) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - detachIso() done(failed)");
        throw new Exception("Unable to find a CDROM device");
    }
    VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
    backingInfo.setDeviceName("");
    device.setBacking(backingInfo);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    //VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(device);
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    //deviceConfigSpecArray[0] = deviceConfigSpec;
    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
    // Monitor VM questions
    final Boolean[] flags = { false };
    final VirtualMachineMO vmMo = this;
    Future<?> future = MonitorServiceExecutor.submit(new Runnable() {

        @Override
        public void run() {
            s_logger.info("VM Question monitor started...");
            while (!flags[0]) {
                try {
                    VirtualMachineRuntimeInfo runtimeInfo = vmMo.getRuntimeInfo();
                    VirtualMachineQuestionInfo question = runtimeInfo.getQuestion();
                    if (question != null) {
                        if (s_logger.isTraceEnabled()) {
                            s_logger.trace("Question id: " + question.getId());
                            s_logger.trace("Question text: " + question.getText());
                        }
                        if (question.getMessage() != null) {
                            for (VirtualMachineMessage msg : question.getMessage()) {
                                if (s_logger.isTraceEnabled()) {
                                    s_logger.trace("msg id: " + msg.getId());
                                    s_logger.trace("msg text: " + msg.getText());
                                }
                                if ("msg.cdromdisconnect.locked".equalsIgnoreCase(msg.getId())) {
                                    s_logger.info("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();
                            String msgId;
                            String msgText;
                            if (s_logger.isDebugEnabled()) {
                                s_logger.debug("question text : " + text);
                            }
                            String[] tokens = text.split(":");
                            msgId = tokens[0];
                            msgText = tokens[1];
                            if ("msg.cdromdisconnect.locked".equalsIgnoreCase(msgId)) {
                                s_logger.info("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");
                            }
                        }
                        ChoiceOption choice = question.getChoice();
                        if (choice != null) {
                            for (ElementDescription info : choice.getChoiceInfo()) {
                                if (s_logger.isTraceEnabled()) {
                                    s_logger.trace("Choice option key: " + info.getKey());
                                    s_logger.trace("Choice option label: " + info.getLabel());
                                }
                            }
                        }
                    }
                } catch (Throwable e) {
                    s_logger.error("Unexpected exception: ", e);
                }
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    s_logger.debug("[ignored] interupted while handling vm question about iso detach.");
                }
            }
            s_logger.info("VM Question monitor stopped");
        }
    });
    try {
        boolean result = _context.getVimClient().waitForTask(morTask);
        if (!result) {
            if (s_logger.isDebugEnabled())
                s_logger.trace("vCenter API trace - detachIso() done(failed)");
            throw new Exception("Failed to detachIso due to " + TaskMO.getTaskFailureInfo(_context, morTask));
        }
        _context.waitForTaskProgressDone(morTask);
        s_logger.trace("vCenter API trace - detachIso() done(successfully)");
    } finally {
        flags[0] = true;
        future.cancel(true);
    }
}
Also used : VirtualMachineQuestionInfo(com.vmware.vim25.VirtualMachineQuestionInfo) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualMachineRuntimeInfo(com.vmware.vim25.VirtualMachineRuntimeInfo) VirtualMachineMessage(com.vmware.vim25.VirtualMachineMessage) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualCdromRemotePassthroughBackingInfo(com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) ChoiceOption(com.vmware.vim25.ChoiceOption) ElementDescription(com.vmware.vim25.ElementDescription)

Example 4 with VirtualCdromRemotePassthroughBackingInfo

use of com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo in project cloudstack by apache.

the class VirtualMachineMO method detachIso.

public int detachIso(String isoDatastorePath, final boolean force) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.getValue() + ", isoDatastorePath: " + isoDatastorePath);
    VirtualDevice device = getIsoDevice(isoDatastorePath);
    if (device == null) {
        if (s_logger.isTraceEnabled())
            s_logger.trace("vCenter API trace - detachIso() done(failed)");
        throw new Exception("Unable to find a CDROM device");
    }
    VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
    backingInfo.setDeviceName("");
    device.setBacking(backingInfo);
    VirtualMachineConfigSpec reConfigSpec = new VirtualMachineConfigSpec();
    // VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(device);
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
    // deviceConfigSpecArray[0] = deviceConfigSpec;
    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
    // Monitor VM questions
    final Boolean[] flags = { false };
    final VirtualMachineMO vmMo = this;
    Future<?> future = answerVmwareQuestion(flags, vmMo, force);
    try {
        boolean result = _context.getVimClient().waitForTask(morTask);
        if (!result) {
            if (s_logger.isDebugEnabled())
                s_logger.trace("vCenter API trace - detachIso() done(failed)");
            throw new Exception("Failed to detachIso due to " + TaskMO.getTaskFailureInfo(_context, morTask));
        }
        _context.waitForTaskProgressDone(morTask);
        s_logger.trace("vCenter API trace - detachIso() done(successfully)");
    } finally {
        flags[0] = true;
        future.cancel(true);
    }
    return device.getKey();
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualCdromRemotePassthroughBackingInfo(com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with VirtualCdromRemotePassthroughBackingInfo

use of com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo in project cloudstack by apache.

the class VmwareHelper method prepareIsoDevice.

public static Pair<VirtualDevice, Boolean> prepareIsoDevice(VirtualMachineMO vmMo, String isoDatastorePath, ManagedObjectReference morDs, boolean connect, boolean connectAtBoot, int deviceNumber, int contextNumber) throws Exception {
    boolean newCdRom = false;
    VirtualCdrom cdRom = (VirtualCdrom) vmMo.getIsoDevice();
    if (cdRom == null) {
        newCdRom = true;
        cdRom = new VirtualCdrom();
        assert (vmMo.getIDEDeviceControllerKey() >= 0);
        cdRom.setControllerKey(vmMo.getIDEDeviceControllerKey());
        if (deviceNumber < 0)
            deviceNumber = vmMo.getNextIDEDeviceNumber();
        cdRom.setUnitNumber(deviceNumber);
        cdRom.setKey(-contextNumber);
    }
    VirtualDeviceConnectInfo cInfo = new VirtualDeviceConnectInfo();
    cInfo.setConnected(connect);
    cInfo.setStartConnected(connectAtBoot);
    cdRom.setConnectable(cInfo);
    if (isoDatastorePath != null) {
        VirtualCdromIsoBackingInfo backingInfo = new VirtualCdromIsoBackingInfo();
        backingInfo.setFileName(isoDatastorePath);
        backingInfo.setDatastore(morDs);
        cdRom.setBacking(backingInfo);
    } else {
        VirtualCdromRemotePassthroughBackingInfo backingInfo = new VirtualCdromRemotePassthroughBackingInfo();
        backingInfo.setDeviceName("");
        cdRom.setBacking(backingInfo);
    }
    return new Pair<VirtualDevice, Boolean>(cdRom, newCdRom);
}
Also used : VirtualCdromIsoBackingInfo(com.vmware.vim25.VirtualCdromIsoBackingInfo) VirtualCdrom(com.vmware.vim25.VirtualCdrom) VirtualDeviceConnectInfo(com.vmware.vim25.VirtualDeviceConnectInfo) VirtualCdromRemotePassthroughBackingInfo(com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo) Pair(com.cloud.utils.Pair)

Aggregations

VirtualCdromRemotePassthroughBackingInfo (com.vmware.vim25.VirtualCdromRemotePassthroughBackingInfo)5 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)3 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)3 VirtualDevice (com.vmware.vim25.VirtualDevice)3 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)3 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)3 Pair (com.cloud.utils.Pair)2 VirtualCdrom (com.vmware.vim25.VirtualCdrom)2 VirtualCdromIsoBackingInfo (com.vmware.vim25.VirtualCdromIsoBackingInfo)2 VirtualDeviceConnectInfo (com.vmware.vim25.VirtualDeviceConnectInfo)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 ChoiceOption (com.vmware.vim25.ChoiceOption)1 ElementDescription (com.vmware.vim25.ElementDescription)1 VirtualMachineMessage (com.vmware.vim25.VirtualMachineMessage)1 VirtualMachineQuestionInfo (com.vmware.vim25.VirtualMachineQuestionInfo)1 VirtualMachineRuntimeInfo (com.vmware.vim25.VirtualMachineRuntimeInfo)1