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