Search in sources :

Example 71 with Datacenter

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

the class ComputeUtils method verifyClusterInVcenter.

/**
 * Precheck to verify if cluster is associated to a datacenter and if it still
 * on the same datacenter and vcenter.  Precheck fails the order if the cluster
 * has datacenter association and is not found on the vcenter under the same datacenter
 * Precheck also fails if the cluster found by name in vcenter does not match externalId
 * in ViPR Cluster.
 * If cluster does not have a datacenter association, then the cluster is
 * a vipr cluster and precheck passes.
 * @param cluster {@link Cluster} cluster instance
 * @param preCheckErrors {@link StringBuilder} instance
 * @return preCheckErrors
 */
public static StringBuilder verifyClusterInVcenter(Cluster cluster, StringBuilder preCheckErrors) {
    // else fail order
    if (!NullColumnValueGetter.isNullURI(cluster.getVcenterDataCenter())) {
        VcenterDataCenter dataCenter = execute(new GetVcenterDataCenter(cluster.getVcenterDataCenter()));
        if (dataCenter != null && !dataCenter.getInactive()) {
            if (!NullColumnValueGetter.isNullURI(dataCenter.getVcenter())) {
                Vcenter vcenter = execute(new GetVcenter(dataCenter.getVcenter()));
                if (vcenter != null && !vcenter.getInactive()) {
                    VMwareSupport vmware = null;
                    try {
                        vmware = new VMwareSupport();
                        vmware.connect(vcenter.getId());
                        ClusterComputeResource vcenterCluster = vmware.getCluster(dataCenter.getLabel(), cluster.getLabel(), false);
                        if (null == vcenterCluster) {
                            preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.notfound.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel()));
                        } else if (vcenterCluster.getMOR() != null && vcenterCluster.getMOR().getVal() != null && vcenterCluster.getMOR().getVal().equalsIgnoreCase(cluster.getExternalId())) {
                            ExecutionUtils.currentContext().logInfo("compute.cluster.precheck.cluster.VcenterDataCenter.found.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel());
                        } else {
                            preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.nomatch.in.vcenter", cluster.getLabel(), vcenter.getLabel()));
                        }
                    } catch (ExecutionException e) {
                        if (e.getCause() instanceof IllegalStateException) {
                            preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.notfound.in.vcenter", cluster.getLabel(), dataCenter.getLabel(), vcenter.getLabel()));
                        } else {
                            // exception
                            throw e;
                        }
                    } finally {
                        if (vmware != null) {
                            vmware.disconnect();
                        }
                    }
                } else {
                    // If the vcenter isn't returned properly, not found in
                    // DB, but the cluster has a reference to
                    // it, there's an issue with the sync of the DB object.
                    // Do not allow the validation to pass
                    // until that's fixed.
                    preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.improper.vcenter", dataCenter.getVcenter()));
                }
            } else {
                // If datacenter does not have reference to a vcenter then
                // there's an issue with the sync of the DB object. Do not allow the validation to pass
                // until that's fixed.
                preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.VcenterDataCenter.noVcenter", dataCenter.getLabel()));
            }
        } else {
            // If the datacenter isn't returned properly, not found in DB,
            // but the cluster has a reference to
            // it, there's an issue with the sync of the DB object. Do not
            // allow the validation to pass
            // until that's fixed.
            preCheckErrors.append(ExecutionUtils.getMessage("compute.cluster.precheck.cluster.improper.VcenterDataCenter", cluster.getVcenterDataCenter()));
        }
    } else {
        // cluster is a vipr cluster only no need to check anything further.
        ExecutionUtils.currentContext().logInfo("compute.cluster.precheck.cluster.noVCenterDataCenter", cluster.getLabel());
    }
    return preCheckErrors;
}
Also used : GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) Vcenter(com.emc.storageos.db.client.model.Vcenter) ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) GetVcenter(com.emc.sa.service.vmware.tasks.GetVcenter) GetVcenterDataCenter(com.emc.sa.service.vmware.tasks.GetVcenterDataCenter) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VMwareSupport(com.emc.sa.service.vmware.VMwareSupport) ExecutionException(com.emc.sa.engine.ExecutionException)

Example 72 with Datacenter

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

the class VMwareHostService method validateClusterHosts.

/**
 * Validates the vCenter cluster hosts match the same hosts we have in our database for the cluster. If there is a mismatch the check
 * will fail the order.
 */
