Search in sources :

Example 6 with DatastoreSummary

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

the class HostMO method getLocalDatastoreOnHost.

public List<Pair<ManagedObjectReference, String>> getLocalDatastoreOnHost() throws Exception {
    List<Pair<ManagedObjectReference, String>> dsList = new ArrayList<Pair<ManagedObjectReference, String>>();
    ObjectContent[] ocs = getDatastorePropertiesOnHyperHost(new String[] { "name", "summary" });
    if (ocs != null) {
        for (ObjectContent oc : ocs) {
            DatastoreSummary dsSummary = (DatastoreSummary) VmwareHelper.getPropValue(oc, "summary");
            if (dsSummary.isMultipleHostAccess() == false && dsSummary.isAccessible() && dsSummary.getType().equalsIgnoreCase("vmfs")) {
                ManagedObjectReference morDs = oc.getObj();
                String name = (String) VmwareHelper.getPropValue(oc, "name");
                if (!name.startsWith("-iqn.") && !name.startsWith("_iqn.")) {
                    dsList.add(new Pair<ManagedObjectReference, String>(morDs, name));
                }
            }
        }
    }
    return dsList;
}
Also used : ObjectContent(com.vmware.vim25.ObjectContent) DatastoreSummary(com.vmware.vim25.DatastoreSummary) ArrayList(java.util.ArrayList) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference) Pair(com.cloud.utils.Pair)

Example 7 with DatastoreSummary

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

the class VmwareResource method execute.

protected Answer execute(GetStorageStatsCommand cmd) {
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Executing resource GetStorageStatsCommand: " + _gson.toJson(cmd));
    }
    try {
        VmwareContext context = getServiceContext();
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, cmd.getStorageId());
        if (morDs != null) {
            DatastoreMO datastoreMo = new DatastoreMO(context, morDs);
            DatastoreSummary summary = datastoreMo.getSummary();
            assert (summary != null);
            long capacity = summary.getCapacity();
            long free = summary.getFreeSpace();
            long used = capacity - free;
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Datastore summary info, storageId: " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ", capacity: " + capacity + ", free: " + free + ", used: " + used);
            }
            if (summary.getCapacity() <= 0) {
                s_logger.warn("Something is wrong with vSphere NFS datastore, rebooting ESX(ESXi) host should help");
            }
            return new GetStorageStatsAnswer(cmd, capacity, used);
        } else {
            String msg = "Could not find datastore for GetStorageStatsCommand storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype();
            s_logger.error(msg);
            return new GetStorageStatsAnswer(cmd, msg);
        }
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = "Unable to execute GetStorageStatsCommand(storageId : " + cmd.getStorageId() + ", localPath: " + cmd.getLocalPath() + ", poolType: " + cmd.getPooltype() + ") due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        return new GetStorageStatsAnswer(cmd, msg);
    }
}
Also used : VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) DatastoreSummary(com.vmware.vim25.DatastoreSummary) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) RemoteException(java.rmi.RemoteException) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Aggregations

DatastoreSummary (com.vmware.vim25.DatastoreSummary)7 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)7 ArrayList (java.util.ArrayList)5 DatastoreMO (com.cloud.hypervisor.vmware.mo.DatastoreMO)3 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)3 Pair (com.cloud.utils.Pair)3 RemoteException (java.rmi.RemoteException)3 GetStorageStatsAnswer (com.cloud.agent.api.GetStorageStatsAnswer)2 CloudException (com.cloud.exception.CloudException)2 InternalErrorException (com.cloud.exception.InternalErrorException)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ObjectContent (com.vmware.vim25.ObjectContent)2 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ConnectException (java.net.ConnectException)2 ConfigurationException (javax.naming.ConfigurationException)2 Answer (com.cloud.agent.api.Answer)1 BackupSnapshotAnswer (com.cloud.agent.api.BackupSnapshotAnswer)1 CheckHealthAnswer (com.cloud.agent.api.CheckHealthAnswer)1 CheckNetworkAnswer (com.cloud.agent.api.CheckNetworkAnswer)1