Search in sources :

Example 31 with ClusterComputeResource

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

the class VMwareSupport method expandVmfsDatastore.

/**
 * Expand a VMFS datastore.
 *
 * @param host
 *            the host to which the volume is assigned.
 * @param cluster
 *            the cluster to which the volume is associated (may be null if the storage is exclusive to the host)
 * @param volume
 *            the volume that was expanded.
 * @param datastore
 *            the datastore to expand.
 */
public void expandVmfsDatastore(HostSystem host, ClusterComputeResource cluster, URI hostOrClusterId, BlockObjectRestRep volume, Datastore datastore) {
    HostScsiDisk disk = findScsiDisk(host, cluster, volume);
    execute(new ExpandVmfsDatastore(host, disk, datastore));
    addAffectedResource(volume);
    addVmfsDatastoreTag(volume, hostOrClusterId, datastore.getName());
    ExecutionUtils.clearRollback();
}
Also used : HostScsiDisk(com.vmware.vim25.HostScsiDisk) ExpandVmfsDatastore(com.emc.sa.service.vmware.block.tasks.ExpandVmfsDatastore)

Example 32 with ClusterComputeResource

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

the class VMwareSupport method createNfsDatastore.

/**
 * Creates an NFS datastore for the hosts in the cluster
 *
 * @param cluster
 *            the cluster.
 * @param fileSystem
 *            the file system.
 * @param export
 *            the export.
 * @param datacenterId
 *            the datacenter ID.
 * @param datastoreName
 *            the name of the datastore to create.
 * @return datastores
 */
public List<Datastore> createNfsDatastore(ClusterComputeResource cluster, FileShareRestRep fileSystem, FileSystemExportParam export, URI datacenterId, String datastoreName) {
    addNfsDatastoreTag(fileSystem, export, datacenterId, datastoreName);
    List<Datastore> datastores = Lists.newArrayList();
    String fileServer = StringUtils.substringBefore(export.getMountPoint(), ":");
    String mountPath = StringUtils.substringAfter(export.getMountPoint(), ":");
    for (HostSystem host : cluster.getHosts()) {
        datastores.add(execute(new CreateNfsDatastore(host, fileServer, mountPath, datastoreName)));
        addAffectedResource(fileSystem);
        ExecutionUtils.clearRollback();
    }
    return datastores;
}
Also used : MountDatastore(com.emc.sa.service.vmware.block.tasks.MountDatastore) ExpandVmfsDatastore(com.emc.sa.service.vmware.block.tasks.ExpandVmfsDatastore) FindLunsBackingDatastore(com.emc.sa.service.vmware.block.tasks.FindLunsBackingDatastore) UnmountVmfsDatastore(com.emc.sa.service.vmware.block.tasks.UnmountVmfsDatastore) CreateNfsDatastore(com.emc.sa.service.vmware.file.tasks.CreateNfsDatastore) ExtendVmfsDatastore(com.emc.sa.service.vmware.block.tasks.ExtendVmfsDatastore) Datastore(com.vmware.vim25.mo.Datastore) FindDatastore(com.emc.sa.service.vmware.tasks.FindDatastore) DeleteDatastore(com.emc.sa.service.vmware.tasks.DeleteDatastore) FindFilesystemWithDatastore(com.emc.sa.service.vipr.file.tasks.FindFilesystemWithDatastore) CreateVmfsDatastore(com.emc.sa.service.vmware.block.tasks.CreateVmfsDatastore) HostSystem(com.vmware.vim25.mo.HostSystem) CreateNfsDatastore(com.emc.sa.service.vmware.file.tasks.CreateNfsDatastore)

Example 33 with ClusterComputeResource

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

the class VMwareSupport method extendVmfsDatastore.

/**
 * Extends a VMFS datastore.
 *
 * @param host
 *            the host to which the volume is assigned.
 * @param cluster
 *            the cluster to which the volume is associated (may be null if the storage is exclusive to the host)
 * @param volume
 *            the volume to extend the datastore with.
 * @param datastore
 *            the datastore to extend.
 */
public void extendVmfsDatastore(HostSystem host, ClusterComputeResource cluster, URI hostOrClusterId, BlockObjectRestRep volume, Datastore datastore) {
    HostScsiDisk disk = findScsiDisk(host, cluster, volume, true);
    execute(new ExtendVmfsDatastore(host, disk, datastore));
    addAffectedResource(volume);
    addVmfsDatastoreTag(volume, hostOrClusterId, datastore.getName());
    ExecutionUtils.clearRollback();
}
Also used : HostScsiDisk(com.vmware.vim25.HostScsiDisk) ExtendVmfsDatastore(com.emc.sa.service.vmware.block.tasks.ExtendVmfsDatastore)

Example 34 with ClusterComputeResource

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

the class VMwareSupport method setMultipathPolicy.

/**
 * Sets the multipath policy on the disks for the given host/cluster
 *
 * @param host
 *            the host to which the volume is assigned.
 * @param cluster
 *            the cluster to which the volume is associated (may be null if the storage is exclusive to the host)
 * @param multipathPolicy
 *            the multipath policy to use.
 * @param volume
 *            the volume with the created datastore.
 */
