Search in sources :

Example 1 with DatastoreInfo

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

the class ClusterMO method findDatastoreByExportPath.

@Override
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.get_value() + ", exportPath: " + exportPath);
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "info" });
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            DatastoreInfo dsInfo = (DatastoreInfo) oc.getPropSet(0).getVal();
            if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) {
                NasDatastoreInfo info = (NasDatastoreInfo) dsInfo;
                if (info != null) {
                    String vmwareUrl = info.getUrl();
                    if (vmwareUrl.charAt(vmwareUrl.length() - 1) == '/')
                        vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1);
                    URI uri = new URI(vmwareUrl);
                    if (uri.getPath().equals("/" + exportPath)) {
                        if (s_logger.isTraceEnabled())
                            s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)");
                        return oc.getObj();
                    }
                }
            }
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)");
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) DatastoreInfo(com.vmware.vim25.DatastoreInfo) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI)

Example 2 with DatastoreInfo

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

the class ClusterMO method findDatastoreByExportPath.

@Override
public ManagedObjectReference findDatastoreByExportPath(String exportPath) throws Exception {
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath(). target MOR: " + _mor.getValue() + ", exportPath: " + exportPath);
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "info" });
    if (ocs != null && ocs.length > 0) {
        for (ObjectContent oc : ocs) {
            DatastoreInfo dsInfo = (DatastoreInfo) oc.getPropSet().get(0).getVal();
            if (dsInfo != null && dsInfo instanceof NasDatastoreInfo) {
                NasDatastoreInfo info = (NasDatastoreInfo) dsInfo;
                if (info != null) {
                    String vmwareUrl = info.getUrl();
                    if (vmwareUrl.charAt(vmwareUrl.length() - 1) == '/')
                        vmwareUrl = vmwareUrl.substring(0, vmwareUrl.length() - 1);
                    URI uri = new URI(vmwareUrl);
                    if (uri.getPath().equals("/" + exportPath)) {
                        if (s_logger.isTraceEnabled())
                            s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(successfully)");
                        return oc.getObj();
                    }
                }
            }
        }
    }
    if (s_logger.isTraceEnabled())
        s_logger.trace("vCenter API trace - findDatastoreByExportPath() done(failed)");
    return null;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) DatastoreInfo(com.vmware.vim25.DatastoreInfo) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) URI(java.net.URI)

Example 3 with DatastoreInfo

use of com.vmware.vim25.DatastoreInfo in project coprhd-controller by CoprHD.

the class TestVcenter method main.

