Search in sources :

Example 11 with ClusterComputeResource

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

the class VcenterApiClient method getVirtualMachines.

private List<VirtualMachine> getVirtualMachines(ClusterComputeResource clusterComputeResource, boolean runningOnly) throws VcenterSystemException {
    try {
        List<VirtualMachine> virtualMachines = new ArrayList<VirtualMachine>();
        String clusterName = clusterComputeResource.getName();
        _log.info("Inspect cluster " + clusterName + " for virtual machines running only " + runningOnly);
        ResourcePool resourcePool = clusterComputeResource.getResourcePool();
        if (resourcePool != null) {
            _log.info("Inspect resource pool " + resourcePool.getName() + " for virtual machines");
            if (resourcePool.getVMs() != null) {
                for (VirtualMachine virtualMachine : resourcePool.getVMs()) {
                    _log.info("Found virtual machine " + virtualMachine.getName() + " in resource pool " + resourcePool.getName());
                    _log.info(toDetails(virtualMachine));
                    if (runningOnly) {
                        // Anything !poweredOff (poweredOn and suspended) will be considered running
                        if (!virtualMachine.getRuntime().getPowerState().equals(VirtualMachinePowerState.poweredOff)) {
                            virtualMachines.add(virtualMachine);
                        }
                    } else {
                        virtualMachines.add(virtualMachine);
                    }
                }
            }
        }
        _log.info("Cluster " + clusterName + " has " + virtualMachines.size() + " virtual machines");
        return virtualMachines;
    } catch (Exception e) {
        _log.error("getVirtualMachines clusterComputeResource exception " + e);
        throw new VcenterSystemException("Error checking cluster for virtual machines");
    }
}
Also used : ArrayList(java.util.ArrayList) ResourcePool(com.vmware.vim25.mo.ResourcePool) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterSystemException(com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException) VirtualMachine(com.vmware.vim25.mo.VirtualMachine)

Example 12 with ClusterComputeResource

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

the class VMwareSupport method mountDatastores.

/**
 * Mount datastores that are backed by the list of volumes
 *
 * @param host the host to mount the datastore on, or null if cluster is being used
 * @param cluster the cluster to mount the datastore on, or null if host is being used
 * @param datacenterName name of the datacenter
 * @param volumeIds the list of volumes
 * @throws Exception thrown if an error occurs
 */
public void mountDatastores(HostSystem host, ClusterComputeResource cluster, String datacenterName, List<URI> volumeIds) throws Exception {
    List<HostSystem> hosts = cluster == null ? Lists.newArrayList(host) : Lists.newArrayList(cluster.getHosts());
    rescanVmfs(hosts);
    for (URI volumeId : volumeIds) {
        BlockObjectRestRep volume = BlockStorageUtils.getVolume(volumeId);
        Set<String> datastoreNames = VMwareDatastoreTagger.getDatastoreNames(volume);
        for (String datastoreName : datastoreNames) {
            Datastore datastore = getDatastore(datacenterName, datastoreName);
            mountDatastore(datastore, hosts);
        }
    }
}
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) URI(java.net.URI) BlockObjectRestRep(com.emc.storageos.model.block.BlockObjectRestRep)

Example 13 with ClusterComputeResource

use of com.vmware.vim25.mo.ClusterComputeResource 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 14 with ClusterComputeResource

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

the class VMwareSupport method detachLuns.

/**
 * Detach the volume from the host or hosts in the cluster. Detach needs to be called on every host
 * that is part of a cluster. Passing in a cluster value signifies that we're dealing with a shared
 * export, so iterate through all the host that is part of the cluster and explicitly detach the lun
 * on every host.
 *
 * @param host host to detach the volume.
 * @param cluster cluster to detach the volume. if not null, use the cluster's hosts
 * @param volume the volume to detach
 */
public void detachLuns(HostSystem host, ClusterComputeResource cluster, BlockObjectRestRep volume) {
    // cluster is only set during shared exports.
    List<HostSystem> hosts = cluster == null ? Lists.newArrayList(host) : Lists.newArrayList(cluster.getHosts());
    for (HostSystem hs : hosts) {
        // Get disk for every host before detaching to have them in sync.
        // Pass in null cluster since we only want to find the specific disk to each host
        // as they are processed. Passing in a cluster value forces find disk on all host
        // that are part of the cluster. Once a host has detach the storage, find disk fails
        // so we can't find disk on all host as we iterate through all the host.
        final HostScsiDisk disk = findScsiDisk(hs, null, volume);
        executeOnHosts(Lists.newArrayList(hs), new HostSystemCallback() {

            @Override
            public void exec(HostSystem host) {
                detachLuns(host, Collections.singletonList(disk));
            }
        });
    }
}
Also used : HostSystem(com.vmware.vim25.mo.HostSystem) HostScsiDisk(com.vmware.vim25.HostScsiDisk)

Example 15 with ClusterComputeResource

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

the class FindCluster method executeTask.

@Override
public ClusterComputeResource executeTask() throws Exception {
    debug("Executing: %s", getDetail());
    ClusterComputeResource cluster = vcenter.findCluster(datacenterName, clusterName);
    if (cluster == null) {
        throw stateException("FindCluster.illegalState.noClusterInDataCenter", datacenterName, clusterName);
    }
    // Check cluster hosts connection state
    HostSystem[] hosts = cluster.getHosts();
    if (hosts == null) {
        throw stateException("FindCluster.illegalState.unableToListHost", clusterName);
    }
    if (checkClusterConnectivity) {
        for (HostSystem host : hosts) {
            checkConnectionState(host);
        }
    }
    return cluster;
}
Also used : ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) HostSystem(com.vmware.vim25.mo.HostSystem)

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