public void setMultipathPolicy(HostSystem host, ClusterComputeResource cluster, String multipathPolicy, BlockObjectRestRep volume) {
    if (VMwareUtils.isValidMultipathPolicy(multipathPolicy)) {
        Map<HostSystem, HostScsiDisk> hostDisks = Maps.newHashMap();
        if (cluster != null) {
            List<HostSystem> clusterHosts = Lists.newArrayList(cluster.getHosts());
            for (HostSystem clusterHost : clusterHosts) {
                if (isHostConnected(clusterHost)) {
                    try {
                        HostScsiDisk disk = execute(new FindHostScsiDiskForLun(clusterHost, volume));
                        hostDisks.put(clusterHost, disk);
                    } catch (Exception ex) {
                        logWarn("vmware.support.multipath.policy.volumenotfound", volume.getWwn(), clusterHost.getName());
                    }
                }
            }
        } else if (host != null) {
            try {
                HostScsiDisk disk = execute(new FindHostScsiDiskForLun(host, volume));
                hostDisks.put(host, disk);
            } catch (Exception e) {
                logWarn("vmware.support.multipath.policy.volumenotfound", volume.getWwn(), host.getName());
            }
        }
        if (hostDisks.size() > 0) {
            execute(new SetMultipathPolicy(hostDisks, multipathPolicy));
        }
    }
}
Also used : FindHostScsiDiskForLun(com.emc.sa.service.vmware.block.tasks.FindHostScsiDiskForLun) SetMultipathPolicy(com.emc.sa.service.vmware.block.tasks.SetMultipathPolicy) HostSystem(com.vmware.vim25.mo.HostSystem) HostScsiDisk(com.vmware.vim25.HostScsiDisk) ExecutionException(com.emc.sa.engine.ExecutionException) VMWareException(com.iwave.ext.vmware.VMWareException)

Example 35 with ClusterComputeResource

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

the class ClusterService method validateVcenterClusterHosts.

/**
 * Validate that the hosts in the cluster in our database matches the vCenter environment
 *
 * @param cluster the cluster to check
 */
public void validateVcenterClusterHosts(Cluster cluster) {
    if (null == cluster) {
        _log.error("Validation cluster is not set, not performing vCenter cluster validation");
        return;
    }
    // We can only proceed if this cluster belongs to a datacenter
    if (NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        _log.info("Cluster is not synced to vcenter");
        return;
    }
    // Get a list of the cluster's hosts that are in our database.
    List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(_dbClient, cluster.getId(), Host.class, "cluster");
    VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, cluster.getVcenterDataCenter());
    // If the datacenter is not in our database, we must fail the validation.
    if (vcenterDataCenter == null) {
        throw APIException.badRequests.vCenterDataCenterNotFound(cluster.getVcenterDataCenter());
    }
    // If the datacenter has a null vCenter reference, we must fail the validation.
    if (NullColumnValueGetter.isNullURI(vcenterDataCenter.getVcenter())) {
        throw APIException.badRequests.vCenterDataCenterHasNullVcenter(vcenterDataCenter.forDisplay());
    }
    Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
    // If the vCenter is not in our database, we must fail the validation.
    if (vcenter == null) {
        throw APIException.badRequests.vCenterNotFound(vcenterDataCenter.getVcenter());
    }
    List<Host> dbHosts = _dbClient.queryObject(Host.class, clusterHosts);
    VCenterAPI api = VcenterDiscoveryAdapter.createVCenterAPI(vcenter);
    try {
        // Query the vCenter to get a reference to the cluster so that we can compare the hosts between the actual
        // environment and our database representation of the cluster.
        ClusterComputeResource vcenterCluster = api.findCluster(vcenterDataCenter.getLabel(), cluster.getLabel());
        // The cluster may not have been pushed to vCenter yet.
        if (vcenterCluster == null) {
            _log.info("Unable to find cluster %s in datacenter %s in vCenter environment %s", cluster.getLabel(), vcenterDataCenter.getLabel(), vcenter.getLabel());
            return;
        }
        // Gather a set of all the host UUIDs in this vCenter cluster.
        Set<String> vCenterHostUuids = Sets.newHashSet();
        for (HostSystem hostSystem : vcenterCluster.getHosts()) {
            if (hostSystem != null && hostSystem.getHardware() != null && hostSystem.getHardware().systemInfo != null) {
                vCenterHostUuids.add(hostSystem.getHardware().systemInfo.uuid);
            }
        }
        // Gather a set of all the host UUIDs in our database.
        Set<String> dbHostUuids = Sets.newHashSet();
        for (Host host : dbHosts) {
            dbHostUuids.add(host.getUuid());
        }
        // If there are hosts in vCenter that are not in our database, fail the validation
        if (!dbHostUuids.containsAll(vCenterHostUuids)) {
            throw APIException.badRequests.clusterHostMismatch(cluster.forDisplay());
        }
    } finally {
        if (api != null) {
            api.logout();
        }
    }
}
Also used : VCenterAPI(com.iwave.ext.vmware.VCenterAPI) Vcenter(com.emc.storageos.db.client.model.Vcenter) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) HostSystem(com.vmware.vim25.mo.HostSystem) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Aggregations

ClusterComputeResource (com.vmware.vim25.mo.ClusterComputeResource)14 HostSystem (com.vmware.vim25.mo.HostSystem)13 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)10 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)9 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)9 ObjectSpec (com.vmware.vim25.ObjectSpec)9 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)9 PropertySpec (com.vmware.vim25.PropertySpec)9 TraversalSpec (com.vmware.vim25.TraversalSpec)9 ObjectContent (com.vmware.vim25.ObjectContent)8 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)7 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)7 ArrayList (java.util.ArrayList)7 HostScsiDisk (com.vmware.vim25.HostScsiDisk)6 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 Datastore (com.vmware.vim25.mo.Datastore)5 Pair (com.cloud.utils.Pair)4 ExpandVmfsDatastore (com.emc.sa.service.vmware.block.tasks.ExpandVmfsDatastore)4 ExtendVmfsDatastore (com.emc.sa.service.vmware.block.tasks.ExtendVmfsDatastore)4 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)4