Search in sources :

Example 1 with DatastoreSummary

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

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.getMultipleHostAccess() == false && dsSummary.isAccessible() && dsSummary.getType().equalsIgnoreCase("vmfs")) {
                ManagedObjectReference morDs = oc.getObj();
                String name = (String) VmwareHelper.getPropValue(oc, "name");
                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 2 with DatastoreSummary

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

the class HostMO method getHostLocalDatastore.

public ManagedObjectReference[] getHostLocalDatastore() throws Exception {
    ServiceUtil serviceUtil = _context.getServiceUtil();
    ManagedObjectReference[] datastores = (ManagedObjectReference[]) serviceUtil.getDynamicProperty(_mor, "datastore");
    List<ManagedObjectReference> l = new ArrayList<ManagedObjectReference>();
    if (datastores != null) {
        for (ManagedObjectReference mor : datastores) {
            DatastoreSummary summary = (DatastoreSummary) serviceUtil.getDynamicProperty(mor, "summary");
            if (summary.getType().equalsIgnoreCase("VMFS") && !summary.getMultipleHostAccess())
                l.add(mor);
        }
    }
    return l.toArray(new ManagedObjectReference[1]);
}
Also used : DatastoreSummary(com.vmware.vim25.DatastoreSummary) ArrayList(java.util.ArrayList) ServiceUtil(com.vmware.apputils.vim25.ServiceUtil) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 3 with DatastoreSummary

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

the class VmwareResource method execute.

protected Answer execute(ModifyStoragePoolCommand cmd) {
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Executing resource ModifyStoragePoolCommand: " + _gson.toJson(cmd));
    }
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(getServiceContext());
        StorageFilerTO pool = cmd.getPool();
        if (pool.getType() != StoragePoolType.NetworkFilesystem && pool.getType() != StoragePoolType.VMFS) {
            throw new Exception("Unsupported storage pool type " + pool.getType());
        }
        ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, pool.getUuid());
        if (morDatastore == null) {
            morDatastore = hyperHost.mountDatastore(pool.getType() == StoragePoolType.VMFS, pool.getHost(), pool.getPort(), pool.getPath(), pool.getUuid().replace("-", ""));
        }
        assert (morDatastore != null);
        DatastoreSummary summary = new DatastoreMO(getServiceContext(), morDatastore).getSummary();
        long capacity = summary.getCapacity();
        long available = summary.getFreeSpace();
        Map<String, TemplateProp> tInfo = new HashMap<String, TemplateProp>();
        ModifyStoragePoolAnswer answer = new ModifyStoragePoolAnswer(cmd, capacity, available, tInfo);
        if (cmd.getAdd() && pool.getType() == StoragePoolType.VMFS) {
            answer.setLocalDatastoreName(morDatastore.getValue());
        }
        return answer;
    } catch (Throwable e) {
        if (e instanceof RemoteException) {
            s_logger.warn("Encounter remote exception to vCenter, invalidate VMware session context");
            invalidateServiceContext();
        }
        String msg = "ModifyStoragePoolCommand failed due to " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg, e);
        return new Answer(cmd, false, msg);
    }
}
Also used : TemplateProp(com.cloud.storage.template.TemplateProp) HashMap(java.util.HashMap) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) 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) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) ModifyTargetsAnswer(com.cloud.agent.api.ModifyTargetsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) ManageSnapshotAnswer(com.cloud.agent.api.ManageSnapshotAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) MigrateVolumeAnswer(com.cloud.agent.api.storage.MigrateVolumeAnswer) SetupAnswer(com.cloud.agent.api.SetupAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) CheckOnHostAnswer(com.cloud.agent.api.CheckOnHostAnswer) CheckHealthAnswer(com.cloud.agent.api.CheckHealthAnswer) RevertToVMSnapshotAnswer(com.cloud.agent.api.RevertToVMSnapshotAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) DeleteVMSnapshotAnswer(com.cloud.agent.api.DeleteVMSnapshotAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CreateVolumeFromSnapshotAnswer(com.cloud.agent.api.CreateVolumeFromSnapshotAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) ResizeVolumeAnswer(com.cloud.agent.api.storage.ResizeVolumeAnswer) BackupSnapshotAnswer(com.cloud.agent.api.BackupSnapshotAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) ValidateSnapshotAnswer(com.cloud.agent.api.ValidateSnapshotAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) DatastoreSummary(com.vmware.vim25.DatastoreSummary) RemoteException(java.rmi.RemoteException) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 4 with DatastoreSummary

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

the class VmwareResource method initializeLocalStorage.

private List<StartupStorageCommand> initializeLocalStorage() {
    List<StartupStorageCommand> storageCmds = new ArrayList<StartupStorageCommand>();
    VmwareContext context = getServiceContext();
    try {
        VmwareHypervisorHost hyperHost = getHyperHost(context);
        if (hyperHost instanceof HostMO) {
            HostMO hostMo = (HostMO) hyperHost;
            List<Pair<ManagedObjectReference, String>> dsList = hostMo.getLocalDatastoreOnHost();
            for (Pair<ManagedObjectReference, String> dsPair : dsList) {
                DatastoreMO dsMo = new DatastoreMO(context, dsPair.first());
                String poolUuid = dsMo.getCustomFieldValue(CustomFieldConstants.CLOUD_UUID);
                if (poolUuid == null || poolUuid.isEmpty()) {
                    poolUuid = UUID.randomUUID().toString();
                    dsMo.setCustomFieldValue(CustomFieldConstants.CLOUD_UUID, poolUuid);
                }
                DatastoreSummary dsSummary = dsMo.getSummary();
                String address = hostMo.getHostName();
                StoragePoolInfo pInfo = new StoragePoolInfo(poolUuid, address, dsMo.getMor().getValue(), "", StoragePoolType.VMFS, dsSummary.getCapacity(), dsSummary.getFreeSpace());
                StartupStorageCommand cmd = new StartupStorageCommand();
                cmd.setName(poolUuid);
                cmd.setPoolInfo(pInfo);
                // give storage host the same UUID as the local storage pool itself
                cmd.setGuid(poolUuid);
                cmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
                cmd.setDataCenter(_dcId);
                cmd.setPod(_pod);
                cmd.setCluster(_cluster);
                s_logger.info("Add local storage startup command: " + _gson.toJson(cmd));
                storageCmds.add(cmd);
            }
        } else {
            s_logger.info("Cluster host does not support local storage, skip it");
        }
    } catch (Exception e) {
        String msg = "initializing local storage failed due to : " + VmwareHelper.getExceptionMessage(e);
        s_logger.error(msg);
        invalidateServiceContext();
        throw new CloudRuntimeException(msg);
    }
    return storageCmds;
}
Also used : HostMO(com.cloud.hypervisor.vmware.mo.HostMO) StartupStorageCommand(com.cloud.agent.api.StartupStorageCommand) ArrayList(java.util.ArrayList) VmwareHypervisorHost(com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost) DatastoreMO(com.cloud.hypervisor.vmware.mo.DatastoreMO) 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) VmwareContext(com.cloud.hypervisor.vmware.util.VmwareContext) DatastoreSummary(com.vmware.vim25.DatastoreSummary) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) StoragePoolInfo(com.cloud.agent.api.StoragePoolInfo) Pair(com.cloud.utils.Pair) ManagedObjectReference(com.vmware.vim25.ManagedObjectReference)

Example 5 with DatastoreSummary

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

the class HostMO method getHostLocalDatastore.

public ManagedObjectReference[] getHostLocalDatastore() throws Exception {
    List<ManagedObjectReference> datastores = _context.getVimClient().getDynamicProperty(_mor, "datastore");
    List<ManagedObjectReference> l = new ArrayList<ManagedObjectReference>();
    if (datastores != null) {
        for (ManagedObjectReference mor : datastores) {
            DatastoreSummary summary = (DatastoreSummary) _context.getVimClient().getDynamicProperty(mor, "summary");
            if (summary.getType().equalsIgnoreCase("VMFS") && !summary.isMultipleHostAccess())
                l.add(mor);
        }
    }
    return l.toArray(new ManagedObjectReference[1]);
}
Also used : DatastoreSummary(com.vmware.vim25.DatastoreSummary) ArrayList(java.util.ArrayList) 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