Search in sources :

Example 1 with FindHostScsiDiskForLun

use of com.emc.sa.service.vmware.block.tasks.FindHostScsiDiskForLun in project coprhd-controller by CoprHD.

the class VMwareSupport method findScsiDisk.

/**
 * Finds the SCSI disk on the host system that matches the volume.
 *
 * @param host
 *            the host system
 * @param cluster
 *            if specified, find disk on all hosts in the cluster
 * @param volume
 *            the volume to find
 * @param availableDiskOnly
 *            if true, only find available disk for VMFS. if false, find disk even if it's not available for VMFS.
 * @param throwIfNotFound
 *            throw exception if the lun is not found. (defaults to true)
 * @return the disk for the volume
 */
public HostScsiDisk findScsiDisk(HostSystem host, ClusterComputeResource cluster, BlockObjectRestRep volume, boolean availableDiskOnly, boolean throwIfNotFound) {
    // Ensure that the volume has a WWN set or we won't be able to find the disk
    if (StringUtils.isBlank(volume.getWwn())) {
        String volumeId = ResourceUtils.stringId(volume);
        String volumeName = ResourceUtils.name(volume);
        ExecutionUtils.fail("failTask.VMwareSupport.findLun", new Object[] { volumeId }, new Object[] { volumeName });
    }
    HostScsiDisk disk = execute(new FindHostScsiDiskForLun(host, volume, availableDiskOnly, throwIfNotFound));
    // Find the volume on all other hosts in the cluster
    if (cluster != null) {
        HostSystem[] hosts = cluster.getHosts();
        if (hosts == null) {
            throw new IllegalStateException("Cluster '" + cluster.getName() + "' contains no hosts");
        }
        Map<HostSystem, HostScsiDisk> disks = Maps.newHashMap();
        disks.put(host, disk);
        for (HostSystem otherHost : hosts) {
            if (StringUtils.equals(host.getName(), otherHost.getName())) {
                continue;
            }
            try {
                if (VMwareSupport.isHostConnected(otherHost)) {
                    HostScsiDisk otherDisk = execute(new FindHostScsiDiskForLun(otherHost, volume, availableDiskOnly, throwIfNotFound));
                    disks.put(otherHost, otherDisk);
                }
            } catch (Exception e) {
                logWarn("vmware.support.find.scsi.disk.volumenotfound", volume.getWwn(), otherHost.getName());
            }
        }
    }
    return disk;
}
Also used : FindHostScsiDiskForLun(com.emc.sa.service.vmware.block.tasks.FindHostScsiDiskForLun) HostSystem(com.vmware.vim25.mo.HostSystem) HostScsiDisk(com.vmware.vim25.HostScsiDisk) ExecutionException(com.emc.sa.engine.ExecutionException) VMWareException(com.iwave.ext.vmware.VMWareException)

Example 2 with FindHostScsiDiskForLun

use of com.emc.sa.service.vmware.block.tasks.FindHostScsiDiskForLun 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)

Aggregations

ExecutionException (com.emc.sa.engine.ExecutionException)2 FindHostScsiDiskForLun (com.emc.sa.service.vmware.block.tasks.FindHostScsiDiskForLun)2 VMWareException (com.iwave.ext.vmware.VMWareException)2 HostScsiDisk (com.vmware.vim25.HostScsiDisk)2 HostSystem (com.vmware.vim25.mo.HostSystem)2 SetMultipathPolicy (com.emc.sa.service.vmware.block.tasks.SetMultipathPolicy)1