public static void main(String[] args) throws MalformedURLException, InvalidProperty, RuntimeFault, RemoteException {
    VCenterAPI vcenterAPI = getVcenterApi("lglw1045.lss.emc.com", "root", "vmware");
    try {
        Datastore ds = vcenterAPI.findDatastore("DC-Simulator-1", "ds-1");
        DatastoreInfo dsInfo = ds.getInfo();
        if (dsInfo != null) {
            return;
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) DatastoreInfo(com.vmware.vim25.DatastoreInfo) Datastore(com.vmware.vim25.mo.Datastore) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException)

Example 4 with DatastoreInfo

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

the class VmwareResource method getUnmanageInstanceDisks.

private List<UnmanagedInstanceTO.Disk> getUnmanageInstanceDisks(VirtualMachineMO vmMo) {
    List<UnmanagedInstanceTO.Disk> instanceDisks = new ArrayList<>();
    VirtualDisk[] disks = null;
    try {
        disks = vmMo.getAllDiskDevice();
    } catch (Exception e) {
        s_logger.info("Unable to retrieve unmanaged instance disks. " + e.getMessage());
    }
    if (disks != null) {
        for (VirtualDevice diskDevice : disks) {
            try {
                if (diskDevice instanceof VirtualDisk) {
                    UnmanagedInstanceTO.Disk instanceDisk = new UnmanagedInstanceTO.Disk();
                    VirtualDisk disk = (VirtualDisk) diskDevice;
                    instanceDisk.setDiskId(disk.getDiskObjectId());
                    instanceDisk.setLabel(disk.getDeviceInfo() != null ? disk.getDeviceInfo().getLabel() : "");
                    instanceDisk.setFileBaseName(vmMo.getVmdkFileBaseName(disk));
                    instanceDisk.setImagePath(getAbsoluteVmdkFile(disk));
                    instanceDisk.setCapacity(disk.getCapacityInBytes());
                    instanceDisk.setPosition(diskDevice.getUnitNumber());
                    DatastoreFile file = new DatastoreFile(getAbsoluteVmdkFile(disk));
                    if (StringUtils.isNoneEmpty(file.getFileBaseName(), file.getDatastoreName())) {
                        VirtualMachineDiskInfo diskInfo = vmMo.getDiskInfoBuilder().getDiskInfoByBackingFileBaseName(file.getFileBaseName(), file.getDatastoreName());
                        instanceDisk.setChainInfo(getGson().toJson(diskInfo));
                    }
                    for (VirtualDevice device : vmMo.getAllDeviceList()) {
                        if (diskDevice.getControllerKey() == device.getKey()) {
                            if (device instanceof VirtualIDEController) {
                                instanceDisk.setController(DiskControllerType.getType(device.getClass().getSimpleName()).toString());
                                instanceDisk.setControllerUnit(((VirtualIDEController) device).getBusNumber());
                            } else if (device instanceof VirtualSCSIController) {
                                instanceDisk.setController(DiskControllerType.getType(device.getClass().getSimpleName()).toString());
                                instanceDisk.setControllerUnit(((VirtualSCSIController) device).getBusNumber());
                            } else {
                                instanceDisk.setController(DiskControllerType.none.toString());
                            }
                            break;
                        }
                    }
                    if (disk.getBacking() instanceof VirtualDeviceFileBackingInfo) {
                        VirtualDeviceFileBackingInfo diskBacking = (VirtualDeviceFileBackingInfo) disk.getBacking();
                        ManagedObjectReference morDs = diskBacking.getDatastore();
                        DatastoreInfo info = (DatastoreInfo) vmMo.getContext().getVimClient().getDynamicProperty(diskBacking.getDatastore(), "info");
                        if (info instanceof NasDatastoreInfo) {
                            NasDatastoreInfo dsInfo = (NasDatastoreInfo) info;
                            instanceDisk.setDatastoreName(dsInfo.getName());
                            if (dsInfo.getNas() != null) {
                                instanceDisk.setDatastoreHost(dsInfo.getNas().getRemoteHost());
                                instanceDisk.setDatastorePath(dsInfo.getNas().getRemotePath());
                                instanceDisk.setDatastoreType(dsInfo.getNas().getType());
                            }
                        } else {
                            instanceDisk.setDatastoreName(info.getName());
                        }
                    }
                    s_logger.info(vmMo.getName() + " " + disk.getDeviceInfo().getLabel() + " " + disk.getDeviceInfo().getSummary() + " " + disk.getDiskObjectId() + " " + disk.getCapacityInKB() + " " + instanceDisk.getController());
                    instanceDisks.add(instanceDisk);
                }
            } catch (Exception e) {
                s_logger.info("Unable to retrieve unmanaged instance disk info. " + e.getMessage());
            }
        }
        Collections.sort(instanceDisks, new Comparator<UnmanagedInstanceTO.Disk>() {

            @Override
            public int compare(final UnmanagedInstanceTO.Disk disk1, final UnmanagedInstanceTO.Disk disk2) {
                return extractInt(disk1) - extractInt(disk2);
            }

            int extractInt(UnmanagedInstanceTO.Disk disk) {
                String num = disk.getLabel().replaceAll("\\D", "");
                // return 0 if no digits found
                return num.isEmpty() ? 0 : Integer.parseInt(num);
            }
        });
    }
    return instanceDisks;
}
Also used : NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) DatastoreInfo(com.vmware.vim25.DatastoreInfo) VirtualSCSIController(com.vmware.vim25.VirtualSCSIController) VirtualDeviceFileBackingInfo(com.vmware.vim25.VirtualDeviceFileBackingInfo) ArrayList(java.util.ArrayList) VirtualDevice(com.vmware.vim25.VirtualDevice) VirtualDisk(com.vmware.vim25.VirtualDisk) ConnectException(java.net.ConnectException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) InternalErrorException(com.cloud.exception.InternalErrorException) CloudException(com.cloud.exception.CloudException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ConfigurationException(javax.naming.ConfigurationException) UnmanagedInstanceTO(org.apache.cloudstack.vm.UnmanagedInstanceTO) VirtualIDEController(com.vmware.vim25.VirtualIDEController) DatastoreFile(com.cloud.hypervisor.vmware.mo.DatastoreFile) VirtualMachineDiskInfo(org.apache.cloudstack.utils.volume.VirtualMachineDiskInfo) NasDatastoreInfo(com.vmware.vim25.NasDatastoreInfo) VirtualDisk(com.vmware.vim25.VirtualDisk) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

DatastoreInfo (com.vmware.vim25.DatastoreInfo)4 NasDatastoreInfo (com.vmware.vim25.NasDatastoreInfo)3 ObjectContent (com.vmware.vim25.ObjectContent)2 URI (java.net.URI)2 RemoteException (java.rmi.RemoteException)2 CloudException (com.cloud.exception.CloudException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1 DatastoreFile (com.cloud.hypervisor.vmware.mo.DatastoreFile)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1 VCenterAPI (com.iwave.ext.vmware.VCenterAPI)1 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)1 VirtualDevice (com.vmware.vim25.VirtualDevice)1 VirtualDeviceFileBackingInfo (com.vmware.vim25.VirtualDeviceFileBackingInfo)1 VirtualDisk (com.vmware.vim25.VirtualDisk)1 VirtualIDEController (com.vmware.vim25.VirtualIDEController)1 VirtualSCSIController (com.vmware.vim25.VirtualSCSIController)1 Datastore (com.vmware.vim25.mo.Datastore)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ConnectException (java.net.ConnectException)1