protected void validateClusterHosts() {
    if (hostCluster != null) {
        VcenterDataCenter datacenter = getModelClient().datacenters().findById(datacenterId);
        Cluster cluster = getModelClient().clusters().findById(hostCluster.getId());
        ClusterComputeResource vcenterCluster = vmware.getCluster(datacenter.getLabel(), cluster.getLabel(), checkClusterConnectivity());
        if (vcenterCluster == null) {
            ExecutionUtils.fail("failTask.vmware.cluster.notfound", args(), args(cluster.getLabel()));
        }
        Set<String> vCenterHostUuids = Sets.newHashSet();
        for (HostSystem hostSystem : vcenterCluster.getHosts()) {
            if (hostSystem.getHardware() != null && hostSystem.getHardware().systemInfo != null) {
                vCenterHostUuids.add(hostSystem.getHardware().systemInfo.uuid);
            }
        }
        List<Host> dbHosts = getModelClient().hosts().findByCluster(hostCluster.getId());
        Set<String> dbHostUuids = Sets.newHashSet();
        for (Host host : dbHosts) {
            // Validate the hosts within the cluster all have good discovery status
            if (!DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.toString().equalsIgnoreCase(host.getCompatibilityStatus())) {
                ExecutionUtils.fail("failTask.vmware.cluster.hostincompatible", args(), args(cluster.getLabel(), host.getLabel()));
            } else if (DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString().equalsIgnoreCase(host.getDiscoveryStatus())) {
                ExecutionUtils.fail("failTask.vmware.cluster.hostsdiscoveryfailed", args(), args(cluster.getLabel(), host.getLabel()));
            }
            dbHostUuids.add(host.getUuid());
        }
        if (!vCenterHostUuids.equals(dbHostUuids)) {
            ExecutionUtils.fail("failTask.vmware.cluster.mismatch", args(), args(cluster.getLabel()));
        } else {
            info("Hosts in cluster %s matches correctly", cluster.getLabel());
        }
    }
}
Also used : ClusterComputeResource(com.vmware.vim25.mo.ClusterComputeResource) HostSystem(com.vmware.vim25.mo.HostSystem) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host)

Example 73 with Datacenter

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

the class VMwareHostService method getConnectedHost.

/**
 * Get the first connected host from the given set of hosts
 *
 * @param hosts list of hosts
 * @param datacenter the datacenter the hosts belong to
 * @return connected host or null if no hosts are connected
 */
protected Host getConnectedHost(List<Host> hosts, VcenterDataCenter datacenter) {
    for (Host host : hosts) {
        HostSystem esxHost = null;
        esxHost = vmware.getHostSystem(datacenter.getLabel(), host.getLabel(), false);
        if (VMwareSupport.isHostConnected(esxHost)) {
            return host;
        }
    }
    return null;
}
Also used : HostSystem(com.vmware.vim25.mo.HostSystem) Host(com.emc.storageos.db.client.model.Host)

Example 74 with Datacenter

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

the class VMwareSupport method createNfsDatastore.

/**
 * Creates an NFS datastore for a host.
 *
 * @param host
 *            the host.
 * @param fileSystem
 *            the file system.
 * @param export
 *            the export.
 * @param datacenterId
 *            the datacenter ID.
 * @param datastoreName
 *            the name of the datastore to create.
 * @return datastore
 */
public Datastore createNfsDatastore(HostSystem host, FileShareRestRep fileSystem, FileSystemExportParam export, URI datacenterId, String datastoreName) {
    addNfsDatastoreTag(fileSystem, export, datacenterId, datastoreName);
    String fileServer = StringUtils.substringBefore(export.getMountPoint(), ":");
    String mountPath = StringUtils.substringAfter(export.getMountPoint(), ":");
    Datastore datastore = execute(new CreateNfsDatastore(host, fileServer, mountPath, datastoreName));
    addAffectedResource(fileSystem);
    ExecutionUtils.clearRollback();
    return datastore;
}
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) CreateNfsDatastore(com.emc.sa.service.vmware.file.tasks.CreateNfsDatastore)

Example 75 with Datacenter

use of com.vmware.vim25.mo.Datacenter 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)

Aggregations

ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)28 PropertyFilterSpec (com.vmware.vim25.PropertyFilterSpec)23 TraversalSpec (com.vmware.vim25.TraversalSpec)21 ObjectSpec (com.vmware.vim25.ObjectSpec)20 PropertySpec (com.vmware.vim25.PropertySpec)20 HostSystem (com.vmware.vim25.mo.HostSystem)20 ArrayList (java.util.ArrayList)17 RemoteException (java.rmi.RemoteException)15 ObjectContent (com.vmware.vim25.ObjectContent)14 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)12 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)11 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)11 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)11 VcenterSystemException (com.emc.storageos.vcentercontroller.exceptions.VcenterSystemException)11 SelectionSpec (com.vmware.vim25.SelectionSpec)11 ClusterComputeResource (com.vmware.vim25.mo.ClusterComputeResource)11 VirtualMachineMO (com.cloud.hypervisor.vmware.mo.VirtualMachineMO)10 VmwareHypervisorHost (com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost)10 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)10 Vcenter (com.emc.storageos.db.client.model.Vcenter)9