Search in sources :

Example 16 with VmConfigSpec

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

the class VirtualMachineMO method cloneFromDiskChain.

public void cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs) throws Exception {
    assert (disks != null);
    assert (disks.length >= 1);
    HostMO hostMo = getRunningHost();
    VirtualMachineConfigInfo vmConfigInfo = getConfigInfo();
    if (!hostMo.createBlankVm(clonedVmName, 1, cpuSpeedMHz, 0, false, memoryMb, 0, vmConfigInfo.getGuestId(), morDs, false))
        throw new Exception("Unable to create a blank VM");
    VirtualMachineMO clonedVmMo = hostMo.findVmOnHyperHost(clonedVmName);
    if (clonedVmMo == null)
        throw new Exception("Unable to find just-created blank VM");
    boolean bSuccess = false;
    try {
        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
        deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
        VirtualDevice device = VmwareHelper.prepareDiskDevice(clonedVmMo, -1, disks, morDs, -1, 1);
        deviceConfigSpecArray[0].setDevice(device);
        deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.add);
        vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
        clonedVmMo.configureVm(vmConfigSpec);
        bSuccess = true;
    } finally {
        if (!bSuccess) {
            clonedVmMo.detachAllDisks();
            clonedVmMo.destroy();
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualMachineConfigInfo(com.vmware.vim25.VirtualMachineConfigInfo)

Example 17 with VmConfigSpec

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

the class VirtualMachineMO method plugDevice.

public void plugDevice(VirtualDevice device) throws Exception {
    VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[1];
    deviceConfigSpecArray[0] = new VirtualDeviceConfigSpec();
    deviceConfigSpecArray[0].setDevice(device);
    deviceConfigSpecArray[0].setOperation(VirtualDeviceConfigSpecOperation.add);
    vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
    if (!configureVm(vmConfigSpec)) {
        throw new Exception("Failed to add devices");
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec)

Example 18 with VmConfigSpec

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

the class VirtualMachineMO method cloneFromDiskChain.

public VirtualMachineMO cloneFromDiskChain(String clonedVmName, int cpuSpeedMHz, int memoryMb, String[] disks, ManagedObjectReference morDs) throws Exception {
    assert (disks != null);
    assert (disks.length >= 1);
    HostMO hostMo = getRunningHost();
    VirtualMachineMO clonedVmMo = HypervisorHostHelper.createWorkerVM(hostMo, new DatastoreMO(hostMo.getContext(), morDs), clonedVmName);
    if (clonedVmMo == null)
        throw new Exception("Unable to find just-created blank VM");
    boolean bSuccess = false;
    try {
        VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
        VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
        VirtualDevice device = VmwareHelper.prepareDiskDevice(clonedVmMo, null, -1, disks, morDs, -1, 1);
        deviceConfigSpec.setDevice(device);
        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
        vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
        clonedVmMo.configureVm(vmConfigSpec);
        bSuccess = true;
        return clonedVmMo;
    } finally {
        if (!bSuccess) {
            clonedVmMo.detachAllDisks();
            clonedVmMo.destroy();
        }
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDevice(com.vmware.vim25.VirtualDevice)

Example 19 with VmConfigSpec

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

the class VirtualMachineMO method tearDownDevice.

public void tearDownDevice(VirtualDevice device) throws Exception {
    VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(device);
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
    vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
    if (!configureVm(vmConfigSpec)) {
        throw new Exception("Failed to detach devices");
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec)

Example 20 with VmConfigSpec

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

the class VirtualMachineMO method plugDevice.

public void plugDevice(VirtualDevice device) throws Exception {
    VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
    deviceConfigSpec.setDevice(device);
    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
    vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
    if (!configureVm(vmConfigSpec)) {
        throw new Exception("Failed to add devices");
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec)

Aggregations

VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)19 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)17 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)11 VirtualDevice (com.vmware.vim25.VirtualDevice)10 IOException (java.io.IOException)8 CloudException (com.cloud.exception.CloudException)7 InternalErrorException (com.cloud.exception.InternalErrorException)7 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ConnectException (java.net.ConnectException)7 RemoteException (java.rmi.RemoteException)7 ConfigurationException (javax.naming.ConfigurationException)7 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)5 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)5 VmwareContext (com.cloud.hypervisor.vmware.util.VmwareContext)5 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)5 OptionValue (com.vmware.vim25.OptionValue)4 VirtualDisk (com.vmware.vim25.VirtualDisk)4 DatacenterMO (com.cloud.hypervisor.vmware.mo.DatacenterMO)3 HostMO (com.cloud.hypervisor.vmware.mo.HostMO)3