Search in sources :

Example 1 with VirtualDevice

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

the class VirtualMachineMO method copyAllVmDiskFiles.

public void copyAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean followDiskChain) throws Exception {
    VirtualDevice[] disks = getAllDiskDevice();
    DatacenterMO dcMo = getOwnerDatacenter().first();
    if (disks != null) {
        for (VirtualDevice disk : disks) {
            List<Pair<String, ManagedObjectReference>> vmdkFiles = this.getDiskDatastorePathChain((VirtualDisk) disk, followDiskChain);
            for (Pair<String, ManagedObjectReference> fileItem : vmdkFiles) {
                DatastoreMO srcDsMo = new DatastoreMO(_context, fileItem.second());
                DatastoreFile srcFile = new DatastoreFile(fileItem.first());
                DatastoreFile destFile = new DatastoreFile(destDsMo.getName(), destDsDir, srcFile.getFileName());
                Pair<VmdkFileDescriptor, byte[]> vmdkDescriptor = null;
                vmdkDescriptor = getVmdkFileInfo(fileItem.first());
                s_logger.info("Copy VM disk file " + srcFile.getPath() + " to " + destFile.getPath());
                srcDsMo.copyDatastoreFile(fileItem.first(), dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
                if (vmdkDescriptor != null) {
                    String vmdkBaseFileName = vmdkDescriptor.first().getBaseFileName();
                    String baseFilePath = srcFile.getCompanionPath(vmdkBaseFileName);
                    destFile = new DatastoreFile(destDsMo.getName(), destDsDir, vmdkBaseFileName);
                    s_logger.info("Copy VM disk file " + baseFilePath + " to " + destFile.getPath());
                    srcDsMo.copyDatastoreFile(baseFilePath, dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
                }
            }
        }
    }
}
Also used : VirtualDevice(com.vmware.vim25.VirtualDevice) Pair(com.cloud.utils.Pair) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 2 with VirtualDevice

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

the class VirtualMachineMO method moveAllVmDiskFiles.

// this method relies on un-offical VMware API
@Deprecated
public void moveAllVmDiskFiles(DatastoreMO destDsMo, String destDsDir, boolean followDiskChain) throws Exception {
    VirtualDevice[] disks = getAllDiskDevice();
    DatacenterMO dcMo = getOwnerDatacenter().first();
    if (disks != null) {
        for (VirtualDevice disk : disks) {
            List<Pair<String, ManagedObjectReference>> vmdkFiles = this.getDiskDatastorePathChain((VirtualDisk) disk, followDiskChain);
            for (Pair<String, ManagedObjectReference> fileItem : vmdkFiles) {
                DatastoreMO srcDsMo = new DatastoreMO(_context, fileItem.second());
                DatastoreFile srcFile = new DatastoreFile(fileItem.first());
                DatastoreFile destFile = new DatastoreFile(destDsMo.getName(), destDsDir, srcFile.getFileName());
                Pair<VmdkFileDescriptor, byte[]> vmdkDescriptor = null;
                vmdkDescriptor = getVmdkFileInfo(fileItem.first());
                s_logger.info("Move VM disk file " + srcFile.getPath() + " to " + destFile.getPath());
                srcDsMo.moveDatastoreFile(fileItem.first(), dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
                if (vmdkDescriptor != null) {
                    String vmdkBaseFileName = vmdkDescriptor.first().getBaseFileName();
                    String baseFilePath = srcFile.getCompanionPath(vmdkBaseFileName);
                    destFile = new DatastoreFile(destDsMo.getName(), destDsDir, vmdkBaseFileName);
                    s_logger.info("Move VM disk file " + baseFilePath + " to " + destFile.getPath());
                    srcDsMo.moveDatastoreFile(baseFilePath, dcMo.getMor(), destDsMo.getMor(), destFile.getPath(), dcMo.getMor(), true);
                }
            }
        }
    }
}
Also used : VirtualDevice(com.vmware.vim25.VirtualDevice) Pair(com.cloud.utils.Pair) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 3 with VirtualDevice

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

the class VirtualMachineMO method getNicDevices.

public VirtualDevice[] getNicDevices() throws Exception {
    VirtualDevice[] devices = (VirtualDevice[]) _context.getServiceUtil().getDynamicProperty(_mor, "config.hardware.device");
    List<VirtualDevice> nics = new ArrayList<VirtualDevice>();
    if (devices != null) {
        for (VirtualDevice device : devices) {
            if (device instanceof VirtualEthernetCard) {
                nics.add(device);
            }
        }
    }
    return nics.toArray(new VirtualDevice[0]);
}
Also used : VirtualDevice(com.vmware.vim25.VirtualDevice) ArrayList(java.util.ArrayList) VirtualEthernetCard(com.vmware.vim25.VirtualEthernetCard)

Example 4 with VirtualDevice

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

the class VirtualMachineMO method tearDownDevice.

public void tearDownDevice(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.remove);
    vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
    if (!configureVm(vmConfigSpec)) {
        throw new Exception("Failed to detach devices");
    }
}
Also used : VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec)

Example 5 with VirtualDevice

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

the class VirtualMachineMO method configureVm.

public boolean configureVm(Ternary<VirtualDevice, VirtualDeviceConfigSpecOperation, VirtualDeviceConfigSpecFileOperation>[] devices) throws Exception {
    assert (devices != null);
    VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec();
    VirtualDeviceConfigSpec[] deviceConfigSpecArray = new VirtualDeviceConfigSpec[devices.length];
    int i = 0;
    for (Ternary<VirtualDevice, VirtualDeviceConfigSpecOperation, VirtualDeviceConfigSpecFileOperation> deviceTernary : devices) {
        VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
        deviceConfigSpec.setDevice(deviceTernary.first());
        deviceConfigSpec.setOperation(deviceTernary.second());
        deviceConfigSpec.setFileOperation(deviceTernary.third());
        deviceConfigSpecArray[i++] = deviceConfigSpec;
    }
    configSpec.setDeviceChange(deviceConfigSpecArray);
    ManagedObjectReference morTask = _context.getService().reconfigVM_Task(_mor, configSpec);
    String result = _context.getServiceUtil().waitForTask(morTask);
    if (result.equals("sucess")) {
        _context.waitForTaskProgressDone(morTask);
        return true;
    } else {
        s_logger.error("VMware reconfigVM_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
    }
    return false;
}
Also used : VirtualDeviceConfigSpecFileOperation(com.vmware.vim25.VirtualDeviceConfigSpecFileOperation) VirtualMachineConfigSpec(com.vmware.vim25.VirtualMachineConfigSpec) VirtualDeviceConfigSpec(com.vmware.vim25.VirtualDeviceConfigSpec) VirtualDeviceConfigSpecOperation(com.vmware.vim25.VirtualDeviceConfigSpecOperation) VirtualDevice(com.vmware.vim25.VirtualDevice) ArrayOfManagedObjectReference(com.vmware.vim25.ArrayOfManagedObjectReference) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

VirtualDevice (com.vmware.vim25.VirtualDevice)49 VirtualDeviceConfigSpec (com.vmware.vim25.VirtualDeviceConfigSpec)23 VirtualMachineConfigSpec (com.vmware.vim25.VirtualMachineConfigSpec)23 VirtualDisk (com.vmware.vim25.VirtualDisk)22 ArrayList (java.util.ArrayList)20 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)19 Pair (com.cloud.utils.Pair)15 ArrayOfManagedObjectReference (com.vmware.vim25.ArrayOfManagedObjectReference)15 VirtualDeviceConnectInfo (com.vmware.vim25.VirtualDeviceConnectInfo)15 VirtualDiskFlatVer2BackingInfo (com.vmware.vim25.VirtualDiskFlatVer2BackingInfo)15 VirtualEthernetCard (com.vmware.vim25.VirtualEthernetCard)11 VirtualDeviceBackingInfo (com.vmware.vim25.VirtualDeviceBackingInfo)8 IOException (java.io.IOException)8 CloudException (com.cloud.exception.CloudException)6 InternalErrorException (com.cloud.exception.InternalErrorException)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 ConnectException (java.net.ConnectException)6 RemoteException (java.rmi.RemoteException)6 ConfigurationException (javax.naming.ConfigurationException)6