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");
}
}
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);
}
}
}
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;
}
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));
}
});
}
}
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;
}
Aggregations